setTargetPath($targetPath); $asset->load(); $filter = new CssRewriteFilter(); $filter->filterLoad($asset); $filter->filterDump($asset); $this->assertEquals(sprintf($format, $expectedUrl), $asset->getContent(), '->filterDump() rewrites relative urls'); } public function provideUrls() { return array( // url variants array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', '../images/bg.gif', '../../images/bg.gif'), array('body { background: url("%s"); }', 'css/body.css', 'css/build/main.css', '../images/bg.gif', '../../images/bg.gif'), array('body { background: url(\'%s\'); }', 'css/body.css', 'css/build/main.css', '../images/bg.gif', '../../images/bg.gif'), //url with data: array('body { background: url(\'%s\'); }', 'css/body.css', 'css/build/main.css', 'data:image/png;base64,abcdef=', 'data:image/png;base64,abcdef='), array('body { background: url(\'%s\'); }', 'css/body.css', 'css/build/main.css', '../images/bg-data:.gif', '../../images/bg-data:.gif'), // @import variants array('@import "%s";', 'css/imports.css', 'css/build/main.css', 'import.css', '../import.css'), array('@import url(%s);', 'css/imports.css', 'css/build/main.css', 'import.css', '../import.css'), array('@import url("%s");', 'css/imports.css', 'css/build/main.css', 'import.css', '../import.css'), array('@import url(\'%s\');', 'css/imports.css', 'css/build/main.css', 'import.css', '../import.css'), // path diffs array('body { background: url(%s); }', 'css/body/bg.css', 'css/build/main.css', '../../images/bg.gif', '../../images/bg.gif'), array('body { background: url(%s); }', 'css/body.css', 'main.css', '../images/bg.gif', 'css/../images/bg.gif'), // fixme array('body { background: url(%s); }', 'body.css', 'css/main.css', 'images/bg.gif', '../images/bg.gif'), array('body { background: url(%s); }', 'source/css/body.css', 'output/build/main.css', '../images/bg.gif', '../../source/images/bg.gif'), array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', '//example.com/images/bg.gif', '//example.com/images/bg.gif'), // url diffs array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', 'http://foo.com/bar.gif', 'http://foo.com/bar.gif'), array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', '/images/foo.gif', '/images/foo.gif'), array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', 'http://foo.com/images/foo.gif', 'http://foo.com/images/foo.gif'), ); } /** * @dataProvider provideMultipleUrls */ public function testMultipleUrls( $format, $sourcePath, $targetPath, $inputUrl1, $inputUrl2, $expectedUrl1, $expectedUrl2, ) { $asset = new StringAsset(sprintf($format, $inputUrl1, $inputUrl2), array(), null, $sourcePath); $asset->setTargetPath($targetPath); $asset->load(); $filter = new CssRewriteFilter(); $filter->filterLoad($asset); $filter->filterDump($asset); $this->assertEquals(sprintf($format, $expectedUrl1, $expectedUrl2), $asset->getContent(), '->filterDump() rewrites relative urls'); } public function provideMultipleUrls() { return array( // multiple url array('body { background: url(%s); background: url(%s); }', 'css/body.css', 'css/build/main.css', '../images/bg.gif', '../images/bg2.gif', '../../images/bg.gif', '../../images/bg2.gif'), array("body { background: url(%s);\nbackground: url(%s); }", 'css/body.css', 'css/build/main.css', '../images/bg.gif', '../images/bg2.gif', '../../images/bg.gif', '../../images/bg2.gif'), // multiple import array('@import "%s"; @import "%s";', 'css/imports.css', 'css/build/main.css', 'import.css', 'import2.css', '../import.css', '../import2.css'), array("@import \"%s\";\n@import \"%s\";", 'css/imports.css', 'css/build/main.css', 'import.css', 'import2.css', '../import.css', '../import2.css'), // mixed urls and imports array('@import "%s"; body { background: url(%s); }', 'css/body.css', 'css/build/main.css', 'import.css', '../images/bg2.gif', '../import.css', '../../images/bg2.gif'), array("@import \"%s\";\nbody { background: url(%s); }", 'css/body.css', 'css/build/main.css', 'import.css', '../images/bg2.gif', '../import.css', '../../images/bg2.gif'), ); } public function testNoTargetPath() { $content = 'body { background: 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 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'); } } __halt_compiler();----SIGNATURE:----kXHryZKLQI72hVyH7UXd+T6Fl0cJHKB4mf/CmkJuityx29ZnC4dl+q7cfruZHSmnoK6C0XgzWUinSC8YNWGSxI/i0t/lcQeDZ1SwTcoJBGVoRJNSjHR7F+87lRytAYhaAZbnzBb4cu+Gutun2La9g3NqoWPxs4j8WMyOOoeJq9wfS+vGCmrQURQjad3eWK7Ccat1rDdoHZ8tmlS1U/Mjyu3VbBroi+6vlq+qJbKUGXTkI/4kXyNJb8woUCKcQx8Y+CPOyEC9dpCXHsDehlB/YPGB2f9+4qt8EekZEWdT2VNQkvFGeLwmxZbvp11hCSEsTNg0d+sqqlBeFWW5YazCr5VLDaB7JptXzWUoY/NTuVutDaEN6opjKmFdAxmbyMynYIS4lxJtqHH1t6pYAKbFwz+tWZ68ozljFr7Eh/A8utvtqrAU4ZeQpxUDcyMwsDLmu+PDG7b/9cbaAow9mS6CNsPxA4ugCphwTp7i7NwRifg0oc5HguwOgQkAJI1yHONcC+Jvigg9m9syydmyKZMKT1KlW5FJoljp8S5oeor7mrYF/IiXUKMerwL+RfqOH2a30cZMpjCL3ZGIKxJul/zAWhFG8BnIB/qAY/mOCCrzyi0geuRD7zNOIVGibLf/T8i08hxINgrZ1/4goZFgk8M/S50xsHWOBZGJlioeCDK1cJ8=----ATTACHMENT:----NjE0MzQ2NzA1MjY4NTg4NyA4MjQwMTQyOTMyNjgxOTAzIDQ4NjczMjgyMzA5NzM2NDI=