summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/cache
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/cache')
-rw-r--r--tests/phpunit/includes/cache/GenderCacheTest.php8
-rw-r--r--tests/phpunit/includes/cache/LocalisationCacheTest.php54
-rw-r--r--tests/phpunit/includes/cache/RedisBloomCacheTest.php71
3 files changed, 37 insertions, 96 deletions
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 @@
-<?php
-
-/**
- * Test for BloomCacheRedis class.
- *
- * @TODO: some generic base "redis test server conf" for all testing?
- *
- * @covers BloomCacheRedis
- * @group Cache
- */
-class BloomCacheRedisTest extends MediaWikiTestCase {
- private static $suffix;
-
- protected function setUp() {
- parent::setUp();
-
- self::$suffix = self::$suffix ? : mt_rand();
-
- $fcache = BloomCache::get( 'main' );
- if ( $fcache instanceof BloomCacheRedis ) {
- $fcache->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 );
- }
- }
-}