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()); }
/** * @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()'); }
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()); }
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'); }
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'); }
public function testIgnoreNonPuliAssets() { $asset = new StringAsset('content'); $asset->load(); $this->filter->filterLoad($asset); $this->filter->filterDump($asset); // no error }
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 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'); }
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()'); }
public function testLoadAppliesAdditionalFilter() { $asset = new StringAsset(''); $asset->load(); $filter = $this->getMock('Assetic\\Filter\\FilterInterface'); $filter->expects($this->once())->method('filterLoad')->with($asset); $asset->load($filter); }
public function testAppend() { $asset = new StringAsset('foobar'); $asset->load(); $filter = new SeparatorFilter('+'); $filter->filterDump($asset); $this->assertEquals('foobar+', $asset->getContent()); }
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()); }
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'); }
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 }
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'); }
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 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()); }
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())); }
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 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 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'); }
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()); }
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'); }
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()); }
/** * @group integration */ public function testFilterLoadWithCompression() { if (!isset($_SERVER['NODE_BIN']) || !isset($_SERVER['NODE_PATH'])) { $this->markTestSkipped('No node.js configuration.'); } $asset = new StringAsset("body\n font 12px Helvetica, Arial, sans-serif\n color black;"); $asset->load(); $filter = new StylusFilter(__DIR__, $_SERVER['NODE_BIN'], array($_SERVER['NODE_PATH'])); $filter->setCompress(true); $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 testBare() { $expected = <<<JAVASCRIPT var square; square = function(x) { return x * x; }; JAVASCRIPT; $asset = new StringAsset('square = (x) -> x * x'); $asset->load(); $this->filter->setBare(true); $this->filter->filterLoad($asset); $this->assertEquals($expected, $asset->getContent()); }