/** * Config setter, used for testing the controller. */ protected function _getConfig() { if (empty($this->_Config)) { $this->_Config = AssetConfig::buildFromIniFile(); } return $this->_Config; }
/** * Factory method for AssetFilterCollection * * @param string $ext The extension An array of filters to put in the collection * @return FilterCollection */ protected function _makeFilters($ext, $target) { $config = array('paths' => $this->_Config->paths($ext, $target), 'target' => $target, 'theme' => $this->_Config->theme()); $filters = $this->_Config->filters($ext, $target); $filterSettings = $this->_Config->filterConfig($filters); return new AssetFilterCollection($filters, $config, $filterSettings); }
/** * Constructor - finds and parses the ini file the plugin uses. * * @return void */ public function __construct(View $View, $settings = array()) { if (empty($settings['noconfig'])) { $config = AssetConfig::buildFromIniFile(); $this->config($config); } parent::__construct($View, $settings); }
/** * Constructor - finds and parses the ini file the plugin uses. * * @return void */ public function __construct($options = array()) { if (empty($options['noconfig'])) { $config = AssetConfig::buildFromIniFile(); $this->config($config); } }
public function setUp() { parent::setUp(); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testConfig = $this->_pluginPath . 'Test' . DS . 'test_files' . DS . 'Config' . DS . 'integration.ini'; $map = array( 'TEST_FILES/' => $this->_pluginPath . 'Test' . DS . 'test_files' . DS ); App::build(array( 'Plugin' => array($map['TEST_FILES/'] . 'Plugin' . DS ) )); CakePlugin::load('TestAssetIni'); AssetConfig::clearAllCachedKeys(); $config = AssetConfig::buildFromIniFile($this->testConfig, $map); $config->filters('js', null, array()); $this->Compressor = $this->getMock('AssetCompressor', array('_getConfig')); $this->Compressor->expects($this->atLeastOnce()) ->method('_getConfig') ->will($this->returnValue($config)); $this->request = new CakeRequest(null, false); $this->response = $this->getMock('CakeResponse', array('checkNotModified', 'type', 'send')); Configure::write('debug', 2); }
function setUp() { $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testConfig = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini'; $this->config = AssetConfig::buildFromIniFile($this->testConfig); $this->config->cachePath('js', TMP); $this->cache = new AssetCache($this->config); }
/** * Get the AssetCompress factory based on the config object. * * @return AssetCompress\Factory */ protected function factory() { if (empty($this->factory)) { $this->config->theme($this->theme); $this->factory = new Factory($this->config); } return $this->factory; }
function testBuildFileNameTheme() { $this->config = AssetConfig::buildFromIniFile($this->_themeConfig); $this->config->theme('blue'); $this->config->cachePath('css', TMP); $this->cache = new AssetCache($this->config); $result = $this->cache->buildFileName('themed.css'); $this->assertEqual('blue-themed.css', $result); }
function testExceptionOnBogusFile() { try { $config = AssetConfig::buildFromIniFile('/bogus'); $this->assertFalse(true, 'Exception not thrown.'); } catch (Exception $e) { $this->assertEqual('Configuration file "/bogus" was not found.', $e->getMessage()); } }
function setUp() { $this->_pluginPath = App::pluginPath('AssetCompress'); $testFile = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini'; AssetConfig::clearAllCachedKeys(); $this->config = AssetConfig::buildFromIniFile($testFile); $this->config->paths('js', array($this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'js' . DS, $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'js' . DS . '*')); $this->config->paths('css', array($this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'css' . DS, $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'css' . DS . '*')); $this->Compiler = new AssetCompiler($this->config); }
/** * start a test * * @return void **/ function startTest() { $this->_pluginPath = App::pluginPath('AssetCompress'); $testFile = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini'; AssetConfig::clearAllCachedKeys(); $this->Helper = new AssetCompressHelper(array('noconfig' => true)); $Config = AssetConfig::buildFromIniFile($testFile); $this->Helper->config($Config); $this->Helper->Html = new HtmlHelper(); Router::reload(); Configure::write('debug', 2); }
public function setUp() { parent::setUp(); $out = $this->getMock('ConsoleOutput', array(), array(), '', false); $in = $this->getMock('ConsoleInput', array(), array(), '', false); $this->Task = $this->getMock('AssetBuildTask', array('in', 'err', 'createFile', '_stop', 'clear'), array($out, $out, $in)); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testFilePath = $this->_pluginPath . 'Test/test_files/View/Parse/'; $this->testConfig = $this->_pluginPath . 'Test' . DS . 'test_files' . DS . 'Config' . DS . 'config.ini'; AssetConfig::clearAllCachedKeys(); $this->config = AssetConfig::buildFromIniFile($this->testConfig); $this->Task->setConfig($this->config); }
function setUp() { parent::setUp(); $this->Dispatcher =& new TestAssetBuildTaskMockShellDispatcher(); $this->Task =& new MockAssetBuildTask($this->Dispatcher); $this->Task->Dispatch =& $this->Dispatcher; $this->Task->Dispatch->shellPaths = App::path('shells'); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testFilePath = $this->_pluginPath . 'tests/test_files/views/'; $this->testConfig = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'config.ini'; AssetConfig::clearAllCachedKeys(); $this->config = AssetConfig::buildFromIniFile($this->testConfig); $this->Task->setConfig($this->config); }
function setUp() { parent::setUp(); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testConfig = $this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'config' . DS . 'integration.ini'; $map = array('TEST_FILES/' => $this->_pluginPath . 'tests' . DS . 'test_files' . DS); AssetConfig::clearAllCachedKeys(); $config = AssetConfig::buildFromIniFile($this->testConfig, $map); $config->filters('js', null, array()); $this->Controller = new TestAssetsController(); $this->Controller->constructClasses(); $this->Controller->_Config = $config; $this->_debug = Configure::read('debug'); }
public function setUp() { parent::setUp(); Cache::drop(AssetConfig::CACHE_CONFIG); Cache::config(AssetConfig::CACHE_CONFIG, array('engine' => 'File')); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->_testFiles = App::pluginPath('AssetCompress') . 'Test' . DS . 'test_files' . DS; $this->testConfig = $this->_testFiles . 'Config' . DS . 'config.ini'; $this->_themeConfig = $this->_testFiles . 'Config' . DS . 'themed.ini'; App::build(array('Plugin' => array($this->_testFiles . 'Plugin' . DS))); CakePlugin::load('TestAssetIni'); AssetConfig::clearAllCachedKeys(); $this->config = AssetConfig::buildFromIniFile($this->testConfig); }
function setUp() { parent::setUp(); $this->_pluginPath = App::pluginPath('AssetCompress'); $this->testConfig = $this->_pluginPath . 'Test' . DS . 'test_files' . DS . 'Config' . DS . 'integration.ini'; $map = array('TEST_FILES/' => $this->_pluginPath . 'Test' . DS . 'test_files' . DS); AssetConfig::clearAllCachedKeys(); $config = AssetConfig::buildFromIniFile($this->testConfig, $map); $config->filters('js', null, array()); $this->Controller = $this->getMock('AssetsController', array('render'), array(new CakeRequest(null, false), new CakeResponse())); $this->Controller->constructClasses(); $this->Controller->response = $this->getMock('CakeResponse'); $this->Controller->_Config = $config; $this->_debug = Configure::read('debug'); }
function testCombineThemeFileWithNonTheme() { App::build(array('views' => array($this->_testFiles . 'views' . DS))); $Config = AssetConfig::buildFromIniFile($this->_themeConfig); $Config->paths('css', array($this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'css' . DS . '**')); $Config->theme('red'); $Compiler = new AssetCompiler($Config); $result = $Compiler->generate('combined.css'); $expected = <<<TEXT @import url("reset/reset.css"); #nav { \twidth:100%; }body { \tcolor: red !important; } TEXT; $this->assertEqual($result, $expected); }
/** * start a test * * @return void **/ function setUp() { parent::setUp(); $this->_pluginPath = App::pluginPath('AssetCompress'); $testFile = $this->_pluginPath . 'Test' . DS . 'test_files' . DS . 'Config' . DS . 'config.ini'; AssetConfig::clearAllCachedKeys(); Cache::drop(AssetConfig::CACHE_CONFIG); Cache::config(AssetConfig::CACHE_CONFIG, array('path' => TMP, 'prefix' => 'asset_compress_test_', 'engine' => 'File')); $controller = null; $request = new CakeRequest(null, false); $request->webroot = ''; $view = new View($controller); $view->request = $request; $this->Helper = new AssetCompressHelper($view, array('noconfig' => true)); $Config = AssetConfig::buildFromIniFile($testFile); $this->Helper->config($Config); $this->Helper->Html = new HtmlHelper($view); Router::reload(); Configure::write('debug', 2); }
public function testRawAssetsPlugin() { App::build(array( 'Plugin' => array($this->_testFiles . 'Plugin' . DS) )); CakePlugin::load('TestAsset'); $config = AssetConfig::buildFromIniFile($this->_testFiles . 'Config/plugins.ini'); $this->Helper->config($config); $result = $this->Helper->css('plugins.css', array('raw' => true)); $expected = array( array( 'link' => array( 'type' => 'text/css', 'rel' => 'stylesheet', 'href' => 'css/nav.css' ) ), array( 'link' => array( 'type' => 'text/css', 'rel' => 'stylesheet', 'href' => '/test_asset/plugin.css' ) ), ); $this->assertTags($result, $expected); }
/** * Transforms the config data into a more structured form * * @param array $contents Contents to build a config object from. * @return AssetConfig */ protected static function _parseConfig($config, $constants) { $AssetConfig = new AssetConfig(array(), $constants); foreach ($config as $section => $values) { if (strpos($section, '_') === false) { // extension section $AssetConfig->addExtension($section, $values); } elseif (strpos($section, self::FILTER_PREFIX) === 0) { // filter section. $name = str_replace(self::FILTER_PREFIX, '', $section); $AssetConfig->filterConfig($name, $values); } else { list($extension, $key) = explode('_', $section, 2); // must be a build target. $files = isset($values['files']) ? $values['files'] : array(); $filters = isset($values['filters']) ? $values['filters'] : array(); $AssetConfig->addTarget($key, $files, $filters); } } if (!empty($config['General']['cacheConfig'])) { Cache::write(self::CACHE_ASSET_CONFIG_KEY, $AssetConfig, self::CACHE_CONFIG); } return $AssetConfig; }
function testCompilePluginFiles() { App::build(array('Plugin' => array($this->_testFiles . 'Plugin' . DS))); CakePlugin::load('TestAsset'); $Config = AssetConfig::buildFromIniFile($this->_pluginConfig); $Config->paths('css', array($this->_pluginPath . 'Test' . DS . 'test_files' . DS . 'css' . DS . '**')); $Compiler = new AssetCompiler($Config); $result = $Compiler->generate('plugins.css'); $expected = <<<TEXT @import url("reset/reset.css"); #nav { \twidth:100%; }.plugin-box { \tcolor: orange; } TEXT; $this->assertEqual($result, $expected); }
/** * Clears the build timestamp. Try to clear it out even if they do not have ts file enabled in * the INI. * * build timestamp file is only created when build() is run from this shell */ public function clear_build_ts() { $this->out('Clearing build timestamp.'); $this->out(); AssetConfig::clearBuildTimeStamp(); }
/** * Transforms the config data into a more structured form * * @param array $contents Contents to build a config object from. * @return AssetConfig */ protected static function _parseConfig($config, $constants) { $AssetConfig = new AssetConfig(self::$_defaults, $constants); foreach ($config as $section => $values) { if (in_array($section, self::$_extensionTypes)) { // extension section, merge in the defaults. $defaults = $AssetConfig->get($section); if ($defaults) { $values = array_merge($defaults, $values); } $AssetConfig->addExtension($section, $values); } elseif (strtolower($section) === self::GENERAL) { $AssetConfig->set(self::GENERAL, $values); } elseif (strpos($section, self::FILTER_PREFIX) === 0) { // filter section. $name = str_replace(self::FILTER_PREFIX, '', $section); $AssetConfig->filterConfig($name, $values); } else { $lastDot = strrpos($section, '.') + 1; $extension = substr($section, $lastDot); $key = $section; // Is there a prefix? Chop it off. if (strpos($section, $extension . '_') !== false) { $key = substr($key, strlen($extension) + 1); } // must be a build target. $AssetConfig->addTarget($key, $values); } } if ($AssetConfig->general('cacheConfig')) { Cache::write(self::CACHE_ASSET_CONFIG_KEY, $AssetConfig, self::CACHE_CONFIG); } return $AssetConfig; }
public function testCompileRemoteFiles() { $Config = AssetConfig::buildFromIniFile($this->_testFiles . 'Config' . DS . 'remote_file.ini'); $Compiler = new AssetCompiler($Config); $result = $Compiler->generate('remote_file.js'); $this->assertContains('jQuery', $result); }
public function testIsThemed() { $this->assertFalse($this->config->isThemed('libs.js')); $config = AssetConfig::buildFromIniFile($this->_themeConfig); $this->assertTrue($config->isThemed('themed.css')); }
/** * Reads a config file and applies it to the given config instance * * @param string $iniFile Contents to apply to the config instance. * @param AssetConfig $AssetConfig The config instance instance we're applying this config file to. * @param string $prefix Prefix for the target key */ protected static function _parseConfigFile($iniFile, $AssetConfig, $prefix = '') { $config = self::_readConfig($iniFile); foreach ($config as $section => $values) { if (in_array($section, self::$_extensionTypes)) { // extension section, merge in the defaults. $defaults = $AssetConfig->get($section); if ($defaults) { $values = array_merge($defaults, $values); } $AssetConfig->addExtension($section, $values); } elseif (strtolower($section) === self::GENERAL) { $AssetConfig->set(self::GENERAL, $values); } elseif (strpos($section, self::FILTER_PREFIX) === 0) { // filter section. $name = str_replace(self::FILTER_PREFIX, '', $section); $AssetConfig->filterConfig($name, $values); } else { $lastDot = strrpos($section, '.') + 1; $extension = substr($section, $lastDot); $key = $section; // Is there a prefix? Chop it off. if (strpos($section, $extension . '_') !== false) { $key = substr($key, strlen($extension) + 1); } // must be a build target. $AssetConfig->addTarget($prefix . $key, $values); } } }