示例#1
0
 public function testLazyLoading()
 {
     $asset = new FileAsset(__FILE__);
     $this->assertEmpty($asset->getContent(), 'The asset content is empty before load');
     $asset->load();
     $this->assertNotEmpty($asset->getContent(), 'The asset content is not empty after load');
 }
 public function testBeautify()
 {
     $this->filter->setBeautify(true);
     $this->filter->filterDump($this->asset);
     $this->assertContains('    foo', $this->asset->getContent());
     $this->assertNotContains('/**', $this->asset->getContent());
 }
示例#3
0
 /**
  * @dataProvider getImages
  */
 public function testFilter($image)
 {
     $asset = new FileAsset($image);
     $asset->load();
     $before = $asset->getContent();
     $this->filter->filterDump($asset);
     $this->assertNotEmpty($asset->getContent(), '->filterLoad() sets content');
     $this->assertNotEquals($before, $asset->getContent(), '->filterLoad() changes the content');
     $this->assertMimeType('image/png', $asset->getContent(), '->filterLoad() creates PNG data');
 }
 public function testFilter()
 {
     $asset = new FileAsset(__DIR__ . '/fixtures/home.jpg');
     $asset->load();
     $before = $asset->getContent();
     $this->filter->filterDump($asset);
     $this->assertNotEmpty($asset->getContent(), '->filterLoad() sets content');
     $this->assertNotEquals($before, $asset->getContent(), '->filterDump() changes the content');
     $this->assertMimeType('image/jpeg', $asset->getContent(), '->filterDump() creates JPEG data');
 }
示例#5
0
文件: File.php 项目: lalop/aphet
 /**
  * @param $path String target path
  * @return \Assetic\Filter\FileAsset
  */
 public function asset($opts = array())
 {
     $asset = new FileAsset($this->real_path);
     $ext = strtolower(substr($this->real_path, strrpos($this->real_path, '.')));
     if (in_array($ext, array('.css', '.scss'))) {
         //il faut rajouter la méthode asset-url
         $scss = new ScssphpFilter();
         if (isset($opts['compass']) && $opts['compass']) {
             $scss->enableCompass(true);
         }
         $scss->registerFunction('aphet_url', function ($args, $scss) {
             if ($args[0][0] === 'string') {
                 $url = is_array($args[0][2][0]) ? $args[0][2][0][2][0] : $args[0][2][0];
             } else {
                 throw new \Exception('je ne sais pas quoi faire là');
             }
             if (strpos($url, '?') !== false) {
                 list($url, $query) = explode('?', $url);
             } else {
                 $query = null;
             }
             if (strpos($url, '#') !== false) {
                 list($url, $hash) = explode('#', $url);
             } else {
                 $hash = null;
             }
             return 'url(' . aphet_url($url) . ($query ? "?{$query}" : '') . ($hash ? "?{$hash}" : '') . ')';
         });
         $asset->ensureFilter($scss);
     } elseif ($ext === '.js') {
         $filter = new \Assetic\Filter\CallablesFilter(function ($asset) {
             $asset->setContent(preg_replace_callback('/aphet_url\\((.*)\\)/', function ($match) {
                 return '\'' . aphet_url(json_decode($match[1])) . '\'';
             }, $asset->getContent()));
         });
         $asset->ensureFilter($filter);
     }
     return $asset;
 }