Beispiel #1
0
 /**
  * testTranslationCaching method
  *
  * @return void
  */
 public function testTranslationCaching()
 {
     $this->skipIf(!Cache::engine('_cake_core_'), 'Missing _cake_core_ cache config, cannot test caching.');
     Configure::write('Config.language', 'cache_test_po');
     // reset internally stored entries
     I18n::clear();
     Cache::clear(false, '_cake_core_');
     $lang = Configure::read('Config.language');
     // make some calls to translate using different domains
     $this->assertEquals('Dom 1 Foo', I18n::translate('dom1.foo', false, 'dom1'));
     $this->assertEquals('Dom 1 Bar', I18n::translate('dom1.bar', false, 'dom1'));
     $domains = I18n::domains();
     $this->assertEquals('Dom 1 Foo', $domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo']);
     // reset internally stored entries
     I18n::clear();
     // now only dom1 should be in cache
     $cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_');
     $this->assertEquals('Dom 1 Foo', $cachedDom1['LC_MESSAGES']['dom1.foo']);
     $this->assertEquals('Dom 1 Bar', $cachedDom1['LC_MESSAGES']['dom1.bar']);
     // dom2 not in cache
     $this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_'));
     // translate a item of dom2 (adds dom2 to cache)
     $this->assertEquals('Dom 2 Foo', I18n::translate('dom2.foo', false, 'dom2'));
     // verify dom2 was cached through manual read from cache
     $cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_');
     $this->assertEquals('Dom 2 Foo', $cachedDom2['LC_MESSAGES']['dom2.foo']);
     $this->assertEquals('Dom 2 Bar', $cachedDom2['LC_MESSAGES']['dom2.bar']);
     // modify cache entry manually to verify that dom1 entries now will be read from cache
     $cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO';
     Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_');
     $this->assertEquals('FOO', I18n::translate('dom1.foo', false, 'dom1'));
 }
 /**
  * testConfig method
  *
  * @return void
  */
 public function testConfig()
 {
     $config = Cache::engine('xcache')->config();
     $expecting = ['prefix' => 'cake_', 'duration' => 3600, 'probability' => 100];
     $this->assertTrue(isset($config['PHP_AUTH_USER']));
     $this->assertTrue(isset($config['PHP_AUTH_PW']));
     unset($config['PHP_AUTH_USER'], $config['PHP_AUTH_PW']);
     $this->assertEquals($config, $expecting);
 }
Beispiel #3
0
 /**
  * Ensure that subrequests don't double proxy the cache engine.
  *
  * @return void
  */
 public function testInitializeTwiceNoDoubleProxy()
 {
     $event = new Event('Sample');
     $this->panel->initialize($event);
     $result = Cache::engine('debug_kit_test');
     $this->assertInstanceOf('DebugKit\\Cache\\Engine\\DebugEngine', $result);
     $this->panel->initialize($event);
     $result2 = Cache::engine('debug_kit_test');
     $this->assertSame($result2, $result);
 }
Beispiel #4
0
 /**
  * Returns the translators collection instance. It can be used
  * for getting specific translators based of their name and locale
  * or to configure some aspect of future translations that are not yet constructed.
  *
  * @return \Aura\Intl\TranslatorLocator The translators collection.
  */
 public static function translators()
 {
     if (static::$_collection !== null) {
         return static::$_collection;
     }
     static::$_collection = new TranslatorRegistry(new PackageLocator(), new FormatterLocator(['sprintf' => function () {
         return new SprintfFormatter();
     }, 'default' => function () {
         return new IcuFormatter();
     }]), new TranslatorFactory(), static::locale());
     if (class_exists('Cake\\Cache\\Cache')) {
         static::$_collection->setCacher(Cache::engine('_cake_core_'));
     }
     return static::$_collection;
 }
Beispiel #5
0
 /**
  * Clear metadata.
  *
  * @param string|null $prefix The cache prefix to be cleared.
  * @throws \Cake\Console\Exception\StopException
  * @return void
  */
 public function clear($prefix = null)
 {
     try {
         $engine = Cache::engine($prefix);
         Cache::clear(false, $prefix);
         if ($engine instanceof ApcEngine) {
             $this->warn("ApcEngine detected: Cleared {$prefix} CLI cache successfully " . "but {$prefix} web cache must be cleared separately.");
         } elseif ($engine instanceof WincacheEngine) {
             $this->warn("WincacheEngine detected: Cleared {$prefix} CLI cache successfully " . "but {$prefix} web cache must be cleared separately.");
         } else {
             $this->out("<success>Cleared {$prefix} cache</success>");
         }
     } catch (\InvalidArgumentException $e) {
         $this->abort($e->getMessage());
     }
 }
 /**
  * testConfig method
  *
  * @return void
  */
 public function testConfig()
 {
     $config = Cache::engine('memcached')->config();
     unset($config['path']);
     $expecting = ['prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => ['127.0.0.1'], 'persistent' => false, 'compress' => false, 'username' => null, 'password' => null, 'groups' => [], 'serialize' => 'php', 'options' => [], 'host' => null, 'port' => null];
     $this->assertEquals($expecting, $config);
 }
Beispiel #7
0
 /**
  * Get the cache engine.
  *
  * @return \Cake\Cache\CacheEngine
  */
 protected function _resolveCacher()
 {
     if (is_string($this->_config)) {
         return Cache::engine($this->_config);
     }
     return $this->_config;
 }
 /**
  * testConnect method
  *
  * @return void
  */
 public function testConnect()
 {
     $Redis = new RedisEngine();
     $this->assertTrue($Redis->init(Cache::engine('redis')->config()));
 }
Beispiel #9
0
 /**
  * test that drop removes cache configs, and that further attempts to use that config
  * do not work.
  *
  * @return void
  */
 public function testDrop()
 {
     Configure::write('App.namespace', 'TestApp');
     $result = Cache::drop('some_config_that_does_not_exist');
     $this->assertFalse($result, 'Drop should not succeed when config is missing.');
     Cache::config('unconfigTest', ['engine' => 'TestAppCache']);
     $this->assertInstanceOf('TestApp\\Cache\\Engine\\TestAppCacheEngine', Cache::engine('unconfigTest'));
     $this->assertTrue(Cache::drop('unconfigTest'));
 }
 /**
  * testConfig method
  *
  * @return void
  */
 public function testConfig()
 {
     $config = Cache::engine('memcached')->config();
     unset($config['path']);
     $expecting = array('prefix' => 'cake_', 'duration' => 3600, 'probability' => 100, 'servers' => array('127.0.0.1'), 'persistent' => false, 'compress' => false, 'login' => null, 'password' => null, 'groups' => array(), 'serialize' => 'php');
     $this->assertEquals($expecting, $config);
 }
Beispiel #11
0
 /**
  * Constructor
  *
  * @param string $alias Cache name alias.
  */
 public function __construct($alias)
 {
     $this->_engine = Cache::engine($alias);
 }