4 * Tests for MediaWiki api.php?action=delete.
14 class ApiDeleteTest
extends ApiTestCase
{
15 public function testDelete() {
16 $name = 'Help:' . ucfirst( __FUNCTION__
);
19 $this->editPage( $name, 'Some text' );
22 $apiResult = $this->doApiRequestWithToken( [
27 $this->assertArrayHasKey( 'delete', $apiResult );
28 $this->assertArrayHasKey( 'title', $apiResult['delete'] );
29 $this->assertSame( $name, $apiResult['delete']['title'] );
30 $this->assertArrayHasKey( 'logid', $apiResult['delete'] );
32 $this->assertFalse( Title
::newFromText( $name )->exists() );
35 public function testDeleteNonexistent() {
36 $this->setExpectedException( ApiUsageException
::class,
37 "The page you specified doesn't exist." );
39 $this->doApiRequestWithToken( [
41 'title' => 'This page deliberately left nonexistent',
45 public function testDeletionWithoutPermission() {
46 $this->setExpectedException( ApiUsageException
::class,
47 'The action you have requested is limited to users in the group:' );
49 $name = 'Help:' . ucfirst( __FUNCTION__
);
52 $this->editPage( $name, 'Some text' );
54 // test deletion without permission
57 $apiResult = $this->doApiRequest( [
60 'token' => $user->getEditToken(),
61 ], null, null, $user );
63 $this->assertTrue( Title
::newFromText( $name )->exists() );
67 public function testDeleteWithTag() {
68 $name = 'Help:' . ucfirst( __FUNCTION__
);
70 ChangeTags
::defineTag( 'custom tag' );
72 $this->editPage( $name, 'Some text' );
74 $this->doApiRequestWithToken( [
77 'tags' => 'custom tag',
80 $this->assertFalse( Title
::newFromText( $name )->exists() );
82 $dbw = wfGetDB( DB_MASTER
);
83 $this->assertSame( 'custom tag', $dbw->selectField(
84 [ 'change_tag', 'logging' ],
87 'log_namespace' => NS_HELP
,
88 'log_title' => ucfirst( __FUNCTION__
),
92 [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
96 public function testDeleteWithoutTagPermission() {
97 $this->setExpectedException( ApiUsageException
::class,
98 'You do not have permission to apply change tags along with your changes.' );
100 $name = 'Help:' . ucfirst( __FUNCTION__
);
102 ChangeTags
::defineTag( 'custom tag' );
103 $this->setMwGlobals( 'wgRevokePermissions',
104 [ 'user' => [ 'applychangetags' => true ] ] );
106 $this->editPage( $name, 'Some text' );
109 $this->doApiRequestWithToken( [
110 'action' => 'delete',
112 'tags' => 'custom tag',
115 $this->assertTrue( Title
::newFromText( $name )->exists() );
119 public function testDeleteAbortedByHook() {
120 $this->setExpectedException( ApiUsageException
::class,
121 'Deletion aborted by hook. It gave no explanation.' );
123 $name = 'Help:' . ucfirst( __FUNCTION__
);
125 $this->editPage( $name, 'Some text' );
127 $this->setTemporaryHook( 'ArticleDelete',
134 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name ] );
136 $this->assertTrue( Title
::newFromText( $name )->exists() );
140 public function testDeleteWatch() {
141 $name = 'Help:' . ucfirst( __FUNCTION__
);
142 $user = self
::$users['sysop']->getUser();
144 $this->editPage( $name, 'Some text' );
145 $this->assertTrue( Title
::newFromText( $name )->exists() );
146 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );
148 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'watch' => '' ] );
150 $this->assertFalse( Title
::newFromText( $name )->exists() );
151 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
154 public function testDeleteUnwatch() {
155 $name = 'Help:' . ucfirst( __FUNCTION__
);
156 $user = self
::$users['sysop']->getUser();
158 $this->editPage( $name, 'Some text' );
159 $this->assertTrue( Title
::newFromText( $name )->exists() );
160 $user->addWatch( Title
::newFromText( $name ) );
161 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
163 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'unwatch' => '' ] );
165 $this->assertFalse( Title
::newFromText( $name )->exists() );
166 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );