-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathOptionsTest.php
More file actions
96 lines (73 loc) · 2.51 KB
/
OptionsTest.php
File metadata and controls
96 lines (73 loc) · 2.51 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
<?php
namespace CssCrush\UnitTest;
use CssCrush\Options;
use CssCrush\Version;
class OptionsTest extends \PHPUnit\Framework\TestCase
{
public $testFile;
public function setUp(): void
{
bootstrap_process();
$this->testFile = temp_file("\n foo {bar: baz;} \n\n baz {bar: foo;}");
}
public function testDefaults()
{
$options = new Options();
$standardOptions = Options::filter();
$this->assertEquals($standardOptions, $options->get());
$testOptions = ['plugins' => ['foo', 'bar'], 'minify' => false];
$options = new Options($testOptions);
$initialOptionsCopy = $testOptions + $standardOptions;
$this->assertEquals($initialOptionsCopy, $options->get());
}
public function testBoilerplate()
{
$boilerplate = <<<TPL
Line breaks
preserved
{{version}}
TPL;
$result = csscrush_string('foo { bar: baz; }', [
'boilerplate' => temp_file($boilerplate),
'newlines' => 'unix',
]);
$this->assertStringContainsStringIgnoringCase(' * ' . Version::detect(), (string) $result);
$this->assertStringContainsStringIgnoringCase(" * Line breaks\n * preserved\n *", (string) $result);
}
public function testFormatters()
{
$sample = '/* A comment */ foo {bar: baz;}';
$single_line_expected = <<<TPL
/* A comment */
foo { bar: baz; }
TPL;
$single_line = csscrush_string($sample, ['formatter' => 'single-line']);
$this->assertEquals($single_line_expected, $single_line);
$padded_expected = <<<TPL
/* A comment */
foo { bar: baz; }
TPL;
$padded = csscrush_string($sample, ['formatter' => 'padded']);
$this->assertEquals($padded_expected, $padded);
$block_expected = <<<TPL
/* A comment */
foo {
bar: baz;
}
TPL;
$block = csscrush_string($sample, ['formatter' => 'block']);
$this->assertEquals($block_expected, $block);
}
public function testSourceMaps()
{
csscrush_file($this->testFile, ['source_map' => true]);
$source_map_contents = file_get_contents("$this->testFile.crush.css.map");
$this->assertMatchesRegularExpression('~"version": ?3,~', $source_map_contents);
}
public function testAdvancedMinify()
{
$sample = "foo { color: papayawhip; color: #cccccc;}";
$output = csscrush_string($sample, ['minify' => ['colors']]);
$this->assertEquals('foo{color:#ffefd5;color:#ccc}', $output);
}
}