예제 #1
0
 function testFindOtherExtension()
 {
     $paths = array($this->_testFiles . 'css' . DS);
     $scanner = new AssetScanner($paths);
     $result = $scanner->find('other.less');
     $expected = $this->_testFiles . 'css' . DS . 'other.less';
 }
예제 #2
0
 /**
  * Check to see if a cached build file is 'fresh'.
  * Fresh cached files have timestamps newer than all of the component
  * files.
  *
  * @param string $target The target file being built.
  * @return boolean
  */
 public function isFresh($target)
 {
     $ext = $this->_Config->getExt($target);
     $files = $this->_Config->files($target);
     $theme = $this->_Config->theme();
     $target = $this->buildFileName($target);
     $buildFile = $this->_Config->cachePath($ext) . $target;
     if (!file_exists($buildFile)) {
         return false;
     }
     $buildTime = filemtime($buildFile);
     $Scanner = new AssetScanner($this->_Config->paths($ext), $theme);
     foreach ($files as $file) {
         $path = $Scanner->find($file);
         if ($Scanner->isRemote($path)) {
             $time = $this->getRemoteFileLastModified($path);
         } else {
             $time = filemtime($path);
         }
         if ($time === false || $time >= $buildTime) {
             return false;
         }
     }
     return true;
 }
예제 #3
0
 function testResolveThemePaths()
 {
     App::build(array('views' => array($this->_testFiles . 'views' . DS)));
     $paths = array($this->_testFiles . 'css' . DS);
     $scanner = new AssetScanner($paths, 'blue');
     $result = $scanner->find('t:theme.css');
     $expected = $this->_testFiles . 'views' . DS . 'themed' . DS . 'blue' . DS . 'webroot' . DS . 'theme.css';
     $this->assertEqual($expected, $result);
     $result = $scanner->find('theme:theme.css');
     $this->assertEqual($expected, $result);
 }
예제 #4
0
 function testResolvePluginPaths()
 {
     App::build(array('Plugin' => array($this->_testFiles . 'Plugin' . DS)));
     CakePlugin::load('TestAsset');
     $paths = array($this->_testFiles . 'css' . DS);
     $scanner = new AssetScanner($paths);
     $result = $scanner->find('p:TestAsset:plugin.css');
     $expected = $this->_testFiles . 'Plugin' . DS . 'TestAsset' . DS . 'webroot' . DS . 'plugin.css';
     $this->assertEqual($expected, $result);
     $result = $scanner->find('plugin:TestAsset:plugin.css');
     $this->assertEqual($expected, $result);
 }
 /**
  * Create a script tag for a script asset. Will generate script tags
  * for either the dynamic build controller, or the generated file if it exists.
  *
  * To create build files without configuration use addScript()
  *
  * Options:
  *
  * - All options supported by HtmlHelper::css() are supported.
  * - `raw` - Set to true to get one script element for each file in the build.
  *
  * @param string $file A build target to include.
  * @param array $options An array of options for the script tag.
  * @throws RuntimeException
  * @return A script tag
  */
 public function script($file, $options = array())
 {
     $file = $this->_addExt($file, '.js');
     $config = $this->config();
     $buildFiles = $config->files($file);
     if (!$buildFiles) {
         throw new RuntimeException('Cannot create a script tag for a build that does not exist.');
     }
     if (!empty($options['raw'])) {
         $output = '';
         unset($options['raw']);
         $scanner = new AssetScanner($config->paths('js', $file), $this->theme);
         foreach ($buildFiles as $part) {
             $part = $scanner->find($part, false);
             $part = str_replace(DS, '/', $part);
             $output .= $this->Html->script($part, $options);
         }
         return $output;
     }
     $url = $this->url($file, $options);
     unset($options['full']);
     return $this->Html->script($url, $options);
 }
예제 #6
0
 public function testIsRemote()
 {
     $paths = array($this->_testFiles . 'css' . DS);
     $scanner = new AssetScanner($paths);
     $this->assertFalse($scanner->isRemote('/Users/markstory/cakephp'));
     $this->assertFalse($scanner->isRemote('C:\\Project\\cakephp'));
     $this->assertTrue($scanner->isRemote('http://example.com'));
 }