Example #1
0
 /**
  * Tests cache configuration
  */
 public function test_cache_config()
 {
     $instance = cache_config::instance();
     $this->assertInstanceOf('cache_config_phpunittest', $instance);
     $this->assertTrue(cache_config_phpunittest::config_file_exists());
     $stores = $instance->get_all_stores();
     $this->assertCount(3, $stores);
     foreach ($stores as $name => $store) {
         // Check its an array.
         $this->assertInternalType('array', $store);
         // Check the name is the key.
         $this->assertEquals($name, $store['name']);
         // Check that it has been declared default.
         $this->assertTrue($store['default']);
         // Required attributes = name + plugin + configuration + modes + features.
         $this->assertArrayHasKey('name', $store);
         $this->assertArrayHasKey('plugin', $store);
         $this->assertArrayHasKey('configuration', $store);
         $this->assertArrayHasKey('modes', $store);
         $this->assertArrayHasKey('features', $store);
     }
     $modemappings = $instance->get_mode_mappings();
     $this->assertCount(3, $modemappings);
     $modes = array(cache_store::MODE_APPLICATION => false, cache_store::MODE_SESSION => false, cache_store::MODE_REQUEST => false);
     foreach ($modemappings as $mapping) {
         // We expect 3 properties.
         $this->assertCount(3, $mapping);
         // Required attributes = mode + store.
         $this->assertArrayHasKey('mode', $mapping);
         $this->assertArrayHasKey('store', $mapping);
         // Record the mode.
         $modes[$mapping['mode']] = true;
     }
     // Must have the default 3 modes and no more.
     $this->assertCount(3, $mapping);
     foreach ($modes as $mode) {
         $this->assertTrue($mode);
     }
     $definitions = $instance->get_definitions();
     // The event invalidation definition is required for the cache API and must be there.
     $this->assertArrayHasKey('core/eventinvalidation', $definitions);
     $definitionmappings = $instance->get_definition_mappings();
     foreach ($definitionmappings as $mapping) {
         // Required attributes = definition + store.
         $this->assertArrayHasKey('definition', $mapping);
         $this->assertArrayHasKey('store', $mapping);
     }
 }
 /**
  * Tests cache configuration
  */
 public function test_cache_config()
 {
     global $CFG;
     if (defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH && !empty($CFG->altcacheconfigpath)) {
         // We need to skip this test - it checks the default config structure, but very likely we arn't using the
         // default config structure here so theres no point in running the test.
         $this->markTestSkipped('Skipped testing default cache config structure as alt cache path is being used.');
     }
     if (defined('TEST_CACHE_USING_APPLICATION_STORE')) {
         // We need to skip this test - it checks the default config structure, but very likely we arn't using the
         // default config structure here because we are testing against an alternative application store.
         $this->markTestSkipped('Skipped testing default cache config structure as alt application store is being used.');
     }
     $instance = cache_config::instance();
     $this->assertInstanceOf('cache_config_phpunittest', $instance);
     $this->assertTrue(cache_config_phpunittest::config_file_exists());
     $stores = $instance->get_all_stores();
     $this->assertCount(3, $stores);
     foreach ($stores as $name => $store) {
         // Check its an array.
         $this->assertInternalType('array', $store);
         // Check the name is the key.
         $this->assertEquals($name, $store['name']);
         // Check that it has been declared default.
         $this->assertTrue($store['default']);
         // Required attributes = name + plugin + configuration + modes + features.
         $this->assertArrayHasKey('name', $store);
         $this->assertArrayHasKey('plugin', $store);
         $this->assertArrayHasKey('configuration', $store);
         $this->assertArrayHasKey('modes', $store);
         $this->assertArrayHasKey('features', $store);
     }
     $modemappings = $instance->get_mode_mappings();
     $this->assertCount(3, $modemappings);
     $modes = array(cache_store::MODE_APPLICATION => false, cache_store::MODE_SESSION => false, cache_store::MODE_REQUEST => false);
     foreach ($modemappings as $mapping) {
         // We expect 3 properties.
         $this->assertCount(3, $mapping);
         // Required attributes = mode + store.
         $this->assertArrayHasKey('mode', $mapping);
         $this->assertArrayHasKey('store', $mapping);
         // Record the mode.
         $modes[$mapping['mode']] = true;
     }
     // Must have the default 3 modes and no more.
     $this->assertCount(3, $mapping);
     foreach ($modes as $mode) {
         $this->assertTrue($mode);
     }
     $definitions = $instance->get_definitions();
     // The event invalidation definition is required for the cache API and must be there.
     $this->assertArrayHasKey('core/eventinvalidation', $definitions);
     $definitionmappings = $instance->get_definition_mappings();
     foreach ($definitionmappings as $mapping) {
         // Required attributes = definition + store.
         $this->assertArrayHasKey('definition', $mapping);
         $this->assertArrayHasKey('store', $mapping);
     }
 }