fc546ffbe9616e43db9b4611f92ee82c3be3ed95
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 $name = 'Help:' . ucfirst( __FUNCTION__
);
79 ChangeTags
::defineTag( 'custom tag' );
81 $this->editPage( $name, 'Some text' );
83 $this->doApiRequestWithToken( [
86 'tags' => 'custom tag',
89 $this->assertFalse( Title
::newFromText( $name )->exists() );
91 $dbw = wfGetDB( DB_MASTER
);
92 $this->assertSame( 'custom tag', $dbw->selectField(
93 [ 'change_tag', 'logging', 'change_tag_def' ],
96 'log_namespace' => NS_HELP
,
97 'log_title' => ucfirst( __FUNCTION__
),
102 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ],
103 'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ]
108 public function testDeleteWithoutTagPermission() {
109 $this->setExpectedException( ApiUsageException
::class,
110 'You do not have permission to apply change tags along with your changes.' );
112 $name = 'Help:' . ucfirst( __FUNCTION__
);
114 ChangeTags
::defineTag( 'custom tag' );
115 $this->setMwGlobals( 'wgRevokePermissions',
116 [ 'user' => [ 'applychangetags' => true ] ] );
118 $this->editPage( $name, 'Some text' );
121 $this->doApiRequestWithToken( [
122 'action' => 'delete',
124 'tags' => 'custom tag',
127 $this->assertTrue( Title
::newFromText( $name )->exists() );
131 public function testDeleteAbortedByHook() {
132 $this->setExpectedException( ApiUsageException
::class,
133 'Deletion aborted by hook. It gave no explanation.' );
135 $name = 'Help:' . ucfirst( __FUNCTION__
);
137 $this->editPage( $name, 'Some text' );
139 $this->setTemporaryHook( 'ArticleDelete',
146 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name ] );
148 $this->assertTrue( Title
::newFromText( $name )->exists() );
152 public function testDeleteWatch() {
153 $name = 'Help:' . ucfirst( __FUNCTION__
);
154 $user = self
::$users['sysop']->getUser();
156 $this->editPage( $name, 'Some text' );
157 $this->assertTrue( Title
::newFromText( $name )->exists() );
158 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );
160 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'watch' => '' ] );
162 $this->assertFalse( Title
::newFromText( $name )->exists() );
163 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
166 public function testDeleteUnwatch() {
167 $name = 'Help:' . ucfirst( __FUNCTION__
);
168 $user = self
::$users['sysop']->getUser();
170 $this->editPage( $name, 'Some text' );
171 $this->assertTrue( Title
::newFromText( $name )->exists() );
172 $user->addWatch( Title
::newFromText( $name ) );
173 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
175 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'unwatch' => '' ] );
177 $this->assertFalse( Title
::newFromText( $name )->exists() );
178 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );