Repository navigation
Expand file tree
/
Copy pathCSSTest.php
More file actions
134 lines (114 loc) · 3.3 KB
/
Copy pathCSSTest.php
File metadata and controls
134 lines (114 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require_once __DIR__.'/../Minify.php';
require_once __DIR__.'/../CSS.php';
require_once __DIR__.'/../Exception.php';
require_once 'PHPUnit/Framework/TestCase.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
*/
public function minify($input, $expected, $options)
{
$this->minifier->add($input);
$result = $this->minifier->minify(false, $options);
$this->assertEquals($result, $expected);
}
/**
* Test conversion of relative paths, provided by dataProviderPaths
*
* @test
* @dataProvider dataProviderPaths
*/
public function convertRelativePath($source, $target, $expected, $options) {
$this->minifier->add($source);
$result = $this->minifier->minify($target, $options);
$this->assertEquals($result, $expected);
}
/**
* Test cases [input, expected result, options]
*
* @return array
*/
public function dataProvider()
{
$tests = array();
$tests[] = array(
__DIR__.'/sample/css/combine_imports/index.css',
file_get_contents(__DIR__.'/sample/css/combine_imports/import.css')."\n",
Minify\CSS::COMBINE_IMPORTS
);
$tests[] = array(
'color: #FF00FF;',
'color: #F0F;',
Minify\CSS::SHORTEN_HEX
);
$tests[] = array(
__DIR__.'/sample/css/import_files/index.css',
'background: url(data:image/png;base64,'.base64_encode(file_get_contents(__DIR__.'/sample/css/import_files/file.png')).');'."\n",
Minify\CSS::IMPORT_FILES
);
$tests[] = array(
'/* This is a CSS comment */',
'',
Minify\CSS::STRIP_COMMENTS
);
$tests[] = array(
'body { color: red; }',
'body{color:red}',
Mi
51F3
nify\CSS::STRIP_WHITESPACE
);
/*
* 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:"\\\\"}',
Minify\CSS::ALL
);
return $tests;
}
/**
*
*/
public function dataProviderPaths() {
$tests = array();
$source = __DIR__.'/sample/css/convert_relative_path/source';
$target = __DIR__.'/sample/css/convert_relative_path/target';
$tests[] = array(
$source . '/external.css',
$target . '/external.css',
file_get_contents($source . '/external.css'),
0
);
return $tests;
}
}