Permalink
Browse files

MDL-36363 cache: added unit tests for muliple loaders

  • Loading branch information...
1 parent 4786eca commit 8003618cd1ec8305b28183a96c66d9042db928cd Sam Hemelryk committed Jan 30, 2013
Showing with 61 additions and 0 deletions.
  1. +22 −0 cache/tests/cache_test.php
  2. +39 −0 cache/tests/fixtures/lib.php
View
@@ -744,4 +744,26 @@ public function test_disable() {
$config = $factory->create_config_instance();
$this->assertEquals('cache_config_phpunittest', get_class($config));
}
+
+ /**
+ * Test that multiple loaders work ok.
+ */
+ public function test_multiple_loaders() {
+ $instance = cache_config_phpunittest::instance(true);
+ $instance->phpunit_add_file_store('phpunittest1');
+ $instance->phpunit_add_file_store('phpunittest2');
+ $instance->phpunit_add_definition('phpunit/multi_loader', array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'component' => 'phpunit',
+ 'area' => 'multi_loader'
+ ));
+ $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest1', 3);
+ $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2);
+
+ $cache = cache::make('phpunit', 'multi_loader');
+ $this->assertInstanceOf('cache_application', $cache);
+ $this->assertFalse($cache->get('test'));
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertEquals('test', $cache->get('test'));
+ }
}
@@ -63,6 +63,45 @@ public function phpunit_add_definition($area, array $properties) {
public function phpunit_remove_stores() {
$this->configstores = array();
}
+
+ /**
+ * Forcefully adds a file store.
+ *
+ * @param string $name
+ */
+ public function phpunit_add_file_store($name) {
+ $this->configstores[$name] = array(
+ 'name' => $name,
+ 'plugin' => 'file',
+ 'configuration' => array(
+ 'path' => ''
+ ),
+ 'features' => 6,
+ 'modes' => 3,
+ 'mappingsonly' => false,
+ 'class' => 'cachestore_file',
+ 'default' => false,
+ 'lock' => 'cachelock_file_default'
+ );
+ }
+
+ /**
+ * Forcefully injects a definition => store mapping.
+ *
+ * This function does no validation, you should only be calling if it you know
+ * exactly what to expect.
+ *
+ * @param string $definition
+ * @param string $store
+ * @param int $sort
+ */
+ public function phpunit_add_definition_mapping($definition, $store, $sort) {
+ $this->configdefinitionmappings[] = array(
+ 'store' => $store,
+ 'definition' => $definition,
+ 'sort' => (int)$sort
+ );
+ }
}
/**

0 comments on commit 8003618

Please sign in to comment.