Example #1
0
 public function testWriteAssetIfNotUpdated()
 {
     $this->configuration->setBuildOnRequest(true);
     $this->configuration->setWriteIfChanged(true);
     $this->object->build();
     $manager = $this->object->getAssetManager();
     $assets = $manager->get('base_css')->all();
     /** @var \Assetic\Asset\AssetInterface $asset */
     $asset = $assets[0];
     $asset->setTargetPath($manager->get('base_css')->getTargetPath());
     $targetFile = $this->configuration->getWebPath($asset->getTargetPath());
     if (is_file($targetFile)) {
         unlink($targetFile);
     }
     $this->assertFileNotExists($targetFile);
     $this->object->writeAsset($asset);
     $this->assertFileExists($targetFile);
     $sourceFile = $asset->getSourceRoot() . '/' . $asset->getSourcePath();
     $targetMTime = filemtime($targetFile);
     sleep(2);
     $modifiedAsset = new FileAsset($sourceFile);
     $modifiedAsset->setTargetPath($targetFile);
     $this->object->writeAsset($modifiedAsset);
     clearstatcache(true, $targetFile);
     $targetMTimeNotModified = filemtime($targetFile);
     $this->assertLessThanOrEqual($targetMTime, $targetMTimeNotModified);
 }
Example #2
0
 public function testCacheBusterStrategyWorker()
 {
     $factory = $this->object->createAssetFactory($this->configuration->getModule('test_application'));
     // no workers by default:
     $this->assertAttributeEquals(array(), 'workers', $factory);
     $cacheBusterStrategy = $this->getMock('AsseticBundle\\CacheBuster\\LastModifiedStrategy');
     $this->object->setCacheBusterStrategy($cacheBusterStrategy);
     $factory = $this->object->createAssetFactory($this->configuration->getModule('test_application'));
     // cache buster strategy is added to workers list:
     $this->assertAttributeEquals(array($cacheBusterStrategy), 'workers', $factory);
 }
Example #3
0
 /**
  * @param AssetInterface $asset
  */
 protected function write(AssetInterface $asset)
 {
     $umask = $this->configuration->getUmask();
     if (null !== $umask) {
         $umask = umask($umask);
     }
     if ($this->configuration->isDebug() && !$this->configuration->isCombine() && $asset instanceof AssetCollection) {
         foreach ($asset as $item) {
             $this->writeAsset($item);
         }
     } else {
         $this->getAssetWriter()->writeAsset($asset);
     }
     if (null !== $umask) {
         umask($umask);
     }
 }
Example #4
0
 /**
  * @param \Zend\View\Renderer\RendererInterface $renderer
  * @return \AsseticBundle\View\StrategyInterface|null
  */
 public function getStrategyForRenderer(Renderer $renderer)
 {
     if (!$this->hasStrategyForRenderer($renderer)) {
         return null;
     }
     $rendererName = $this->getRendererName($renderer);
     if (!isset($this->strategy[$rendererName])) {
         $strategyClass = $this->configuration->getStrategyNameForRenderer($rendererName);
         if (!class_exists($strategyClass, true)) {
             throw new \AsseticBundle\Exception\InvalidArgumentException(sprintf('strategy class "%s" dosen\'t exists', $strategyClass));
         }
         $instance = new $strategyClass();
         if (!$instance instanceof StrategyInterface) {
             throw new \AsseticBundle\Exception\DomainException(sprintf('strategy class "%s" is not instanceof "AsseticBundle\\View\\StrategyInterface"', $strategyClass));
         }
         $this->strategy[$rendererName] = $instance;
     }
     /** @var $strategy \AsseticBundle\View\StrategyInterface */
     $strategy = $this->strategy[$rendererName];
     $strategy->setBaseUrl($this->configuration->getBaseUrl());
     $strategy->setRenderer($renderer);
     return $strategy;
 }
 public function testAddRendererToStrategy()
 {
     $value = $this->object->addRendererToStrategy('a', 'b');
     $this->assertNull($value);
 }