jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/404150 )
Change subject: Add PHPUnit tests for ApiDelete
......................................................................
Add PHPUnit tests for ApiDelete
This covers deleting non-file pages.
Bug: T183886
Change-Id: I31c27786b16b55f8bf4cf528bf4c1ea49075e02e
---
A tests/phpunit/includes/api/ApiDeleteTest.php
1 file changed, 79 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
Anomie: Looks good to me, but someone else must approve
diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php
b/tests/phpunit/includes/api/ApiDeleteTest.php
new file mode 100644
index 0000000..87167f0
--- /dev/null
+++ b/tests/phpunit/includes/api/ApiDeleteTest.php
@@ -0,0 +1,79 @@
+<?php
+
+/**
+ * Tests for MediaWiki api.php?action=delete.
+ *
+ * @author Yifei He
+ *
+ * @group API
+ * @group Database
+ * @group medium
+ *
+ * @covers ApiDelete
+ */
+class ApiDeleteTest extends ApiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->doLogin();
+ }
+
+ public function testDelete() {
+ $name = 'Help:ApiDeleteTest_testDelete';
+
+ // test non-existing page
+ try {
+ $this->doApiRequestWithToken( [
+ 'action' => 'delete',
+ 'title' => $name,
+ ] );
+ $this->fail( "Should have raised an ApiUsageException"
);
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e,
'missingtitle' ) );
+ }
+
+ // create new page
+ $this->editPage( $name, 'Some text' );
+
+ // test deletion
+ $apiResult = $this->doApiRequestWithToken( [
+ 'action' => 'delete',
+ 'title' => $name,
+ ] );
+ $apiResult = $apiResult[0];
+
+ $this->assertArrayHasKey( 'delete', $apiResult );
+ $this->assertArrayHasKey( 'title', $apiResult['delete'] );
+ // Normalized $name is used
+ $this->assertSame(
+ 'Help:ApiDeleteTest testDelete',
+ $apiResult['delete']['title']
+ );
+ $this->assertArrayHasKey( 'logid', $apiResult['delete'] );
+
+ $this->assertFalse( Title::newFromText( $name )->exists() );
+ }
+
+ public function testDeletionWithoutPermission() {
+ $name = 'Help:ApiDeleteTest_testDeleteWithoutPermission';
+
+ // create new page
+ $this->editPage( $name, 'Some text' );
+
+ // test deletion without permission
+ try {
+ $user = new User();
+ $apiResult = $this->doApiRequest( [
+ 'action' => 'delete',
+ 'title' => $name,
+ 'token' => $user->getEditToken(),
+ ], null, null, $user );
+ $this->fail( "Should have raised an ApiUsageException"
);
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e,
'permissiondenied' ) );
+ }
+
+ $this->assertTrue( Title::newFromText( $name )->exists() );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/404150
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I31c27786b16b55f8bf4cf528bf4c1ea49075e02e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Eflyjason <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Eflyjason <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits