Ejemplo n.º 1
0
 public function testFilterLoad()
 {
     $asset = new StringAsset('.foo{.bar{width:1+1;}}');
     $asset->load();
     $this->filter->filterLoad($asset);
     $this->assertEquals(".foo .bar {\n  width: 2;\n}\n", $asset->getContent(), '->filterLoad() parses the content');
 }
Ejemplo n.º 2
0
    public function testCompile()
    {
        if (!isset($_SERVER['CLOSURE_JAR'])) {
            $this->markTestSkipped('There is no CLOSURE_JAR environment variable.');
        }
        $input = <<<EOF
(function() {
function unused(){}
function foo(bar) {
    var foo = 'foo';
    return foo + bar;
}
alert(foo("bar"));
})();
EOF;
        $expected = <<<EOF
(function(){alert("foobar")})();

EOF;
        $asset = new StringAsset($input);
        $asset->load();
        $filter = new CompilerJarFilter($_SERVER['CLOSURE_JAR']);
        $filter->filterLoad($asset);
        $filter->filterDump($asset);
        $this->assertEquals($expected, $asset->getContent());
    }
Ejemplo n.º 3
0
    /**
     * @group integration
     */
    public function testFilterDump()
    {
        if (!isset($_SERVER['YUI_COMPRESSOR_JAR'])) {
            $this->markTestSkipped('There is no YUI_COMPRESSOR_JAR environment variable.');
        }
        $source = <<<JAVASCRIPT
(function() {

var asdf = 'asdf';
var qwer = 'qwer';

if (asdf.indexOf(qwer)) {
    alert("That's not possible!");
} else {
    alert("Boom.");
}

})();

JAVASCRIPT;
        $expected = <<<JAVASCRIPT
(function(){var a="asdf";var b="qwer";if(a.indexOf(b)){alert("That's not possible!")}else{alert("Boom.")}})();
JAVASCRIPT;
        $asset = new StringAsset($source);
        $asset->load();
        $filter = new JsCompressorFilter($_SERVER['YUI_COMPRESSOR_JAR']);
        $filter->filterDump($asset);
        $this->assertEquals($expected, $asset->getContent(), '->filterDump()');
    }
Ejemplo n.º 4
0
    public function testRoundTrip()
    {
        $input = <<<EOF
(function() {
function unused(){}
function foo(bar) {
    var foo = 'foo';
    return foo + bar;
}
alert(foo("bar"));
})();
EOF;
        $expected = <<<EOF
(function() {
  alert("foobar")
})();

EOF;
        $asset = new StringAsset($input);
        $asset->load();
        $filter = new CompilerApiFilter();
        $filter->setCompilationLevel(CompilerApiFilter::COMPILE_SIMPLE_OPTIMIZATIONS);
        $filter->setJsExterns('');
        $filter->setExternsUrl('');
        $filter->setExcludeDefaultExterns(true);
        $filter->setFormatting(CompilerApiFilter::FORMAT_PRETTY_PRINT);
        $filter->setUseClosureLibrary(false);
        $filter->setWarningLevel(CompilerApiFilter::LEVEL_VERBOSE);
        $filter->filterLoad($asset);
        $filter->filterDump($asset);
        $this->assertEquals($expected, $asset->getContent());
    }
Ejemplo n.º 5
0
 public function testPreserveCommentsFalse()
 {
     $asset = new StringAsset("/* Line 1 */\n.foo { color: green }");
     $asset->load();
     $this->filter->setPreserveComments(false);
     $this->filter->filterLoad($asset);
     $this->assertNotContains('/* Line 1 */', $asset->getContent(), '->setPreserveComments(false)');
 }
 public function testFilterLoadWithUseNib()
 {
     $asset = new StringAsset("@import 'nib'\nbody\n  whitespace nowrap\n  font 12px Helvetica, Arial, sans-serif\n  color black");
     $asset->load();
     $this->filter->setUseNib(true);
     $this->filter->filterLoad($asset);
     $this->assertEquals("body {\n  white-space: nowrap;\n  font: 12px Helvetica, Arial, sans-serif;\n  color: #000;\n}\n", $asset->getContent(), '->filterLoad() parses the content using the nib extension');
 }
Ejemplo n.º 7
0
 public function testGetContentNullUnlessLoaded()
 {
     // see https://github.com/kriswallsmith/assetic/pull/432
     $asset = new StringAsset("test");
     $this->assertNull($asset->getContent(), '->getContent() returns null unless load() has been called.');
     $asset->load();
     $this->assertEquals("test", $asset->getContent(), '->getContent() returns the content after load()');
 }
Ejemplo n.º 8
0
 public function testAppend()
 {
     $asset = new StringAsset('foobar');
     $asset->load();
     $filter = new SeparatorFilter('+');
     $filter->filterDump($asset);
     $this->assertEquals('foobar+', $asset->getContent());
 }
Ejemplo n.º 9
0
 public function testFilterLoadWithCompression()
 {
     $asset = new StringAsset("body\n  font 12px Helvetica, Arial, sans-serif\n  color black;");
     $asset->load();
     $this->filter->setCompress(true);
     $this->filter->filterLoad($asset);
     $this->assertEquals("body{font:12px Helvetica,Arial,sans-serif;color:#000}\n", $asset->getContent(), '->filterLoad() parses the content and compress it');
 }
 public function testIgnoreNonPuliAssets()
 {
     $asset = new StringAsset('content');
     $asset->load();
     $this->filter->filterLoad($asset);
     $this->filter->filterDump($asset);
     // no error
 }
Ejemplo n.º 11
0
 public function testNoHeader()
 {
     $asset = new StringAsset('square = (x) -> x * x');
     $asset->load();
     $this->filter->setNoHeader(true);
     $this->filter->filterLoad($asset);
     $this->assertNotRegExp('/^\\/\\/ Generated by CoffeeScript/i', $asset->getContent());
 }
Ejemplo n.º 12
0
 public function testPresets()
 {
     $asset = new StringAsset('.foo { color: @bar }');
     $asset->load();
     $this->filter->setPresets(array('bar' => 'green'));
     $this->filter->filterLoad($asset);
     $this->assertEquals(".foo { color:green; }\n", $asset->getContent(), '->setPresets() to pass variables into lessphp filter');
 }
Ejemplo n.º 13
0
 public function testEmptyUrl()
 {
     $asset = new StringAsset('body { background: url(); }', array(), 'http://www.example.com', 'css/main.css');
     $asset->setTargetPath('css/packed/main.css');
     $asset->load();
     $filter = new CssRewriteFilter();
     $filter->filterDump($asset);
     // no error is thrown
 }
Ejemplo n.º 14
0
 public function testUriRewriteWithSymlinks()
 {
     $filter = new UriRewriteFilter('path/to/public', array('//assets' => strtr('path/to/outside/public/assets', '/', DIRECTORY_SEPARATOR)));
     $input = "body { background-image: url('../foo/bar.png'); }";
     $asset = new StringAsset($input, array(), 'path/to/outside/public/assets/baz', 'qux.css');
     $asset->load();
     $filter->filterDump($asset);
     $this->assertEquals("body { background-image: url('/assets/foo/bar.png'); }", $asset->getContent());
 }
 public function testNoTargetPath()
 {
     $content = 'body{url(foo.gif)}';
     $asset = new StringAsset($content);
     $asset->load();
     $filter = new CssRewriteFilter();
     $filter->filterDump($asset);
     $this->assertEquals($content, $asset->getContent(), '->filterDump() urls are not changed without urls');
 }
Ejemplo n.º 16
0
 public function testFilterLoadBared()
 {
     $this->filter = new CoffeephpFilter(array('bare' => false));
     $asset = new StringAsset($this->stringAsset);
     $this->filter->options['bare'] = true;
     $asset->load();
     $this->filter->filterLoad($asset);
     $this->assertEquals($this->compiledStringAsset, $asset->getContent(), '->filterLoad() sets an include path based on source url');
 }
 /**
  * @dataProvider provideUrls
  */
 public function testUrls($before, $after)
 {
     $asset = new StringAsset($before, array(), null, '.');
     $asset->setTargetPath('.');
     $asset->load();
     $filter = new CachebusterFilter('v=bar');
     $filter->filterDump($asset);
     $this->assertEquals($after, $asset->getContent());
 }
Ejemplo n.º 18
0
 public function testSetImportPath()
 {
     $filter = $this->getFilter();
     $filter->addImportPath(__DIR__ . '/fixtures/sass/import_path');
     $asset = new StringAsset("@import 'import';\n#test { color: \$red }");
     $asset->load();
     $filter->filterLoad($asset);
     $this->assertEquals("#test {\n  color: red; }\n", $asset->getContent(), 'Import paths are correctly used');
 }
Ejemplo n.º 19
0
 public function testFilterLoad()
 {
     $prolog = "/** @jsx React.DOM */\n";
     $expected = $prolog . 'React.renderComponent(React.createElement(HelloMessage, {name: "John"}), mountNode);';
     $asset = new StringAsset($prolog . 'React.renderComponent(<HelloMessage name="John" />, mountNode);');
     $asset->load();
     $this->filter->filterLoad($asset);
     $this->assertEquals($expected, $this->clean($asset->getContent()));
 }
Ejemplo n.º 20
0
 public function testExternalSource()
 {
     $asset = new StringAsset('body { background: url(../images/bg.gif); }', array(), 'http://www.example.com', 'css/main.css');
     $asset->setTargetPath('css/packed/main.css');
     $asset->load();
     $filter = new CssRewriteFilter();
     $filter->filterDump($asset);
     $this->assertContains('http://www.example.com/css/../images/bg.gif', $asset->getContent(), '->filterDump() rewrites references in external stylesheets');
 }
 /**
  * @dataProvider provideMultipleUrls
  */
 public function testMultipleUrls($version, $format, $expectedFormat, $inputUrl1, $expectedUrl1, $inputUrl2, $expectedUrl2)
 {
     $asset = new StringAsset(sprintf($expectedFormat, $inputUrl1, $inputUrl2));
     $asset->load();
     $filter = new CssCacheBustingFilter();
     $filter->setVersion($version);
     $filter->setFormat($format);
     $filter->filterDump($asset);
     $this->assertEquals(sprintf($expectedFormat, $expectedUrl1, $expectedUrl2), $asset->getContent());
 }
 public function testFilterDump()
 {
     $expected = 'body{baz:foo;foo:new;too:me}div.other,div.test{border:1px solid black}';
     $inputCss = 'body { foo:bar; too: me;} body { baz:foo; } body { foo: new }
     div.test { border: 1px solid black; }
     div.other { border: 1px solid black} ';
     $asset = new StringAsset($inputCss);
     $asset->ensureFilter($this->filter);
     $result = $asset->dump();
     $this->assertEquals($expected, $result);
 }
 public function testFilter()
 {
     // Create twig env
     $twig = new \Twig_Environment($this->getLoader());
     // Create twig filter
     $filter = new TwigFilter($twig);
     // Create sample asset
     $asset = new StringAsset("{{ '<' | e('html') }}", array($filter));
     // Test asset content
     $this->assertEquals('&lt;', $asset->dump());
 }
    public function testFilterLoad()
    {
        $expected = <<<EOF
.foo .bar {
  width: 2; }

EOF;
        $asset = new StringAsset('.foo{.bar{width:1+ 1;}}');
        $asset->load();
        $this->filter->filterLoad($asset);
        $this->assertEquals($expected, $asset->getContent(), '->filterLoad() parses the content');
    }
Ejemplo n.º 25
0
 public function testCsso()
 {
     $input = '.test { height: 10px; height: 20px; }';
     $asset = new StringAsset($input);
     $asset->load();
     try {
         $this->filter->filterLoad($asset);
     } catch (FilterException $e) {
         $this->markTestIncomplete('Could not properly test CSSO filter. Make sure Node and CSSO are in your PATH.');
     }
     $this->assertEquals('.test{height:20px}', $asset->getContent());
 }
Ejemplo n.º 26
0
 public function testMixedIteration()
 {
     $asset = new StringAsset('asset');
     $nestedAsset = new StringAsset('nested');
     $innerColl = new AssetCollection(array($nestedAsset));
     $contents = array();
     $filter = new CallablesFilter(function ($asset) use(&$contents) {
         $contents[] = $asset->getContent();
     });
     $coll = new AssetCollection(array($asset, $innerColl), array($filter));
     $coll->load();
     $this->assertEquals(array('asset', 'nested'), $contents, '->load() iterates over multiple levels');
 }
Ejemplo n.º 27
0
 public function testUriRewriteWithSymlinksAndSubDir()
 {
     $request = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $request->shouldReceive('getScriptName')->twice()->andReturn('/index.php');
     $request->shouldReceive('getHost')->once();
     $filter = new UriRewriteFilter('path/to/public', array('//assets' => strtr('path/to/outside/public/assets', '/', DIRECTORY_SEPARATOR)));
     $filter->setRequest($request);
     $input = "body { background-image: url('../foo/bar.png'); }";
     $asset = new StringAsset($input, array(), 'path/to/outside/public/assets/baz', 'qux.css');
     $asset->load();
     $filter->filterDump($asset);
     $this->assertEquals("body { background-image: url('http://example.com/assets/foo/bar.png'); }", $asset->getContent());
 }
 public function testSimple()
 {
     $directory = $this->getMockBuilder('Alex\\AsseticExtraBundle\\Assetic\\Util\\AssetDirectory')->disableOriginalConstructor()->getMock();
     $directory->expects($this->any())->method('getTarget')->will($this->returnValue('assets'));
     $directory->expects($this->once())->method('add')->with('images/foo.png')->will($this->returnValue('assets/foo.png'));
     $filter = new AssetDirectoryFilter($directory);
     $asset = new StringAsset('body { background: url("../images/foo.png"); }', array($filter), null, 'css/main.css');
     $asset->setTargetPath('css/main.css');
     $asset->load();
     $filter->filterLoad($asset);
     $filter->filterDump($asset);
     $this->assertEquals('body { background: url("../assets/foo.png"); }', $asset->getContent(), 'AssetDirectoryFilter filters URL');
 }
Ejemplo n.º 29
0
    public function testCompile()
    {
        $input = <<<EOF
@def BG_COLOR rgb(235, 239, 249);
body {background-color: BG_COLOR;}
EOF;
        $expected = <<<EOF
body{background-color:#ebeff9}
EOF;
        $asset = new StringAsset($input);
        $asset->load();
        $this->filter->filterLoad($asset);
        $this->assertEquals($expected, $asset->getContent());
    }
 /**
  * {@inheritDoc}
  *
  * @return AssetInterface|ImageInterface
  */
 public function apply(ImageInterface $image)
 {
     $asset = new StringAsset($image->get('png'));
     $asset->load();
     try {
         $this->filter->filterDump($asset);
     } catch (FilterException $e) {
         // FilterException is thrown when "optipng" utility was not found.
         // This should never happen on production environment; maybe we should enforce it?
     }
     // TODO: workaround hackish way of applying optipng and other compression filters.
     // Without that we're loosing some optimizations by running content through image library functions!
     return new ImageAssetWrapper($asset);
     //        return $this->imagine->load($asset->getContent());
 }