4 * Tests for MediaWiki api.php?action=delete.
14 class ApiDeleteTest
extends ApiTestCase
{
16 protected function setUp() {
22 public function testDelete() {
23 $name = 'Help:' . ucfirst( __FUNCTION__
);
26 $this->editPage( $name, 'Some text' );
29 $apiResult = $this->doApiRequestWithToken( [
34 $this->assertArrayHasKey( 'delete', $apiResult );
35 $this->assertArrayHasKey( 'title', $apiResult['delete'] );
36 $this->assertSame( $name, $apiResult['delete']['title'] );
37 $this->assertArrayHasKey( 'logid', $apiResult['delete'] );
39 $this->assertFalse( Title
::newFromText( $name )->exists() );
42 public function testDeleteNonexistent() {
43 $this->setExpectedException( ApiUsageException
::class,
44 "The page you specified doesn't exist." );
46 $this->doApiRequestWithToken( [
48 'title' => 'This page deliberately left nonexistent',
52 public function testDeletionWithoutPermission() {
53 $this->setExpectedException( ApiUsageException
::class,
54 'The action you have requested is limited to users in the group:' );
56 $name = 'Help:' . ucfirst( __FUNCTION__
);
59 $this->editPage( $name, 'Some text' );
61 // test deletion without permission
64 $apiResult = $this->doApiRequest( [
67 'token' => $user->getEditToken(),
68 ], null, null, $user );
70 $this->assertTrue( Title
::newFromText( $name )->exists() );
74 public function testDeleteWithTag() {
75 $name = 'Help:' . ucfirst( __FUNCTION__
);
77 ChangeTags
::defineTag( 'custom tag' );
79 $this->editPage( $name, 'Some text' );
81 $this->doApiRequestWithToken( [
84 'tags' => 'custom tag',
87 $this->assertFalse( Title
::newFromText( $name )->exists() );
89 $dbw = wfGetDB( DB_MASTER
);
90 $this->assertSame( 'custom tag', $dbw->selectField(
91 [ 'change_tag', 'logging' ],
94 'log_namespace' => NS_HELP
,
95 'log_title' => ucfirst( __FUNCTION__
),
99 [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
103 public function testDeleteWithoutTagPermission() {
104 $this->setExpectedException( ApiUsageException
::class,
105 'You do not have permission to apply change tags along with your changes.' );
107 $name = 'Help:' . ucfirst( __FUNCTION__
);
109 ChangeTags
::defineTag( 'custom tag' );
110 $this->setMwGlobals( 'wgRevokePermissions',
111 [ 'user' => [ 'applychangetags' => true ] ] );
113 $this->editPage( $name, 'Some text' );
116 $this->doApiRequestWithToken( [
117 'action' => 'delete',
119 'tags' => 'custom tag',
122 $this->assertTrue( Title
::newFromText( $name )->exists() );
126 public function testDeleteAbortedByHook() {
127 $this->setExpectedException( ApiUsageException
::class,
128 'Deletion aborted by hook. It gave no explanation.' );
130 $name = 'Help:' . ucfirst( __FUNCTION__
);
132 $this->editPage( $name, 'Some text' );
134 $this->setTemporaryHook( 'ArticleDelete',
141 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name ] );
143 $this->assertTrue( Title
::newFromText( $name )->exists() );
147 public function testDeleteWatch() {
148 $name = 'Help:' . ucfirst( __FUNCTION__
);
149 $user = self
::$users['sysop']->getUser();
151 $this->editPage( $name, 'Some text' );
152 $this->assertTrue( Title
::newFromText( $name )->exists() );
153 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );
155 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'watch' => '' ] );
157 $this->assertFalse( Title
::newFromText( $name )->exists() );
158 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
161 public function testDeleteUnwatch() {
162 $name = 'Help:' . ucfirst( __FUNCTION__
);
163 $user = self
::$users['sysop']->getUser();
165 $this->editPage( $name, 'Some text' );
166 $this->assertTrue( Title
::newFromText( $name )->exists() );
167 $user->addWatch( Title
::newFromText( $name ) );
168 $this->assertTrue( $user->isWatched( Title
::newFromText( $name ) ) );
170 $this->doApiRequestWithToken( [ 'action' => 'delete', 'title' => $name, 'unwatch' => '' ] );
172 $this->assertFalse( Title
::newFromText( $name )->exists() );
173 $this->assertFalse( $user->isWatched( Title
::newFromText( $name ) ) );