2013-04-14 23:38:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MatthiasMullie\Minify;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CSS minifier test case.
|
|
|
|
*/
|
|
|
|
class CSSTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private $minifier;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the environment before running a test.
|
|
|
|
*/
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->minifier = new Minify\CSS();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up the environment after running a test.
|
|
|
|
*/
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
$this->minifier = null;
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test CSS minifier rules, provided by dataProvider
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
* @dataProvider dataProvider
|
|
|
|
*/
|
2014-10-07 18:21:22 +02:00
|
|
|
public function minify($input, $expected, $debug = false)
|
2013-04-14 23:38:24 +02:00
|
|
|
{
|
2014-10-07 18:21:22 +02:00
|
|
|
$this->minifier->debug((bool) $debug);
|
|
|
|
|
2013-04-14 23:38:24 +02:00
|
|
|
$this->minifier->add($input);
|
2014-10-07 18:21:22 +02:00
|
|
|
$result = $this->minifier->minify();
|
2013-04-14 23:38:24 +02:00
|
|
|
|
2013-12-26 20:39:10 +01:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-04-14 23:38:24 +02:00
|
|
|
}
|
|
|
|
|
2013-12-01 23:47:40 +01:00
|
|
|
/**
|
|
|
|
* Test conversion of relative paths, provided by dataProviderPaths
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
* @dataProvider dataProviderPaths
|
|
|
|
*/
|
2014-10-09 08:56:14 +02:00
|
|
|
public function convertRelativePath($source, $target, $expected, $options)
|
|
|
|
{
|
2013-12-01 23:47:40 +01:00
|
|
|
$this->minifier->add($source);
|
|
|
|
$result = $this->minifier->minify($target, $options);
|
|
|
|
|
2013-12-26 20:39:10 +01:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-12-01 23:47:40 +01:00
|
|
|
}
|
|
|
|
|
2013-04-14 23:38:24 +02:00
|
|
|
/**
|
|
|
|
* Test cases [input, expected result, options]
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function dataProvider()
|
|
|
|
{
|
|
|
|
$tests = array();
|
|
|
|
|
|
|
|
$tests[] = array(
|
2014-10-08 16:34:49 +02:00
|
|
|
__DIR__ . '/sample/combine_imports/index.css',
|
2013-12-26 23:59:56 +01:00
|
|
|
'body{color:red}',
|
2013-04-14 23:38:24 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$tests[] = array(
|
2013-12-26 23:59:56 +01:00
|
|
|
'color:#FF00FF;',
|
|
|
|
'color:#F0F;',
|
2013-04-14 23:38:24 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$tests[] = array(
|
2014-10-08 16:34:49 +02:00
|
|
|
__DIR__ . '/sample/import_files/index.css',
|
|
|
|
'background:url(data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/sample/import_files/file.png')) . ');',
|
2013-04-14 23:38:24 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$tests[] = array(
|
|
|
|
'/* This is a CSS comment */',
|
|
|
|
'',
|
|
|
|
);
|
|
|
|
|
|
|
|
$tests[] = array(
|
|
|
|
'body { color: red; }',
|
|
|
|
'body{color:red}',
|
|
|
|
);
|
|
|
|
|
2013-04-22 10:19:35 +02:00
|
|
|
/*
|
|
|
|
* https://github.com/forkcms/forkcms/issues/387
|
|
|
|
*
|
|
|
|
* CSS backslash.
|
|
|
|
* * Backslash escaped by backslash in CSS
|
|
|
|
* * Double CSS backslashed escaped twice for in PHP string
|
|
|
|
*/
|
|
|
|
$tests[] = array(
|
|
|
|
'.iconic.map-pin:before { content: "\\\\"; }',
|
|
|
|
'.iconic.map-pin:before{content:"\\\\"}',
|
|
|
|
);
|
2013-04-22 10:16:01 +02:00
|
|
|
|
2014-10-07 18:21:22 +02:00
|
|
|
// whitespace inside strings shouldn't be replaced
|
|
|
|
$tests[] = array(
|
|
|
|
'content:"preserve whitespace',
|
|
|
|
'content:"preserve whitespace',
|
|
|
|
);
|
|
|
|
|
2013-04-14 23:38:24 +02:00
|
|
|
return $tests;
|
|
|
|
}
|
2013-12-01 23:47:40 +01:00
|
|
|
|
2014-10-09 08:56:14 +02:00
|
|
|
public function dataProviderPaths()
|
|
|
|
{
|
2013-12-01 23:47:40 +01:00
|
|
|
$tests = array();
|
|
|
|
|
2014-10-08 16:34:49 +02:00
|
|
|
$source = __DIR__ . '/sample/convert_relative_path/source';
|
|
|
|
$target = __DIR__ . '/sample/convert_relative_path/target';
|
2013-12-01 23:47:40 +01:00
|
|
|
|
|
|
|
$tests[] = array(
|
|
|
|
$source . '/external.css',
|
|
|
|
$target . '/external.css',
|
|
|
|
file_get_contents($source . '/external.css'),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
return $tests;
|
|
|
|
}
|
2013-04-14 23:38:24 +02:00
|
|
|
}
|