X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Finterwiki%2FInterwikiTest.php;h=409805bab7c4349cadff5c31784274b9aab23784;hp=b1ad77a7e50284ff1d03c1b33eb8856b1baa18dc;hb=c2b506a59f3ad1b8b4a7123b91a6b1395841743a;hpb=4cb9c1a24bde6e29c5e8f05c7cd1de54ffdd342a diff --git a/tests/phpunit/includes/interwiki/InterwikiTest.php b/tests/phpunit/includes/interwiki/InterwikiTest.php index b1ad77a7e5..409805bab7 100644 --- a/tests/phpunit/includes/interwiki/InterwikiTest.php +++ b/tests/phpunit/includes/interwiki/InterwikiTest.php @@ -106,7 +106,7 @@ class InterwikiTest extends MediaWikiTestCase { $this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' ); $interwiki = $interwikiLookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' ); $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); @@ -115,150 +115,8 @@ class InterwikiTest extends MediaWikiTestCase { $this->assertSame( true, $interwiki->isLocal(), 'isLocal' ); $this->assertSame( false, $interwiki->isTranscludable(), 'isTranscludable' ); - Interwiki::invalidateCache( 'de' ); + $interwikiLookup->invalidateCache( 'de' ); $this->assertNotSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'invalidate cache' ); } - /** - * @param string $thisSite - * @param string[] $local - * @param string[] $global - * - * @return string[] - */ - private function populateHash( $thisSite, $local, $global ) { - $hash = []; - $hash[ '__sites:' . wfWikiID() ] = $thisSite; - - $globals = []; - $locals = []; - - foreach ( $local as $row ) { - $prefix = $row['iw_prefix']; - $data = $row['iw_local'] . ' ' . $row['iw_url']; - $locals[] = $prefix; - $hash[ "_{$thisSite}:{$prefix}" ] = $data; - } - - foreach ( $global as $row ) { - $prefix = $row['iw_prefix']; - $data = $row['iw_local'] . ' ' . $row['iw_url']; - $globals[] = $prefix; - $hash[ "__global:{$prefix}" ] = $data; - } - - $hash[ '__list:__global' ] = implode( ' ', $globals ); - $hash[ '__list:_' . $thisSite ] = implode( ' ', $locals ); - - return $hash; - } - - private function populateCDB( $thisSite, $local, $global ) { - $cdbFile = tempnam( wfTempDir(), 'MW-ClassicInterwikiLookupTest-' ) . '.cdb'; - $cdb = CdbWriter::open( $cdbFile ); - - $hash = $this->populateHash( $thisSite, $local, $global ); - - foreach ( $hash as $key => $value ) { - $cdb->set( $key, $value ); - } - - $cdb->close(); - return $cdbFile; - } - - public function testCDBStorage() { - // NOTE: CDB setup is expensive, so we only do - // it once and run all the tests in one go. - - $dewiki = [ - 'iw_prefix' => 'de', - 'iw_url' => 'http://de.wikipedia.org/wiki/', - 'iw_local' => 1 - ]; - - $zzwiki = [ - 'iw_prefix' => 'zz', - 'iw_url' => 'http://zzwiki.org/wiki/', - 'iw_local' => 0 - ]; - - $cdbFile = $this->populateCDB( - 'en', - [ $dewiki ], - [ $zzwiki ] - ); - - $this->setWgInterwikiCache( $cdbFile ); - - $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup(); - $this->assertEquals( - [ $dewiki, $zzwiki ], - $interwikiLookup->getAllPrefixes(), - 'getAllPrefixes()' - ); - - $this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' ); - $this->assertTrue( $interwikiLookup->isValidInterwiki( 'zz' ), 'known prefix is valid' ); - - $interwiki = $interwikiLookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); - - $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); - $this->assertSame( true, $interwiki->isLocal(), 'isLocal' ); - - $interwiki = $interwikiLookup->fetch( 'zz' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); - - $this->assertSame( 'http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL' ); - $this->assertSame( false, $interwiki->isLocal(), 'isLocal' ); - - // cleanup temp file - unlink( $cdbFile ); - } - - public function testArrayStorage() { - $dewiki = [ - 'iw_prefix' => 'de', - 'iw_url' => 'http://de.wikipedia.org/wiki/', - 'iw_local' => 1 - ]; - - $zzwiki = [ - 'iw_prefix' => 'zz', - 'iw_url' => 'http://zzwiki.org/wiki/', - 'iw_local' => 0 - ]; - - $cdbData = $this->populateHash( - 'en', - [ $dewiki ], - [ $zzwiki ] - ); - - $this->setWgInterwikiCache( $cdbData ); - - $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup(); - $this->assertEquals( - [ $dewiki, $zzwiki ], - $interwikiLookup->getAllPrefixes(), - 'getAllPrefixes()' - ); - - $this->assertTrue( $interwikiLookup->isValidInterwiki( 'de' ), 'known prefix is valid' ); - $this->assertTrue( $interwikiLookup->isValidInterwiki( 'zz' ), 'known prefix is valid' ); - - $interwiki = $interwikiLookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); - - $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); - $this->assertSame( true, $interwiki->isLocal(), 'isLocal' ); - - $interwiki = $interwikiLookup->fetch( 'zz' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); - - $this->assertSame( 'http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL' ); - $this->assertSame( false, $interwiki->isLocal(), 'isLocal' ); - } - }