Eflyjason has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/404150 )
Change subject: Add PHPUnit for ApiDelete for deleting non-file pages
......................................................................
Add PHPUnit for ApiDelete for deleting non-file pages
Bug: T183886
Change-Id: I31c27786b16b55f8bf4cf528bf4c1ea49075e02e
---
A tests/phpunit/includes/api/ApiDeleteTest.php
1 file changed, 81 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/50/404150/1
diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php
b/tests/phpunit/includes/api/ApiDeleteTest.php
new file mode 100644
index 0000000..8d153ba
--- /dev/null
+++ b/tests/phpunit/includes/api/ApiDeleteTest.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * Tests for MediaWiki api.php?action=delete.
+ *
+ * @author Yifei He
+ *
+ * @group API
+ * @group Database
+ * @group medium
+ *
+ * @covers ApiDelete
+ */
+class ApiDeleteTest extends ApiTestCase {
+
+ protected function setUp() {
+ global $wgExtraNamespaces, $wgNamespaceContentModels,
$wgContentHandlers, $wgContLang;
+
+ parent::setUp();
+
+ $this->setMwGlobals( [
+ 'wgExtraNamespaces' => $wgExtraNamespaces,
+ 'wgNamespaceContentModels' => $wgNamespaceContentModels,
+ 'wgContentHandlers' => $wgContentHandlers,
+ 'wgContLang' => $wgContLang,
+ ] );
+
+ MWNamespace::clearCaches();
+ $wgContLang->resetNamespaces(); # reset namespace cache
+
+ $this->doLogin();
+ }
+
+ protected function tearDown() {
+ global $wgContLang;
+
+ MWNamespace::clearCaches();
+ $wgContLang->resetNamespaces(); # reset namespace cache
+
+ parent::tearDown();
+ }
+
+ public function testDelete() {
+ $name = 'Help:ApiDeleteTest_testDelete'; // assume Help
namespace to default to wikitext
+
+ // -- test non-existing page
--------------------------------------------
+ try {
+ $this->doApiRequestWithToken( [
+ 'action' => 'delete',
+ 'title' => $name,
+ ] );
+ $this->fail( "Should have raised an ApiUsageException"
);
+ } catch ( ApiUsageException $e ) {
+ $this->assertTrue( self::apiExceptionHasCode( $e,
'missingtitle' ) );
+ }
+
+ $this->doApiRequestWithToken( [
+ 'action' => 'edit',
+ 'title' => $name,
+ 'text' => 'some text',
+ ] );
+
+ // -- test page --------------------------------------------
+ $apiResult = $this->doApiRequestWithToken( [
+ 'action' => 'delete',
+ 'title' => $name,
+ ] );
+ $apiResult = $apiResult[0];
+
+ // Validate API result data
+ $this->assertArrayHasKey( 'delete', $apiResult );
+ $this->assertArrayHasKey( 'title', $apiResult['delete'] );
+ $this->assertEquals( Title::newFromText( $name ),
$apiResult['delete']['title'] );
+ $this->assertArrayHasKey( 'logid', $apiResult['delete'] );
+
+ // -- validate
-----------------------------------------------------
+ $page = new WikiPage( Title::newFromText( $name ) );
+ $content = $page->getContent();
+ $this->assertNull( $content, 'Page should have been deleted' );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/404150
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I31c27786b16b55f8bf4cf528bf4c1ea49075e02e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Eflyjason <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits