Exemplo n.º 1
0
 /**
  * Test disabling the cache.
  */
 public function test_disable()
 {
     global $CFG;
     $configfile = $CFG->dataroot . '/muc/config.php';
     // That's right, we're deleting the config file.
     $this->assertTrue(@unlink($configfile));
     // Disable the cache
     cache_phpunit_factory::phpunit_disable();
     // Check we get the expected disabled factory.
     $factory = cache_factory::instance();
     $this->assertInstanceOf('cache_factory_disabled', $factory);
     // Check we get the expected disabled config.
     $config = $factory->create_config_instance();
     $this->assertInstanceOf('cache_config_disabled', $config);
     // Check we get the expected disabled caches.
     $cache = cache::make('phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $this->assertFalse(file_exists($configfile));
     $this->assertFalse($cache->get('test'));
     $this->assertFalse($cache->set('test', 'test'));
     $this->assertFalse($cache->delete('test'));
     $this->assertTrue($cache->purge());
     cache_factory::reset();
     $factory = cache_factory::instance(true);
     $config = $factory->create_config_instance();
     $this->assertEquals('cache_config_phpunittest', get_class($config));
 }
Exemplo n.º 2
0
 /**
  * Test disabling the cache.
  */
 public function test_disable()
 {
     global $CFG;
     if (defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH || !empty($CFG->altcacheconfigpath)) {
         // We can't run this test as it requires us to delete the cache configuration script which we just
         // cant do with a custom path in play.
         $this->markTestSkipped('Skipped testing cache disable functionality as alt cache path is being used.');
     }
     $configfile = $CFG->dataroot . '/muc/config.php';
     // That's right, we're deleting the config file.
     $this->assertTrue(@unlink($configfile));
     // Disable the cache
     cache_phpunit_factory::phpunit_disable();
     // Check we get the expected disabled factory.
     $factory = cache_factory::instance();
     $this->assertInstanceOf('cache_factory_disabled', $factory);
     // Check we get the expected disabled config.
     $config = $factory->create_config_instance();
     $this->assertInstanceOf('cache_config_disabled', $config);
     // Check we get the expected disabled caches.
     $cache = cache::make('phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     // Test an application cache.
     $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $this->assertFalse(file_exists($configfile));
     $this->assertFalse($cache->get('test'));
     $this->assertFalse($cache->set('test', 'test'));
     $this->assertFalse($cache->delete('test'));
     $this->assertTrue($cache->purge());
     // Test a session cache.
     $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $this->assertFalse(file_exists($configfile));
     $this->assertFalse($cache->get('test'));
     $this->assertFalse($cache->set('test', 'test'));
     $this->assertFalse($cache->delete('test'));
     $this->assertTrue($cache->purge());
     // Finally test a request cache.
     $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $this->assertFalse(file_exists($configfile));
     $this->assertFalse($cache->get('test'));
     $this->assertFalse($cache->set('test', 'test'));
     $this->assertFalse($cache->delete('test'));
     $this->assertTrue($cache->purge());
     cache_factory::reset();
     $factory = cache_factory::instance(true);
     $config = $factory->create_config_instance();
     $this->assertEquals('cache_config_testing', get_class($config));
 }