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 testBatchedDelete() {
45 $this->setMwGlobals( 'wgDeleteRevisionsBatchSize', 1 );
47 $name = 'Help:' . ucfirst( __FUNCTION__
);
48 for ( $i = 1; $i <= 3; $i++
) {
49 $this->editPage( $name, "Revision $i" );
52 $apiResult = $this->doApiRequestWithToken( [
57 $this->assertArrayHasKey( 'delete', $apiResult );
58 $this->assertArrayHasKey( 'title', $apiResult['delete'] );
59 $this->assertSame( $name, $apiResult['delete']['title'] );
60 $this->assertArrayHasKey( 'scheduled', $apiResult['delete'] );
61 $this->assertTrue( $apiResult['delete']['scheduled'] );
62 $this->assertArrayNotHasKey( 'logid', $apiResult['delete'] );
65 JobQueueGroup
::destroySingletons();
67 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
70 $this->assertFalse( Title
::newFromText( $name )->exists( Title
::GAID_FOR_UPDATE
) );
73 public function testDeleteNonexistent() {
74 $this->setExpectedException( ApiUsageException
::class,
75 "The page you specified doesn't exist." );
77 $this->doApiRequestWithToken( [
79 'title' => 'This page deliberately left nonexistent',
83 public function testDeletionWithoutPermission() {
84 $this->setExpectedException( ApiUsageException
::class,
85 'The action you have requested is limited to users in the group:' );
87 $name = 'Help:' . ucfirst( __FUNCTION__
);
90 $this->editPage( $name, 'Some text' );
92 // test deletion without permission
95 $apiResult = $this->doApiRequest( [
98 'token' => $user->getEditToken(),
99 ], null, null, $user );
101 $this->assertTrue( Title
::newFromText( $name )->exists() );
105 public function testDeleteWithTag() {
106 $name = 'Help:' . ucfirst( __FUNCTION__
);
108 ChangeTags
::defineTag( 'custom tag' );
110 $this->editPage( $name, 'Some text' );
112 $this->doApiRequestWithToken( [
113 'action' => 'delete',
115 'tags' => 'custom tag',
118 $this->assertFalse( Title
::newFromText( $name )->exists() );
120 $dbw = wfGetDB( DB_MASTER
);
121 $this->assertSame( 'custom tag', $dbw->selectField(
122 [ 'change_tag', 'logging', 'change_tag_def' ],
125 'log_namespace' => NS_HELP
,
126 'log_title' => ucfirst( __FUNCTION__
),
131 'change_tag' => [ 'JOIN', 'ct_log_id = log_id' ],
132 'change_tag_def' => [ 'JOIN', 'ctd_id = ct_tag_id' ]
137 public function testDeleteWithoutTagPermission() {
138 $this->setExpectedException( ApiUsageException
::class,
139 'You do not have permission to apply change tags along with your changes.' );
141 $name = 'Help:' . ucfirst( __FUNCTION__
);
143 ChangeTags
::defineTag( 'custom tag' );
144 $this->setMwGlobals( 'wgRevokePermissions',
145 [ 'user' => [ 'applychangetags' => true ] ] );
146 $this->resetServices();
148 $this->editPage( $name, 'Some text' );
151 $this->doApiRequestWithToken( [
152 'action' => 'delete',
154 'tags' => 'custom tag',
157 $this->assertTrue( Title
::newFromText( $name )->exists() );
161 public function testDeleteAbortedByHook() {
162 $this->setExpectedException( ApiUsageException
::class,
163 'Deletion aborted by hook. It gave no explanation.' );
165 $name = 'Help:' . ucfirst( __FUNCTION__
);
167 $this->editPage( $name, 'Some text' );
169 $this->setTemporaryHook( 'ArticleDelete',
176 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name ] );
178 $this->assertTrue( Title
::newFromText( $name )->exists() );
182 public function testDeleteWatch() {
183 $name = 'Help:' . ucfirst( __FUNCTION__
);
184 $user = self
::$users['sysop']->getUser();
186 $this->editPage( $name, 'Some text' );
187 $this->assertTrue( Title
::newFromText( $name )->exists() );
188 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );
190 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'watch' => '' ] );
192 $this->assertFalse( Title
::newFromText( $name )->exists() );
193 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
196 public function testDeleteUnwatch() {
197 $name = 'Help:' . ucfirst( __FUNCTION__
);
198 $user = self
::$users['sysop']->getUser();
200 $this->editPage( $name, 'Some text' );
201 $this->assertTrue( Title
::newFromText( $name )->exists() );
202 $user->addWatch( Title
::newFromText( $name ) );
203 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
205 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'unwatch' => '' ] );
207 $this->assertFalse( Title
::newFromText( $name )->exists() );
208 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );