From: Yifei He Date: Sun, 14 Jan 2018 09:52:57 +0000 (+0800) Subject: Add PHPUnit tests for ApiDelete X-Git-Tag: 1.31.0-rc.0~875^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=1891a1e972b3eb0db21776cce4ce8bad0ae59f4c Add PHPUnit tests for ApiDelete This covers deleting non-file pages. Bug: T183886 Change-Id: I31c27786b16b55f8bf4cf528bf4c1ea49075e02e --- diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php b/tests/phpunit/includes/api/ApiDeleteTest.php new file mode 100644 index 0000000000..87167f034f --- /dev/null +++ b/tests/phpunit/includes/api/ApiDeleteTest.php @@ -0,0 +1,79 @@ +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() ); + } +}