Skip to content

Commit

Permalink
Merge branch 'MDL-40555-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	cache/stores/static/lib.php
  • Loading branch information
stronk7 committed Jul 16, 2013
2 parents 259e3c2 + 4a749e9 commit 3f0a887
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
29 changes: 27 additions & 2 deletions cache/stores/static/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected static function flush_store() {
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cachestore_static extends static_data_store implements cache_is_key_aware {
class cachestore_static extends static_data_store implements cache_is_key_aware, cache_is_searchable {

/**
* The name of the store
Expand Down Expand Up @@ -133,7 +133,8 @@ public function __construct($name, array $configuration = array()) {
*/
public static function get_supported_features(array $configuration = array()) {
return self::SUPPORTS_DATA_GUARANTEE +
self::SUPPORTS_NATIVE_TTL;
self::SUPPORTS_NATIVE_TTL +
self::IS_SEARCHABLE;
}

/**
Expand Down Expand Up @@ -418,4 +419,28 @@ public static function initialise_test_instance(cache_definition $definition) {
public function my_name() {
return $this->name;
}

/**
* Finds all of the keys being stored in the cache store instance.
*
* @return array
*/
public function find_all() {
return array_keys($this->store);
}

/**
* Finds all of the keys whose keys start with the given prefix.
*
* @param string $prefix
*/
public function find_by_prefix($prefix) {
$return = array();
foreach ($this->find_all() as $key) {
if (strpos($key, $prefix) === 0) {
$return[] = $key;
}
}
return $return;
}
}
50 changes: 50 additions & 0 deletions cache/tests/cache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,54 @@ public function test_purge_routines() {
$this->assertContains('Identifier required for cache has not been provided', $ex->getMessage());
}
}

/**
* Test that the default stores all support searching.
*/
public function test_defaults_support_searching() {
$instance = cache_config_phpunittest::instance(true);
$instance->phpunit_add_definition('phpunit/search1', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'search1',
'requiresearchable' => true
));
$instance->phpunit_add_definition('phpunit/search2', array(
'mode' => cache_store::MODE_SESSION,
'component' => 'phpunit',
'area' => 'search2',
'requiresearchable' => true
));
$instance->phpunit_add_definition('phpunit/search3', array(
'mode' => cache_store::MODE_REQUEST,
'component' => 'phpunit',
'area' => 'search3',
'requiresearchable' => true
));
$factory = cache_factory::instance();

// Test application cache is searchable.
$definition = $factory->create_definition('phpunit', 'search1');
$this->assertInstanceOf('cache_definition', $definition);
$this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
$cache = $factory->create_cache($definition);
$this->assertInstanceOf('cache_application', $cache);
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());

// Test session cache is searchable.
$definition = $factory->create_definition('phpunit', 'search2');
$this->assertInstanceOf('cache_definition', $definition);
$this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
$cache = $factory->create_cache($definition);
$this->assertInstanceOf('cache_session', $cache);
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());

// Test request cache is searchable.
$definition = $factory->create_definition('phpunit', 'search3');
$this->assertInstanceOf('cache_definition', $definition);
$this->assertEquals(cache_store::IS_SEARCHABLE, $definition->get_requirements_bin() & cache_store::IS_SEARCHABLE);
$cache = $factory->create_cache($definition);
$this->assertInstanceOf('cache_request', $cache);
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
}
}
23 changes: 23 additions & 0 deletions cache/tests/fixtures/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public function phpunit_get_store_class() {
return get_class($this->get_store());
}

/**
* Returns all the interfaces the cache store implements.
* @return array
*/
public function phpunit_get_store_implements() {
return class_implements($this->get_store());
}
}

/**
Expand All @@ -245,6 +252,14 @@ class cache_phpunit_session extends cache_session {
public function phpunit_get_store_class() {
return get_class($this->get_store());
}

/**
* Returns all the interfaces the cache store implements.
* @return array
*/
public function phpunit_get_store_implements() {
return class_implements($this->get_store());
}
}

/**
Expand All @@ -264,6 +279,14 @@ class cache_phpunit_request extends cache_request {
public function phpunit_get_store_class() {
return get_class($this->get_store());
}

/**
* Returns all the interfaces the cache store implements.
* @return array
*/
public function phpunit_get_store_implements() {
return class_implements($this->get_store());
}
}

/**
Expand Down

0 comments on commit 3f0a887

Please sign in to comment.