From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- tests/phpunit/includes/cache/GenderCacheTest.php | 8 +-- .../includes/cache/LocalisationCacheTest.php | 54 ++++++++++------ .../phpunit/includes/cache/RedisBloomCacheTest.php | 71 ---------------------- 3 files changed, 37 insertions(+), 96 deletions(-) delete mode 100644 tests/phpunit/includes/cache/RedisBloomCacheTest.php (limited to 'tests/phpunit/includes/cache') diff --git a/tests/phpunit/includes/cache/GenderCacheTest.php b/tests/phpunit/includes/cache/GenderCacheTest.php index ce2db5d7..04fb00d9 100644 --- a/tests/phpunit/includes/cache/GenderCacheTest.php +++ b/tests/phpunit/includes/cache/GenderCacheTest.php @@ -6,14 +6,10 @@ */ class GenderCacheTest extends MediaWikiLangTestCase { - protected function setUp() { - global $wgDefaultUserOptions; - parent::setUp(); + function addDBData() { //ensure the correct default gender - $wgDefaultUserOptions['gender'] = 'unknown'; - } + $this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', array( 'gender' => 'unknown' ) ); - function addDBData() { $user = User::newFromName( 'UTMale' ); if ( $user->getID() == 0 ) { $user->addToDatabase(); diff --git a/tests/phpunit/includes/cache/LocalisationCacheTest.php b/tests/phpunit/includes/cache/LocalisationCacheTest.php index fc06a501..a0d308aa 100644 --- a/tests/phpunit/includes/cache/LocalisationCacheTest.php +++ b/tests/phpunit/includes/cache/LocalisationCacheTest.php @@ -7,18 +7,32 @@ */ class LocalisationCacheTest extends MediaWikiTestCase { protected function setUp() { - global $IP; - parent::setUp(); $this->setMwGlobals( array( - 'wgMessagesDirs' => array( "$IP/tests/phpunit/data/localisationcache" ), 'wgExtensionMessagesFiles' => array(), 'wgHooks' => array(), ) ); } + /** + * @return PHPUnit_Framework_MockObject_MockObject|LocalisationCache + */ + protected function getMockLocalisationCache() { + global $IP; + $lc = $this->getMockBuilder( 'LocalisationCache' ) + ->setConstructorArgs( array( array( 'store' => 'detect' ) ) ) + ->setMethods( array( 'getMessagesDirs' ) ) + ->getMock(); + $lc->expects( $this->any() )->method( 'getMessagesDirs' ) + ->will( $this->returnValue( + array( "$IP/tests/phpunit/data/localisationcache" ) + ) ); + + return $lc; + } + public function testPuralRulesFallback() { - $cache = new LocalisationCache( array( 'store' => 'detect' ) ); + $cache = $this->getMockLocalisationCache(); $this->assertEquals( $cache->getItem( 'ar', 'pluralRules' ), @@ -46,7 +60,7 @@ class LocalisationCacheTest extends MediaWikiTestCase { } public function testRecacheFallbacks() { - $lc = new LocalisationCache( array( 'store' => 'detect' ) ); + $lc = $this->getMockLocalisationCache(); $lc->recache( 'uk' ); $this->assertEquals( array( @@ -60,23 +74,25 @@ class LocalisationCacheTest extends MediaWikiTestCase { } public function testRecacheFallbacksWithHooks() { - global $wgHooks; - // Use hook to provide updates for messages. This is what the // LocalisationUpdate extension does. See bug 68781. - $wgHooks['LocalisationCacheRecacheFallback'][] = function ( - LocalisationCache $lc, - $code, - array &$cache - ) { - if ( $code === 'ru' ) { - $cache['messages']['present-uk'] = 'ru-override'; - $cache['messages']['present-ru'] = 'ru-override'; - $cache['messages']['present-en'] = 'ru-override'; - } - }; + $this->mergeMwGlobalArrayValue( 'wgHooks', array( + 'LocalisationCacheRecacheFallback' => array( + function ( + LocalisationCache $lc, + $code, + array &$cache + ) { + if ( $code === 'ru' ) { + $cache['messages']['present-uk'] = 'ru-override'; + $cache['messages']['present-ru'] = 'ru-override'; + $cache['messages']['present-en'] = 'ru-override'; + } + } + ) + ) ); - $lc = new LocalisationCache( array( 'store' => 'detect' ) ); + $lc = $this->getMockLocalisationCache(); $lc->recache( 'uk' ); $this->assertEquals( array( diff --git a/tests/phpunit/includes/cache/RedisBloomCacheTest.php b/tests/phpunit/includes/cache/RedisBloomCacheTest.php deleted file mode 100644 index 3d491e90..00000000 --- a/tests/phpunit/includes/cache/RedisBloomCacheTest.php +++ /dev/null @@ -1,71 +0,0 @@ -delete( "unit-testing-" . self::$suffix ); - } else { - $this->markTestSkipped( 'The main bloom cache is not redis.' ); - } - } - - public function testBloomCache() { - $key = "unit-testing-" . self::$suffix; - $fcache = BloomCache::get( 'main' ); - $count = 1500; - - $this->assertTrue( $fcache->delete( $key ), "OK delete of filter '$key'." ); - $this->assertTrue( $fcache->init( $key, $count, .001 ), "OK init of filter '$key'." ); - - $members = array(); - for ( $i = 0; $i < $count; ++$i ) { - $members[] = "$i-value-$i"; - } - $this->assertTrue( $fcache->add( $key, $members ), "Addition of members to '$key' OK." ); - - for ( $i = 0; $i < $count; ++$i ) { - $this->assertTrue( $fcache->isHit( $key, "$i-value-$i" ), "Hit on member '$i-value-$i'." ); - } - - $falsePositives = array(); - for ( $i = $count; $i < 2 * $count; ++$i ) { - if ( $fcache->isHit( $key, "value$i" ) ) { - $falsePositives[] = "value$i"; - } - } - - $eFalsePositives = array( - 'value1763', - 'value2245', - 'value2353', - 'value2791', - 'value2898', - 'value2975' - ); - $this->assertEquals( $eFalsePositives, $falsePositives, "Correct number of false positives found." ); - } - - protected function tearDown() { - parent::tearDown(); - - $fcache = BloomCache::get( 'main' ); - if ( $fcache instanceof BloomCacheRedis ) { - $fcache->delete( "unit-testing-" . self::$suffix ); - } - } -} -- cgit v1.2.2