diff options
Diffstat (limited to 'bin/wiki/vendor/addwiki/mediawiki-api/tests/integration')
8 files changed, 698 insertions, 0 deletions
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 |