summaryrefslogtreecommitdiff
path: root/bin/wiki/vendor/addwiki/mediawiki-api/tests
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/vendor/addwiki/mediawiki-api/tests')
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.pngbin0 -> 2807 bytes
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/namespaces.json241
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/CategoryTraverserTest.php203
-rwxr-xr-xbin/wiki/vendor/addwiki/mediawiki-api/tests/integration/FileUploaderTest.php75
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/NamespaceGetterTest.php86
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageIntegrationTest.php66
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageListGetterTest.php99
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/TestEnvironment.php116
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/UserIntegrationTest.php35
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/phpunit.xml.dist18
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/AnonymousGeneratorTest.php26
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/FluentGeneratorTest.php55
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/MediawikiFactoryTest.php54
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Service/PagePurgerTest.php187
-rw-r--r--bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/phpunit.xml.dist13
15 files changed, 1274 insertions, 0 deletions
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.png b/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.png
new file mode 100644
index 00000000..9f8efbc8
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.png
Binary files differ
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/namespaces.json b/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/namespaces.json
new file mode 100644
index 00000000..2933692a
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/fixtures/namespaces.json
@@ -0,0 +1,241 @@
+{
+ "batchcomplete": "",
+ "query": {
+ "namespaces": {
+ "-2": {
+ "id": -2,
+ "case": "first-letter",
+ "canonical": "Media",
+ "*": "Medium"
+ },
+ "-1": {
+ "id": -1,
+ "case": "first-letter",
+ "canonical": "Special",
+ "*": "Spezial"
+ },
+ "0": {
+ "id": 0,
+ "case": "first-letter",
+ "content": "",
+ "*": ""
+ },
+ "1": {
+ "id": 1,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Talk",
+ "*": "Diskussion"
+ },
+ "2": {
+ "id": 2,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "User",
+ "*": "Benutzer"
+ },
+ "3": {
+ "id": 3,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "User talk",
+ "*": "Benutzer Diskussion"
+ },
+ "4": {
+ "id": 4,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Project",
+ "*": "Wikipedia"
+ },
+ "5": {
+ "id": 5,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Project talk",
+ "*": "Wikipedia Diskussion"
+ },
+ "6": {
+ "id": 6,
+ "case": "first-letter",
+ "canonical": "File",
+ "*": "Datei"
+ },
+ "7": {
+ "id": 7,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "File talk",
+ "*": "Datei Diskussion"
+ },
+ "8": {
+ "id": 8,
+ "case": "first-letter",
+ "canonical": "MediaWiki",
+ "*": "MediaWiki"
+ },
+ "9": {
+ "id": 9,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "MediaWiki talk",
+ "*": "MediaWiki Diskussion"
+ },
+ "10": {
+ "id": 10,
+ "case": "first-letter",
+ "canonical": "Template",
+ "*": "Vorlage"
+ },
+ "11": {
+ "id": 11,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Template talk",
+ "*": "Vorlage Diskussion"
+ },
+ "12": {
+ "id": 12,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Help",
+ "*": "Hilfe"
+ },
+ "13": {
+ "id": 13,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Help talk",
+ "*": "Hilfe Diskussion"
+ },
+ "14": {
+ "id": 14,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Category",
+ "*": "Kategorie"
+ },
+ "15": {
+ "id": 15,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Category talk",
+ "*": "Kategorie Diskussion"
+ },
+ "100": {
+ "id": 100,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Portal",
+ "*": "Portal"
+ },
+ "101": {
+ "id": 101,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Portal Diskussion",
+ "*": "Portal Diskussion"
+ },
+ "828": {
+ "id": 828,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Module",
+ "*": "Modul"
+ },
+ "829": {
+ "id": 829,
+ "case": "first-letter",
+ "subpages": "",
+ "canonical": "Module talk",
+ "*": "Modul Diskussion"
+ },
+ "2300": {
+ "id": 2300,
+ "case": "first-letter",
+ "canonical": "Gadget",
+ "*": "Gadget"
+ },
+ "2301": {
+ "id": 2301,
+ "case": "first-letter",
+ "canonical": "Gadget talk",
+ "*": "Gadget Diskussion"
+ },
+ "2302": {
+ "id": 2302,
+ "case": "case-sensitive",
+ "canonical": "Gadget definition",
+ "defaultcontentmodel": "GadgetDefinition",
+ "*": "Gadget-Definition"
+ },
+ "2303": {
+ "id": 2303,
+ "case": "case-sensitive",
+ "canonical": "Gadget definition talk",
+ "*": "Gadget-Definition Diskussion"
+ },
+ "2600": {
+ "id": 2600,
+ "case": "first-letter",
+ "canonical": "Topic",
+ "defaultcontentmodel": "flow-board",
+ "*": "Thema"
+ }
+ },
+ "namespacealiases": [
+ {
+ "id": 2,
+ "*": "Benutzerin"
+ },
+ {
+ "id": 3,
+ "*": "BD"
+ },
+ {
+ "id": 3,
+ "*": "Benutzerin Diskussion"
+ },
+ {
+ "id": 4,
+ "*": "WP"
+ },
+ {
+ "id": 5,
+ "*": "WD"
+ },
+ {
+ "id": 6,
+ "*": "Bild"
+ },
+ {
+ "id": 6,
+ "*": "Image"
+ },
+ {
+ "id": 7,
+ "*": "Bild Diskussion"
+ },
+ {
+ "id": 7,
+ "*": "Image talk"
+ },
+ {
+ "id": 12,
+ "*": "H"
+ },
+ {
+ "id": 13,
+ "*": "HD"
+ },
+ {
+ "id": 100,
+ "*": "P"
+ },
+ {
+ "id": 101,
+ "*": "PD"
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/CategoryTraverserTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/CategoryTraverserTest.php
new file mode 100644
index 00000000..7161447d
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/CategoryTraverserTest.php
@@ -0,0 +1,203 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\CategoryLoopException;
+use Mediawiki\Api\Service\CategoryTraverser;
+use Mediawiki\DataModel\Page;
+use Mediawiki\DataModel\PageIdentifier;
+use Mediawiki\DataModel\Title;
+use Mediawiki\DataModel\Revision;
+use Mediawiki\DataModel\Content;
+
+class CategoryTraverserTest extends \PHPUnit_Framework_TestCase {
+
+ /** @var TestEnvironment */
+ protected $testEnvironment;
+
+ /** @var \Mediawiki\Api\MediawikiFactory */
+ protected $factory;
+
+ /** @var \Mediawiki\Api\Service\CategoryTraverser */
+ protected $traverser;
+
+ public function setUp() {
+ parent::setUp();
+ $this->testEnvironment = TestEnvironment::newDefault();
+ $this->factory = $this->testEnvironment->getFactory();
+ $this->traverser = $this->factory->newCategoryTraverser();
+ }
+
+ /**
+ * A convenience wrapper around a PageDeleter.
+ * @param string[] $titles The titles to delete.
+ */
+ public function deletePages( $titles ) {
+ $deleter = $this->factory->newPageDeleter();
+ foreach ( $titles as $t ) {
+ // @todo Properly delete?
+ // $deleter->deleteFromPageTitle( new Title( $t ) );
+ $this->savePage( $t, '' );
+ }
+ }
+
+ /**
+ * A convenience wrapper to a RevisionSaver.
+ * @param string $title The title of the new page.
+ * @param string $content The wikitext to save to the page.
+ * @return Page The saved Page.
+ */
+ protected function savePage( $title, $content ) {
+ $pageIdentifier = new PageIdentifier( new Title( $title ) );
+ $revision = new Revision( new Content( $content ), $pageIdentifier );
+ $this->factory->newRevisionSaver()->save( $revision );
+ return $this->factory->newPageGetter()->getFromPageIdentifier( $pageIdentifier );
+ }
+
+ /**
+ * Get a list of all pages in a category or any of its descendants.
+ */
+ public function testDescendants() {
+ $rootCat = $this->savePage( 'Category:Root category', '' );
+ $this->savePage( 'Category:Sub category B', '[[Category:Root category]]' );
+ $this->savePage( 'Category:Sub category C', '[[Category:Root category]]' );
+ $this->savePage( 'Test page A1', 'Testing. [[Category:Root category]]' );
+ $this->savePage( 'Test page B1', 'Testing. [[Category:Sub category B]]' );
+ $this->savePage( 'Test page B2', 'Testing. [[Category:Sub category B]]' );
+ $this->savePage( 'Test page C1', 'Testing. [[Category:Sub category C]]' );
+ $this->testEnvironment->runJobs();
+
+ $callback = function ( Page $pageInfo, Page $parentCat ) {
+ $parentCatName = $parentCat->getPageIdentifier()->getTitle()->getText();
+ $thisPageName = $pageInfo->getPageIdentifier()->getTitle()->getText();
+ if ( $parentCatName === 'Category:Root category' ) {
+ $this->assertEquals( 'Test page A1', $thisPageName );
+ }
+ if ( $parentCatName === 'Category:Sub category C' ) {
+ $this->assertEquals( 'Test page C1', $thisPageName );
+ }
+ };
+ $this->traverser->addCallback( CategoryTraverser::CALLBACK_PAGE, $callback );
+ $decendants = $this->traverser->descend( $rootCat );
+ $this->assertCount( 4, $decendants->toArray() );
+ $this->deletePages( [
+ 'Category:Root category',
+ 'Category:Sub category B',
+ 'Category:Sub category C',
+ 'Test page A1',
+ 'Test page B1',
+ 'Test page B2',
+ 'Test page C1',
+ ] );
+ }
+
+ /**
+ * Make sure there aren't duplicate results when there are multiple paths to
+ * the same page.
+ */
+ public function testDescendantsWithMultiplePaths() {
+ $grandparent = $this->savePage( 'Category:Grandparent', '' );
+ $this->savePage( 'Category:Parent 1', '[[Category:Grandparent]]' );
+ $this->savePage( 'Category:Parent 2', '[[Category:Grandparent]]' );
+ $this->savePage( 'Parent 1', '[[Category:Grandparent]]' );
+ $this->savePage( 'Child 1', '[[Category:Parent 1]]' );
+ $this->savePage( 'Child 2', '[[Category:Parent 1]]' );
+ $this->savePage( 'Child 3', '[[Category:Parent 2]]' );
+ $this->testEnvironment->runJobs();
+ $decendants = $this->traverser->descend( $grandparent );
+ $this->assertCount( 4, $decendants->toArray() );
+ $this->deletePages( [
+ 'Category:Grandparent',
+ 'Category:Parent 1',
+ 'Category:Parent 2',
+ 'Child 1',
+ 'Child 2',
+ 'Child 3',
+ ] );
+ }
+
+ /**
+ * Categories should only be traversed once. For example, in the following graph, 'C' can be
+ * reached as a child of 'A' or of 'B', but only the first arrival will proceed to 'D':
+ *
+ * A
+ * | \
+ * | B
+ * | /
+ * C
+ * |
+ * D
+ *
+ */
+ public function testDescendantsOnlyVisitCatsOnce() {
+ global $wgVisitedCats;
+ $wgVisitedCats = [];
+ $catA = $this->savePage( 'Category:A cat', '' );
+ $this->savePage( 'Category:B cat', 'Testing. [[Category:A cat]]' );
+ $this->savePage( 'Category:C cat', 'Testing. [[Category:A cat]][[Category:B cat]]' );
+ $this->savePage( 'Category:D cat', 'Testing. [[Category:C cat]]' );
+ $this->testEnvironment->runJobs();
+ $callback = function ( Page $pageInfo, Page $parentCat ) {
+ global $wgVisitedCats;
+ $wgVisitedCats[] = $parentCat->getPageIdentifier()->getTitle()->getText();
+ };
+ $this->traverser->addCallback( CategoryTraverser::CALLBACK_CATEGORY, $callback );
+ $descendants = $this->traverser->descend( $catA );
+ $this->assertCount( 0, $descendants->toArray() );
+ $this->assertCount( 3, $wgVisitedCats );
+ $this->deletePages( [
+ 'Category:A cat',
+ 'Category:B cat',
+ 'Category:C cat',
+ 'Category:D cat',
+ ] );
+ }
+
+ /**
+ * Category loops are caught on descent.
+ *
+ * E
+ * / \
+ * F G
+ * / \
+ * H I
+ * |
+ * E <-- throw an Exception when we get to this repetition
+ *
+ */
+ public function testDescendIntoLoop() {
+ $catA = $this->savePage( 'Category:E cat', '[[Category:H cat]]' );
+ $catB = $this->savePage( 'Category:F cat', '[[Category:E cat]]' );
+ $catC = $this->savePage( 'Category:G cat', '[[Category:E cat]]' );
+ $catD = $this->savePage( 'Category:H cat', '[[Category:F cat]]' );
+ $catE = $this->savePage( 'Category:I cat', '[[Category:F cat]]' );
+ $this->testEnvironment->runJobs();
+ $haveCaught = false;
+ try {
+ $this->traverser->descend( $catA );
+ } catch ( CategoryLoopException $ex ) {
+ $haveCaught = true;
+ $expectedCatLoop = [
+ 'Category:E cat',
+ 'Category:F cat',
+ 'Category:H cat',
+ ];
+ // Build a simplified representation of the thrown loop pages, to get around different
+ // revision IDs.
+ $actualCatLoop = [];
+ foreach ( $ex->getCategoryPath()->toArray() as $p ) {
+ $actualCatLoop[] = $p->getPageIdentifier()->getTitle()->getText();
+ }
+ $this->assertEquals( $expectedCatLoop, $actualCatLoop );
+ }
+ $this->assertTrue( $haveCaught );
+ $this->deletePages( [
+ 'Category:E cat',
+ 'Category:F cat',
+ 'Category:G cat',
+ 'Category:H cat',
+ 'Category:I cat',
+ ] );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/FileUploaderTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/FileUploaderTest.php
new file mode 100755
index 00000000..e805ee1d
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/FileUploaderTest.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\ApiUser;
+use Mediawiki\Api\MediawikiApi;
+use Mediawiki\Api\MediawikiFactory;
+use Mediawiki\Api\Service\FileUploader;
+use Mediawiki\Api\SimpleRequest;
+use Mediawiki\DataModel\Page;
+use Mediawiki\DataModel\PageIdentifier;
+use Mediawiki\DataModel\Title;
+use PHPUnit_Framework_TestCase;
+
+/**
+ * Test the \Mediawiki\Api\Service\FileUploader class.
+ */
+class FileUploaderTest extends PHPUnit_Framework_TestCase {
+
+ /** @var MediawikiFactory */
+ protected $factory;
+
+ /** @var FileUploader */
+ protected $fileUploader;
+
+ /**
+ * Create a FileUploader to use in all these tests.
+ */
+ public function setup() {
+ parent::setup();
+ $testEnvironment = TestEnvironment::newDefault();
+ $this->factory = $testEnvironment->getFactory();
+ $this->fileUploader = $this->factory->newFileUploader();
+
+ // Log in as the sysop user. These credentials are referenced in docs/contributing.rst.
+ $localApiUser = new ApiUser( 'admin', 'admin123' );
+ $api = $testEnvironment->getApi();
+ $api->login( $localApiUser );
+ }
+
+ public function testUpload() {
+ $testPagename = uniqid( 'file-uploader-test-' ) . '.png';
+ $testTitle = new Title( 'File:'.$testPagename );
+
+ // Check that the file doesn't exist yet.
+ $testFile = $this->factory->newPageGetter()->getFromTitle( $testTitle );
+ $this->assertEquals( 0, $testFile->getPageIdentifier()->getId() );
+
+ // Upload a file.
+ $testFilename = dirname( __DIR__ ) . '/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.png';
+ $uploaded = $this->fileUploader->upload( $testPagename, $testFilename, 'Testing',
+ null, null, true );
+ $this->assertTrue( $uploaded );
+
+ // Get the file again, and check that it exists this time.
+ $testFile2 = $this->factory->newPageGetter()->getFromTitle( $testTitle );
+ $this->assertGreaterThan( 0, $testFile2->getPageIdentifier()->getId() );
+ }
+
+ public function testUploadByChunks() {
+ $testPagename = uniqid( 'file-uploader-test-' ) . '.png';
+ $testTitle = new Title( 'File:'.$testPagename );
+
+ // Upload a 83725 byte file in 10k chunks.
+ $testFilename = dirname( __DIR__ ) . '/fixtures/blue ℳ𝒲β™₯π“Šπ“ƒπ’Ύπ’Έβ„΄π’Ήβ„―.png';
+ $this->fileUploader->setChunkSize( 1024 * 10 );
+ $uploaded = $this->fileUploader->upload( $testPagename, $testFilename, 'Testing',
+ null, null, true );
+ $this->assertTrue( $uploaded );
+
+ // Get the file again, and check that it exists this time.
+ $testFile2 = $this->factory->newPageGetter()->getFromTitle( $testTitle );
+ $this->assertGreaterThan( 0, $testFile2->getPageIdentifier()->getId() );
+ }
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/NamespaceGetterTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/NamespaceGetterTest.php
new file mode 100644
index 00000000..eea55f9f
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/NamespaceGetterTest.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\MediawikiApi;
+use Mediawiki\Api\Service\NamespaceGetter;
+use Mediawiki\Api\SimpleRequest;
+use Mediawiki\DataModel\NamespaceInfo;
+
+class NamespaceGetterTest extends \PHPUnit_Framework_TestCase {
+ public function testGetNamespaceByCanonicalNameReturnsNullIfNamespaceWasNotFound() {
+ $nsGetter = new NamespaceGetter( $this->getApi() );
+ $this->assertNull( $nsGetter->getNamespaceByCanonicalName( 'Dummy' ) );
+ }
+
+ public function testGetNamespaceByCanonicalNameReturnsNamespaceIfNamespaceWasFound() {
+ $nsGetter = new NamespaceGetter( $this->getApi() );
+ $expectedNamespace = new NamespaceInfo( 1, 'Talk', 'Diskussion', 'first-letter' );
+ $this->assertEquals( $expectedNamespace, $nsGetter->getNamespaceByCanonicalName( 'Talk' ) );
+ }
+
+ public function testGetNamespaceByNameTriesAllNames() {
+ $nsGetter = new NamespaceGetter( $this->getApi() );
+ $expectedNamespace = new NamespaceInfo( 1, 'Talk', 'Diskussion', 'first-letter' );
+ $this->assertEquals( $expectedNamespace, $nsGetter->getNamespaceByName( 'Talk' ) );
+ $this->assertEquals( $expectedNamespace, $nsGetter->getNamespaceByName( 'Diskussion' ) );
+ }
+
+ public function testGetNamespaceByNameTriesAliases() {
+ $nsGetter = new NamespaceGetter( $this->getApi() );
+ $expectedNamespace = new NamespaceInfo(
+ 3,
+ 'User talk',
+ 'Benutzer Diskussion',
+ 'first-letter',
+ null,
+ [ 'BD', 'Benutzerin Diskussion' ]
+ );
+ $this->assertEquals( $expectedNamespace, $nsGetter->getNamespaceByName(
+ 'Benutzerin Diskussion'
+ ) );
+ $this->assertEquals( $expectedNamespace, $nsGetter->getNamespaceByName( 'BD' ) );
+ }
+
+ public function testGetNamespacesReturnsAllNamespaces() {
+ $nsGetter = new NamespaceGetter( $this->getApi() );
+ $talkNamespace = new NamespaceInfo( 1, 'Talk', 'Diskussion', 'first-letter' );
+ $gadgetNamespace = new NamespaceInfo(
+ 2302,
+ 'Gadget definition',
+ 'Gadget-Definition',
+ 'case-sensitive',
+ 'GadgetDefinition'
+ );
+ $namespaces = $nsGetter->getNamespaces();
+ $this->assertCount( 27, $namespaces );
+ $this->assertArrayHasKey( 1, $namespaces );
+ $this->assertEquals( $talkNamespace, $namespaces[1] );
+ $this->assertArrayHasKey( 2302, $namespaces );
+ $this->assertEquals( $gadgetNamespace, $namespaces[2302] );
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|MediawikiApi
+ */
+ private function getApi() {
+ $api = $this->getMockBuilder( MediawikiApi::class )->disableOriginalConstructor()->getMock();
+ $api->expects( $this->any() )
+ ->method( 'getRequest' )
+ ->with( $this->getRequest() )
+ ->willReturn( $this->getNamespaceFixture() );
+ return $api;
+ }
+
+ private function getRequest() {
+ return new SimpleRequest(
+ 'query', [
+ 'meta' => 'siteinfo',
+ 'siprop' => 'namespaces|namespacealiases'
+ ] );
+ }
+
+ private function getNamespaceFixture() {
+ return json_decode( file_get_contents( __DIR__ . '/../fixtures/namespaces.json' ), true );
+ }
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageIntegrationTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageIntegrationTest.php
new file mode 100644
index 00000000..673eac8f
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageIntegrationTest.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\DataModel\Content;
+use Mediawiki\DataModel\PageIdentifier;
+use Mediawiki\DataModel\Revision;
+use Mediawiki\DataModel\Title;
+use PHPUnit_Framework_TestCase;
+
+/**
+ * @author Addshore
+ */
+class PageIntegrationTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var PageIdentifier
+ */
+ private static $localPageIdentifier;
+
+ public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+ $title = new Title( 'TestPage - ' . strval( time() ) );
+ self::$localPageIdentifier = new PageIdentifier( $title );
+ }
+
+ public function testCreatePage() {
+ $factory = TestEnvironment::newDefault()->getFactory();
+ $this->assertTrue(
+ $factory->newRevisionSaver()->save(
+ new Revision(
+ new Content( 'testCreatePage_content' ),
+ self::$localPageIdentifier
+ )
+ ),
+ 'Failed to Create Page ' . self::$localPageIdentifier->getTitle()->getText()
+ );
+ }
+
+ /**
+ * This is testGetPageUsingTitle as currently we only know the title
+ * @depends testCreatePage
+ */
+ public function testGetPageUsingTitle() {
+ $factory = TestEnvironment::newDefault()->getFactory();
+ $page = $factory->newPageGetter()->getFromPageIdentifier( self::$localPageIdentifier );
+ $this->assertTrue( is_int( $page->getPageIdentifier()->getId() ) );
+ $title = $page->getPageIdentifier()->getTitle();
+ $this->assertEquals( self::$localPageIdentifier->getTitle(), $title );
+ $content = $page->getRevisions()->getLatest()->getContent()->getData();
+ $this->assertEquals( 'testCreatePage_content', $content );
+ self::$localPageIdentifier = $page->getPageIdentifier();
+ }
+
+ /**
+ * @depends testGetPageUsingTitle
+ */
+ public function testGetPageUsingId() {
+ $factory = TestEnvironment::newDefault()->getFactory();
+ $page = $factory->newPageGetter()->getFromPageId( self::$localPageIdentifier->getId() );
+ $this->assertEquals( self::$localPageIdentifier->getId(), $page->getPageIdentifier()->getId() );
+ $title = $page->getPageIdentifier()->getTitle();
+ $this->assertEquals( self::$localPageIdentifier->getTitle(), $title );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageListGetterTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageListGetterTest.php
new file mode 100644
index 00000000..39a973a4
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/PageListGetterTest.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\DataModel\Content;
+use Mediawiki\DataModel\PageIdentifier;
+use Mediawiki\DataModel\Revision;
+use Mediawiki\DataModel\Title;
+use PHPUnit_Framework_TestCase;
+
+/**
+ * Test the \Mediawiki\Api\Service\PageListGetter class.
+ */
+class PageListGetterTest extends PHPUnit_Framework_TestCase {
+
+ /** @var string */
+ private $emptyCatName = 'Category:Empty category';
+
+ /** @var string */
+ private $nonemptyCatName = 'Category:Test category';
+
+ /** @var \Mediawiki\Api\Service\PageListGetter */
+ private $pageListGetter;
+
+ /**
+ * Set up some test categories and pages.
+ */
+ public function setUp() {
+ $testEnvironment = TestEnvironment::newDefault();
+ $factory = $testEnvironment->getFactory();
+
+ // An empty category.
+ $emptyCat = new PageIdentifier( new Title( $this->emptyCatName ) );
+ $factory->newRevisionSaver()->save( new Revision( new Content( '' ), $emptyCat ) );
+
+ // A non-empty category.
+ $testCat = new PageIdentifier( new Title( $this->nonemptyCatName ) );
+ $factory->newRevisionSaver()->save( new Revision( new Content( '' ), $testCat ) );
+
+ // Some pages in the latter.
+ // (Count must exceed the default categorymember result set size of 10.)
+ $revisionSaver = $factory->newRevisionSaver();
+ for ( $i = 1; $i <= 35; $i++ ) {
+ $testCat = new PageIdentifier( new Title( "Test page $i" ) );
+ // Even pages link to Main Page, odd pages transclude {{test}}.
+ $mainPageLink = ( ( $i % 2 ) == 0 ) ? 'Go to [[Main Page]].' : 'This is a {{test}}.';
+ $content = new Content( "$mainPageLink\n\n[[$this->nonemptyCatName]]" );
+ $revisionSaver->save( new Revision( $content, $testCat ) );
+ }
+
+ // Run all jobs, to make sure everything is up to date.
+ $testEnvironment->runJobs();
+
+ $this->pageListGetter = $factory->newPageListGetter();
+ }
+
+ public function testGetPageListFromCategoryName() {
+ // The empty category.
+ $emptyCategory = $this->pageListGetter->getPageListFromCategoryName( $this->emptyCatName );
+ $this->assertCount( 0, $emptyCategory->toArray() );
+
+ // The nonempty category.
+ $testCategory = $this->pageListGetter->getPageListFromCategoryName( $this->nonemptyCatName );
+ $this->assertCount( 35, $testCategory->toArray() );
+ }
+
+ public function testGetPageListFromPageTransclusions() {
+ $linksHere = $this->pageListGetter->getPageListFromPageTransclusions( 'Template:Test' );
+ // Only odd-numbered test pages link to the 'Test' template.
+ $this->assertCount( 18, $linksHere->toArray() );
+ }
+
+ public function testGetFromWhatLinksHere() {
+ // Every even-numbered test page links to Main Page.
+ $mainPageLinks = $this->pageListGetter->getFromWhatLinksHere( 'Main Page' );
+ $this->assertCount( 17, $mainPageLinks->toArray() );
+
+ // Nothing links to 'Test page 4'.
+ $testPageLinks = $this->pageListGetter->getFromWhatLinksHere( 'Test page 4' );
+ $this->assertCount( 0, $testPageLinks->toArray() );
+ }
+
+ public function testGetFromPrefix() {
+ // Pages with this prefix should be test pages 1, & 10-15; i.e. 7 of them.
+ $testPages = $this->pageListGetter->getFromPrefix( 'Test page 1' );
+ $this->assertCount( 11, $testPages->toArray() );
+ }
+
+ public function testGetRandom() {
+ // Default is 1.
+ $randomPages1 = $this->pageListGetter->getRandom();
+ $this->assertCount( 1, $randomPages1->toArray() );
+
+ // 8 random pages.
+ $randomPages2 = $this->pageListGetter->getRandom( [ 'rnlimit' => 8 ] );
+ $this->assertCount( 8, $randomPages2->toArray() );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/TestEnvironment.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/TestEnvironment.php
new file mode 100644
index 00000000..f40c0cd9
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/TestEnvironment.php
@@ -0,0 +1,116 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\Guzzle\ClientFactory;
+use Mediawiki\Api\MediawikiApi;
+use Mediawiki\Api\MediawikiFactory;
+use Mediawiki\Api\SimpleRequest;
+use Monolog\Handler\StreamHandler;
+use Monolog\Logger;
+
+/**
+ * @author Addshore
+ */
+class TestEnvironment {
+
+ /** @var \Mediawiki\Api\MediawikiFactory */
+ private $factory;
+
+ /** @var MediawikiApi */
+ protected $api;
+
+ /**
+ * Get a new default test environment.
+ * @return TestEnvironment
+ */
+ public static function newDefault() {
+ return new self();
+ }
+
+ /**
+ * Set up the test environment by creating a new API object pointing to a
+ * MediaWiki installation on localhost (or elsewhere as specified by the
+ * MEDIAWIKI_API_URL environment variable).
+ */
+ public function __construct() {
+ $this->factory = new MediawikiFactory( $this->getApi() );
+ }
+
+ /**
+ * Get the MediawikiApi to test against, based on the MEDIAWIKI_API_URL environment variable.
+ * @return MediawikiApi
+ * @throws \Exception If the MEDIAWIKI_API_URL environment variable does not end in 'api.php'
+ */
+ public function getApi() {
+ if ( $this->api instanceof MediawikiApi ) {
+ return $this->api;
+ }
+ $apiUrl = getenv( 'MEDIAWIKI_API_URL' );
+ if ( empty( $apiUrl ) ) {
+ $apiUrl = 'http://localhost/w/api.php';
+ } elseif ( substr( $apiUrl, -7 ) !== 'api.php' ) {
+ $msg = "URL incorrect: $apiUrl"
+ . " (the MEDIAWIKI_API_URL environment variable should end in 'api.php')";
+ throw new \Exception( $msg );
+ }
+
+ // Log to a local file.
+ $logger = new Logger( 'mediawiki-api' );
+ $logFile = __DIR__ . '/../../log/mediawiki-api.log';
+ $logger->pushHandler( new StreamHandler( $logFile, Logger::DEBUG ) );
+
+ // Create and return the API object.
+ $this->api = new MediawikiApi( $apiUrl );
+ $this->api->setLogger( $logger );
+ return $this->api;
+ }
+
+ /**
+ * Get the MediaWiki factory.
+ *
+ * @return \Mediawiki\Api\MediawikiFactory The factory instance.
+ */
+ public function getFactory() {
+ return $this->factory;
+ }
+
+ /**
+ * Run all jobs in the queue. This only works if the MediaWiki installation has $wgJobRunRate
+ * set to greater than zero (for test-running, you should set it to something higher than 50).
+ * @todo This and TestEnvironment::getJobQueueLength() should probably not live here.
+ * @return void
+ */
+ public function runJobs() {
+ $reqestProps = [ 'meta' => 'siteinfo', 'siprop' => 'general' ];
+ $siteInfoRequest = new SimpleRequest( 'query', $reqestProps );
+ $out = $this->getApi()->getRequest( $siteInfoRequest );
+ $mainPageUrl = $out['query']['general']['base'];
+ $i = 0;
+ while ( $this->getJobQueueLength( $this->getApi() ) > 0 ) {
+ $i++;
+ $cf = new ClientFactory();
+ $cf->getClient()->get( $mainPageUrl );
+ if ($i == 10) {
+ // Give up if we've been looping too much. This is very arbitrary.
+ break;
+ }
+ }
+ }
+
+ /**
+ * Get the number of jobs currently in the queue.
+ * @todo This and TestEnvironment::runJobs() should probably not live here.
+ * @param MediawikiApi $api
+ * @return int
+ */
+ public function getJobQueueLength( MediawikiApi $api ) {
+ $req = new SimpleRequest( 'query', [
+ 'meta' => 'siteinfo',
+ 'siprop' => 'statistics',
+ ]
+ );
+ $out = $api->getRequest( $req );
+ return (int)$out['query']['statistics']['jobs'];
+ }
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/UserIntegrationTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/UserIntegrationTest.php
new file mode 100644
index 00000000..29221edb
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/UserIntegrationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\ApiUser;
+use PHPUnit_Framework_TestCase;
+
+/**
+ * @author Addshore
+ */
+class UserIntegrationTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var ApiUser
+ */
+ private static $localApiUser;
+
+ public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+ $strTime = strval( time() );
+ self::$localApiUser = new ApiUser( 'TestUser - ' . strval( time() ), $strTime . '-pass' );
+ }
+
+ public function testCreateUser() {
+ $factory = TestEnvironment::newDefault()->getFactory();
+ $createResult = $factory->newUserCreator()->create(
+ self::$localApiUser->getUsername(),
+
+
+ self::$localApiUser->getPassword()
+ );
+ $this->assertTrue( $createResult );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/phpunit.xml.dist b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/phpunit.xml.dist
new file mode 100644
index 00000000..4a0040c3
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/integration/phpunit.xml.dist
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- convertWarningsToExceptions is false as real API calls can return un expected warnings -->
+<phpunit
+ bootstrap="../../vendor/autoload.php"
+ colors="true"
+ convertWarningsToExceptions="false"
+ >
+ <testsuites>
+ <testsuite name="addwiki/mediawiki-api/integration">
+ <directory suffix="Test.php">.</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">./../../src</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/AnonymousGeneratorTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/AnonymousGeneratorTest.php
new file mode 100644
index 00000000..67d6e450
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/AnonymousGeneratorTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Mediawiki\Api\Test\Generator;
+
+use Mediawiki\Api\Generator\AnonymousGenerator;
+
+/**
+ * @author Addshore
+ *
+ * @covers \Mediawiki\Api\Generator\AnonymousGenerator
+ */
+class AnonymousGeneratorTest extends \PHPUnit_Framework_TestCase {
+
+ public function testConstruction() {
+ $generator = new AnonymousGenerator( 'name', [ 'gfoo' => 'bar' ] );
+
+ $this->assertEquals(
+ [
+ 'generator' => 'name',
+ 'gfoo' => 'bar',
+ ],
+ $generator->getParams()
+ );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/FluentGeneratorTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/FluentGeneratorTest.php
new file mode 100644
index 00000000..bd7cb0bf
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Generator/FluentGeneratorTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Mediawiki\Api\Test\Generator;
+
+use Mediawiki\Api\Generator\FluentGenerator;
+
+/**
+ * @author Addshore
+ *
+ * @covers \Mediawiki\Api\Generator\FluentGenerator
+ */
+class FluentGeneratorTest extends \PHPUnit_Framework_TestCase {
+
+ public function testConstructionWithNoGPrefix() {
+ $generator = new FluentGenerator( 'name' );
+ $generator->set( 'foo', 'bar' );
+
+ $this->assertEquals(
+ [
+ 'generator' => 'name',
+ 'gfoo' => 'bar',
+ ],
+ $generator->getParams()
+ );
+ }
+
+ public function testConstructionWithGPrefix() {
+ $generator = new FluentGenerator( 'name' );
+ $generator->set( 'gfoo', 'bar' );
+
+ $this->assertEquals(
+ [
+ 'generator' => 'name',
+ 'gfoo' => 'bar',
+ ],
+ $generator->getParams()
+ );
+ }
+
+ public function testFluidity() {
+ $generator = FluentGenerator::factory( 'name' )
+ ->set( 'foo', 'bar' )
+ ->set( 'gcat', 'meow' );
+
+ $this->assertEquals(
+ [
+ 'generator' => 'name',
+ 'gfoo' => 'bar',
+ 'gcat' => 'meow',
+ ],
+ $generator->getParams()
+ );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/MediawikiFactoryTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/MediawikiFactoryTest.php
new file mode 100644
index 00000000..c4ce958f
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/MediawikiFactoryTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Mediawiki\Api\Test;
+
+use Mediawiki\Api\MediawikiFactory;
+
+/**
+ * @covers Mediawiki\Api\MediawikiFactory
+ *
+ * @author Addshore
+ */
+class MediawikiFactoryTest extends \PHPUnit_Framework_TestCase {
+
+ public function getMockMediawikiApi() {
+ return $this->getMockBuilder( 'Mediawiki\Api\MediawikiApi' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ public function provideFactoryMethodsTest() {
+ return [
+ [ 'Mediawiki\Api\Service\RevisionSaver', 'newRevisionSaver' ],
+ [ 'Mediawiki\Api\Service\RevisionUndoer', 'newRevisionUndoer' ],
+ [ 'Mediawiki\Api\Service\PageGetter', 'newPageGetter' ],
+ [ 'Mediawiki\Api\Service\UserGetter', 'newUserGetter' ],
+ [ 'Mediawiki\Api\Service\PageDeleter', 'newPageDeleter' ],
+ [ 'Mediawiki\Api\Service\PageMover', 'newPageMover' ],
+ [ 'Mediawiki\Api\Service\PageListGetter', 'newPageListGetter' ],
+ [ 'Mediawiki\Api\Service\PageRestorer', 'newPageRestorer' ],
+ [ 'Mediawiki\Api\Service\PagePurger', 'newPagePurger' ],
+ [ 'Mediawiki\Api\Service\RevisionRollbacker', 'newRevisionRollbacker' ],
+ [ 'Mediawiki\Api\Service\RevisionPatroller', 'newRevisionPatroller' ],
+ [ 'Mediawiki\Api\Service\PageProtector', 'newPageProtector' ],
+ [ 'Mediawiki\Api\Service\PageWatcher', 'newPageWatcher' ],
+ [ 'Mediawiki\Api\Service\RevisionDeleter', 'newRevisionDeleter' ],
+ [ 'Mediawiki\Api\Service\RevisionRestorer', 'newRevisionRestorer' ],
+ [ 'Mediawiki\Api\Service\UserBlocker', 'newUserBlocker' ],
+ [ 'Mediawiki\Api\Service\UserRightsChanger', 'newUserRightsChanger' ],
+ [ 'Mediawiki\Api\Service\UserCreator', 'newUserCreator' ],
+ [ 'Mediawiki\Api\Service\LogListGetter', 'newLogListGetter' ],
+ [ 'Mediawiki\Api\Service\FileUploader', 'newFileUploader' ],
+ [ 'Mediawiki\Api\Service\ImageRotator', 'newImageRotator' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideFactoryMethodsTest
+ */
+ public function testFactoryMethod( $class, $method ) {
+ $factory = new MediawikiFactory( $this->getMockMediawikiApi() );
+ $this->assertInstanceOf( $class, $factory->$method() );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Service/PagePurgerTest.php b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Service/PagePurgerTest.php
new file mode 100644
index 00000000..38199c26
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/Service/PagePurgerTest.php
@@ -0,0 +1,187 @@
+<?php
+
+namespace Mediawiki\Api\Test\Service;
+
+use Mediawiki\Api\MediawikiApi;
+use Mediawiki\Api\Service\PagePurger;
+use Mediawiki\DataModel\Page;
+use Mediawiki\DataModel\Pages;
+use Mediawiki\DataModel\PageIdentifier;
+use Mediawiki\DataModel\Title;
+use PHPUnit_Framework_MockObject_MockObject;
+
+/**
+ * @author Addshore
+ * @covers Mediawiki\Api\Service\PagePurger
+ */
+class PagePurgerTest extends \PHPUnit_Framework_TestCase {
+
+ private function getMockApi() {
+ /** @var MediawikiApi|PHPUnit_Framework_MockObject_MockObject $mock */
+ $mock = $this->getMockBuilder( '\Mediawiki\Api\MediawikiApi' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ return $mock;
+ }
+
+ public function testValidConstruction() {
+ new PagePurger( $this->getMockApi() );
+ $this->assertTrue( true );
+ }
+
+ public function testPurgePage() {
+ $api = $this->getMockApi();
+ $api->expects( $this->once() )
+ ->method( 'postRequest' )
+ ->with(
+ $this->isInstanceOf( '\Mediawiki\Api\SimpleRequest' )
+ )
+ ->will( $this->returnValue(
+ [
+ "batchcomplete" => "",
+ "purge" => [ [ "ns" => 0, "title" => "Foo", "purged" => "" ] ]
+ ] ) );
+
+ $service = new PagePurger( $api );
+
+ $page = new Page(
+ new PageIdentifier(
+ new Title( 'Foo', 0 ),
+ 123
+ )
+ );
+
+ $this->assertTrue( $service->purge( $page ) );
+ }
+
+ function testIncorrectPurgePage() {
+ $api = $this->getMockApi();
+ $api->expects( $this->once() )
+ ->method( 'postRequest' )
+ ->with(
+ $this->isInstanceOf( '\Mediawiki\Api\SimpleRequest' )
+ )
+ ->will( $this->returnValue( [
+ "batchcomplete" => "",
+ "purge" =>
+ [ [
+ "ns" => 0,
+ "title" => "This page really does not exist",
+ "missing" => ""
+ ] ]
+ ] ) );
+
+ $service = new PagePurger( $api );
+
+ $page = new Page(
+ new PageIdentifier(
+ new Title( 'Foo', 0 ),
+ 123
+ )
+ );
+
+ $this->assertFalse( $service->purge( $page ) );
+ }
+
+ public function testPurgePages() {
+ $api = $this->getMockApi();
+ $api->expects( $this->once() )
+ ->method( 'postRequest' )
+ ->with(
+ $this->isInstanceOf( '\Mediawiki\Api\SimpleRequest' )
+ )
+ ->will( $this->returnValue(
+ [
+ "batchcomplete" => "",
+ "purge" => [
+ [
+ "ns" => 0,
+ "title" => "Foo",
+ "purged" => ""
+ ],
+ [
+ "ns" => 0,
+ "title" => "Bar",
+ "purged" => ""
+ ],
+ ]
+ ]
+ ) );
+
+ $service = new PagePurger( $api );
+
+ $pages = new Pages( [
+ new Page(
+ new PageIdentifier(
+ new Title( 'Foo', 0 ),
+ 100
+ )
+ ), new Page(
+ new PageIdentifier(
+ new Title( 'Bar', 1 ),
+ 101
+ )
+ ) ] );
+
+ $this->assertEquals( $service->purgePages( $pages ), $pages );
+ }
+
+ function testIncorrectPurgePages() {
+ $api = $this->getMockApi();
+ $api->expects( $this->once() )
+ ->method( 'postRequest' )
+ ->with(
+ $this->isInstanceOf( '\Mediawiki\Api\SimpleRequest' )
+ )
+ ->will( $this->returnValue(
+ [
+ "batchcomplete" => "",
+ "purge" => [
+ [
+ "ns" => 0,
+ "title" => "Foo",
+ "purged" => ""
+ ],
+ [
+ "ns" => 0,
+ "title" => "Bar",
+ "purged" => ""
+ ],
+ [
+ "ns" => 0,
+ "title" => "This page really does not exist",
+ "missing" => ""
+ ],
+ ]
+ ]
+ ) );
+
+ $service = new PagePurger( $api );
+
+ $pages = new Pages( [
+ new Page(
+ new PageIdentifier(
+ new Title( 'Foo', 0 ),
+ 100
+ )
+ ), new Page(
+ new PageIdentifier(
+ new Title( 'Bar', 1 ),
+ 101
+ )
+ ), new Page(
+ new PageIdentifier(
+ new Title( 'MissingPage', 1 ),
+ 103
+ )
+ ) ] );
+
+ // MissingPage is not in the pages that are returned by purgePages
+ $pagesArray = $pages->toArray();
+ array_pop( $pagesArray );
+ $result = new Pages( $pagesArray );
+
+ $this->assertEquals( $service->purgePages( $pages ), $result );
+ }
+
+}
diff --git a/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/phpunit.xml.dist b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/phpunit.xml.dist
new file mode 100644
index 00000000..8f4cecef
--- /dev/null
+++ b/bin/wiki/vendor/addwiki/mediawiki-api/tests/unit/phpunit.xml.dist
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit bootstrap="../../vendor/autoload.php" colors="true">
+ <testsuites>
+ <testsuite name="addwiki/mediawiki-api/unit">
+ <directory suffix="Test.php">.</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">./../../src</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file