public function testPluginWithMaster() { $c = $this->_root->getComponentByClass('Kwf_Component_Plugin_Interface_UseViewCache_Component'); Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = true; $html1 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $html2 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $html3 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $this->assertEquals($html1, $html2); $this->assertEquals($html1, $html3); apc_clear_cache('user'); Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean(); Kwf_Cache_Simple::resetZendCache(); Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = false; $html4 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $html5 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $html6 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $this->assertNotEquals($html3, $html4); $this->assertNotEquals($html4, $html5); $this->assertNotEquals($html4, $html6); $this->assertNotEquals($html5, $html6); Kwf_Component_Plugin_Interface_UseViewCache_Plugin_Component::$useViewCache = true; $html7 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $html8 = $c->render(true, true); Kwf_Component_Plugin_Interface_UseViewCache_Component::$num++; $this->assertEquals($html7, $html3); $this->assertEquals($html8, $html3); }
private function _setup($rootClass) { Kwf_Component_Data_Root::setComponentClass($rootClass); $this->_root = Kwf_Component_Data_Root::getInstance(); Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF); Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean(); Kwf_Cache_Simple::resetZendCache(); }
public function setUp() { apc_clear_cache('user'); Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean(); Kwf_Cache_Simple::resetZendCache(); parent::setUp(); Kwf_Events_Dispatcher::addListeners('Kwf_Model_RowCache_RowCacheModel'); Kwf_Model_Abstract::getInstance('Kwf_Model_RowCache_SourceModel')->setData(array(array('id' => 1, 'foo' => 1, 'bar' => 'x1'), array('id' => 2, 'foo' => 2, 'bar' => 'x2'), array('id' => 3, 'foo' => 3, 'bar' => 'x3'), array('id' => 4, 'foo' => 4, 'bar' => 'x4'))); }
public function setUp() { parent::setUp(); //clear view cache Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean(); Kwf_Cache_Simple::resetZendCache(); Kwf_Component_Data_Root::setComponentClass('Kwc_FavouritesSelenium_Root'); //use custom user model $this->presetModel = Kwf_Registry::get('config')->user->model; Kwf_Registry::get('config')->user->model = 'Kwc_FavouritesSelenium_UserModel'; //unset existing userModel instance to get new one $reg = Kwf_Registry::getInstance()->set('userModel', Kwf_Model_Abstract::getInstance('Kwc_FavouritesSelenium_UserModel')); }
protected function _init($componentClass) { Kwf_Component_Data_Root::setComponentClass($componentClass); Zend_Session::$_unitTestEnabled = true; $this->_root = Kwf_Component_Data_Root::getInstance(); $this->_root->setFilename('kwf/kwctest/' . $componentClass); if (function_exists('apc_clear_cache')) { apc_clear_cache('user'); } Kwf_Component_Cache_Memory::getInstance()->_clean(); Kwf_Cache_Simple::resetZendCache(); Kwc_FulltextSearch_MetaModel::setInstance(new Kwf_Model_FnF(array('primaryKey' => 'page_id'))); Kwf_Assets_Package_Default::clearInstances(); Kwf_Component_LogDuplicateModel::setInstance(new Kwf_Model_FnF(array())); Kwf_Media_MemoryCache::getInstance()->clean(); return $this->_root; }
public static function _handleEvent($event) { $eventStart = microtime(true); Kwf_Cache_Simple::resetZendCache(); //reset to re-fetch namespace if (substr($event->filename, -4) == '.css' || substr($event->filename, -3) == '.js' || substr($event->filename, -9) == '.printcss' || substr($event->filename, -5) == '.scss') { echo "asset modified\n"; if ($event instanceof Event\Modify) { //there is no cache for individual files, scss cache is handled in Kwf_Assets_Dependency_File_Scss using mtime $assetsType = substr($event->filename, strrpos($event->filename, '.') + 1); if ($assetsType == 'scss') { $assetsType = 'css'; } self::_clearAssetsAll($assetsType); if ($assetsType == 'js') { self::_clearAssetsAll('defer.js'); } } else { if ($event instanceof Event\Create || $event instanceof Event\Delete || $event instanceof Event\Move) { self::_clearAssetsDependencies(); $assetsType = substr($event->filename, strrpos($event->filename, '.') + 1); if ($assetsType == 'scss') { $assetsType = 'css'; } self::_clearAssetsAll($assetsType); if ($assetsType == 'js') { self::_clearAssetsAll('defer.js'); } } } } else { if (self::_endsWith($event->filename, '/dependencies.ini')) { if ($event instanceof Event\Modify) { self::_clearAssetsDependencies(); self::_clearAssetsAll(); } } else { if (preg_match('#/config([^/]*)?\\.ini$#', $event->filename)) { //config.ini, configPoi.ini, config.local.ini (in any directory) if ($event instanceof Event\Modify) { $section = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection')); $cacheId = 'config_' . str_replace('-', '_', $section); Kwf_Config_Cache::getInstance()->remove($cacheId); echo "removed config cache\n"; $apcCacheId = $cacheId . getcwd(); $cacheIds = array($apcCacheId, $apcCacheId . 'mtime'); $simpleCacheStaticPrefixes = array('config-', 'configAr-'); if (Kwf_Util_Apc::isAvailable()) { self::_clearApcCache(array('cacheIds' => $cacheIds, 'clearCacheSimpleStatic' => $simpleCacheStaticPrefixes)); echo "cleared apc config cache\n"; } else { foreach ($simpleCacheStaticPrefixes as $i) { Kwf_Cache_SimpleStatic::clear($i); } } $cmd = Kwf_Config::getValue('server.phpCli') . " bootstrap.php clear-cache --type=setup"; exec($cmd, $out, $ret); echo "cleared setup.php cache"; if ($ret) { echo " [FAILED]"; } echo "\n"; } } else { if (preg_match('#(Acl|MenuConfig)\\.php$#', $event->filename)) { if ($event instanceof Event\Modify) { Kwf_Acl::clearCache(); echo "cleared acl cache...\n"; } } else { if (self::_endsWith($event->filename, '.twig')) { $loader = new Twig_Loader_Filesystem('.'); $twig = new Twig_Environment($loader, array('cache' => 'cache/twig')); $cacheFile = $event->filename; $cacheFile = substr($cacheFile, strlen(getcwd()) + 1); $cacheFile = $twig->getCacheFilename($cacheFile); if (file_exists($cacheFile)) { unlink($cacheFile); echo "cleared twig cache file '{$cacheFile}' for template '{$event->filename}'\n"; } } } } } } if (self::_startsWith($event->filename, getcwd() . '/components') || self::_startsWith($event->filename, getcwd() . '/theme') || self::_startsWith($event->filename, KWF_PATH . '/Kwc') || defined('VKWF_PATH') && self::_startsWith($event->filename, VKWF_PATH . '/Vkwc')) { $cls = null; foreach (explode(PATH_SEPARATOR, get_include_path()) as $ip) { if (substr($ip, 0, 1) == '.') { $ip = getcwd() . substr($ip, 1); } if (substr($ip, 0, 1) != '/') { $ip = getcwd() . '/' . $ip; } if (self::_startsWith($event->filename, $ip)) { $cls = str_replace('/', '_', substr($event->filename, strlen($ip) + 1, -4)); } } if (!$cls) { echo "unknown component class?!\n"; return; } if (!self::_endsWith($event->filename, '/Component.php')) { //other component file $cls = substr($cls, 0, strrpos($cls, '_')) . '_Component'; } echo "component {$cls}\n"; if (!@class_exists($cls)) { echo "parse error: {$cls}\n"; return; } $matchingClasses = array(); try { foreach (Kwc_Abstract::getComponentClasses() as $c) { if (is_instance_of($c, $cls)) { $matchingClasses[] = $c; } } } catch (Exception $e) { } if (self::_endsWith($event->filename, '/Admin.php') || self::_endsWith($event->filename, '/Master.tpl') || self::_endsWith($event->filename, '/Component.tpl') || self::_endsWith($event->filename, '/Partial.tpl') || self::_endsWith($event->filename, '/Master.twig') || self::_endsWith($event->filename, '/Component.twig') || self::_endsWith($event->filename, '/Partial.twig') || self::_endsWith($event->filename, '/Controller.php') || self::_endsWith($event->filename, '/FrontendForm.php') || self::_endsWith($event->filename, '/Form.php') || self::_endsWith($event->filename, '/Component.css') || self::_endsWith($event->filename, '/Component.scss') || self::_endsWith($event->filename, '/Component.printcss')) { if ($event instanceof Event\Create || $event instanceof Event\Delete) { echo "recalculate 'componentFiles' setting because comopnent file got removed/added...\n"; self::_clearComponentSettingsCache($matchingClasses, 'componentFiles'); } } if (self::_endsWith($event->filename, '/Component.php') || self::_endsWith($event->filename, '/FrontendForm.php')) { if ($event instanceof Event\Modify) { self::_clearComponentSettingsCache($matchingClasses); //view cache can depend on settings $s = new Kwf_Model_Select(); $s->whereEquals('component_class', $matchingClasses); self::_deleteViewCache($s); } } else { if (self::_endsWith($event->filename, '/Component.css') || self::_endsWith($event->filename, '/Component.scss') || self::_endsWith($event->filename, '/Component.printcss')) { //MODIFY already handled above (assets) //CREATE/DELETE also handled above } else { if (self::_endsWith($event->filename, '/Master.tpl') || self::_endsWith($event->filename, '/Master.twig')) { if ($event instanceof Event\Modify) { $s = new Kwf_Model_Select(); //all component_classes $s->whereEquals('type', 'master'); self::_deleteViewCache($s); } } else { if (self::_endsWith($event->filename, '/Component.tpl') || self::_endsWith($event->filename, '/Component.twig')) { if ($event instanceof Event\Modify) { $s = new Kwf_Model_Select(); $s->whereEquals('component_class', $matchingClasses); $s->whereEquals('type', 'component'); $s->whereEquals('renderer', 'component'); self::_deleteViewCache($s); } } else { if (self::_endsWith($event->filename, '/Partial.tpl') || self::_endsWith($event->filename, '/Partial.twig')) { if ($event instanceof Event\Modify) { $s = new Kwf_Model_Select(); $s->whereEquals('component_class', $matchingClasses); $s->whereEquals('type', 'partial'); self::_deleteViewCache($s); } } else { if (self::_endsWith($event->filename, '/Mail.html.tpl') || self::_endsWith($event->filename, '/Mail.html.twig')) { if ($event instanceof Event\Modify) { $s = new Kwf_Model_Select(); $s->whereEquals('component_class', $matchingClasses); $s->whereEquals('type', 'component'); $s->whereEquals('renderer', 'mail_html'); self::_deleteViewCache($s); } } else { if (self::_endsWith($event->filename, '/Mail.txt.tpl') || self::_endsWith($event->filename, '/Mail.txt.twig')) { if ($event instanceof Event\Modify) { $s = new Kwf_Model_Select(); $s->whereEquals('component_class', $matchingClasses); $s->whereEquals('type', 'component'); $s->whereEquals('renderer', 'mail_txt'); self::_deleteViewCache($s); } } } } } } } } } echo "finished in " . round((microtime(true) - $eventStart) * 1000, 2) . "ms\n\n"; }