4 * Tests for MediaWiki api.php?action=delete.
14 class ApiDeleteTest
extends ApiTestCase
{
16 protected function setUp() {
18 $this->tablesUsed
= array_merge(
20 [ 'change_tag', 'change_tag_def', 'logging' ]
24 public function testDelete() {
25 $name = 'Help:' . ucfirst( __FUNCTION__
);
28 $this->editPage( $name, 'Some text' );
31 $apiResult = $this->doApiRequestWithToken( [
36 $this->assertArrayHasKey( 'delete', $apiResult );
37 $this->assertArrayHasKey( 'title', $apiResult['delete'] );
38 $this->assertSame( $name, $apiResult['delete']['title'] );
39 $this->assertArrayHasKey( 'logid', $apiResult['delete'] );
41 $this->assertFalse( Title
::newFromText( $name )->exists() );
44 public function testDeleteNonexistent() {
45 $this->setExpectedException( ApiUsageException
::class,
46 "The page you specified doesn't exist." );
48 $this->doApiRequestWithToken( [
50 'title' => 'This page deliberately left nonexistent',
54 public function testDeletionWithoutPermission() {
55 $this->setExpectedException( ApiUsageException
::class,
56 'The action you have requested is limited to users in the group:' );
58 $name = 'Help:' . ucfirst( __FUNCTION__
);
61 $this->editPage( $name, 'Some text' );
63 // test deletion without permission
66 $apiResult = $this->doApiRequest( [
69 'token' => $user->getEditToken(),
70 ], null, null, $user );
72 $this->assertTrue( Title
::newFromText( $name )->exists() );
76 public function testDeleteWithTag() {
77 $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH
);
78 $name = 'Help:' . ucfirst( __FUNCTION__
);
80 ChangeTags
::defineTag( 'custom tag' );
82 $this->editPage( $name, 'Some text' );
84 $this->doApiRequestWithToken( [
87 'tags' => 'custom tag',
90 $this->assertFalse( Title
::newFromText( $name )->exists() );
92 $dbw = wfGetDB( DB_MASTER
);
93 $this->assertSame( 'custom tag', $dbw->selectField(
94 [ 'change_tag', 'logging' ],
97 'log_namespace' => NS_HELP
,
98 'log_title' => ucfirst( __FUNCTION__
),
102 [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
106 public function testDeleteWithTagNewBackend() {
107 $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW
);
108 $name = 'Help:' . ucfirst( __FUNCTION__
);
110 ChangeTags
::defineTag( 'custom tag' );
112 $this->editPage( $name, 'Some text' );
114 $this->doApiRequestWithToken( [
115 'action' => 'delete',
117 'tags' => 'custom tag',
120 $this->assertFalse( Title
::newFromText( $name )->exists() );
122 $dbw = wfGetDB( DB_MASTER
);
123 $this->assertSame( 'custom tag', $dbw->selectField(
124 [ 'change_tag', 'logging', 'change_tag_def' ],
127 'log_namespace' => NS_HELP
,
128 'log_title' => ucfirst( __FUNCTION__
),
133 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ],
134 'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ]
139 public function testDeleteWithoutTagPermission() {
140 $this->setExpectedException( ApiUsageException
::class,
141 'You do not have permission to apply change tags along with your changes.' );
143 $name = 'Help:' . ucfirst( __FUNCTION__
);
145 ChangeTags
::defineTag( 'custom tag' );
146 $this->setMwGlobals( 'wgRevokePermissions',
147 [ 'user' => [ 'applychangetags' => true ] ] );
149 $this->editPage( $name, 'Some text' );
152 $this->doApiRequestWithToken( [
153 'action' => 'delete',
155 'tags' => 'custom tag',
158 $this->assertTrue( Title
::newFromText( $name )->exists() );
162 public function testDeleteAbortedByHook() {
163 $this->setExpectedException( ApiUsageException
::class,
164 'Deletion aborted by hook. It gave no explanation.' );
166 $name = 'Help:' . ucfirst( __FUNCTION__
);
168 $this->editPage( $name, 'Some text' );
170 $this->setTemporaryHook( 'ArticleDelete',
177 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name ] );
179 $this->assertTrue( Title
::newFromText( $name )->exists() );
183 public function testDeleteWatch() {
184 $name = 'Help:' . ucfirst( __FUNCTION__
);
185 $user = self
::$users['sysop']->getUser();
187 $this->editPage( $name, 'Some text' );
188 $this->assertTrue( Title
::newFromText( $name )->exists() );
189 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );
191 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'watch' => '' ] );
193 $this->assertFalse( Title
::newFromText( $name )->exists() );
194 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
197 public function testDeleteUnwatch() {
198 $name = 'Help:' . ucfirst( __FUNCTION__
);
199 $user = self
::$users['sysop']->getUser();
201 $this->editPage( $name, 'Some text' );
202 $this->assertTrue( Title
::newFromText( $name )->exists() );
203 $user->addWatch( Title
::newFromText( $name ) );
204 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
206 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'unwatch' => '' ] );
208 $this->assertFalse( Title
::newFromText( $name )->exists() );
209 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );