forked from leafo/scssphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiTest.php
More file actions
133 lines (116 loc) · 3.12 KB
/
ApiTest.php
File metadata and controls
133 lines (116 loc) · 3.12 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
<?php
/**
* SCSSPHP
*
* @copyright 2012-2015 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
* @link http://leafo.github.io/scssphp
*/
namespace Leafo\ScssPhp\Tests;
use Leafo\ScssPhp\Compiler;
/**
* API test
*
* @author Leaf Corcoran <leafot@gmail.com>
*/
class ApiTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->scss = new Compiler();
}
public function testUserFunction()
{
$this->scss->registerFunction('add-two', function ($args) {
list($a, $b) = $args;
return $a[1] + $b[1];
});
$this->assertEquals(
'result: 30;',
$this->compile('result: add-two(10, 20);')
);
}
public function testUserFunctionNull()
{
$this->scss->registerFunction('get-null', function ($args) {
return Compiler::$null;
});
$this->assertEquals(
'',
$this->compile('result: get-null();')
);
}
public function testUserFunctionKwargs()
{
$this->scss->registerFunction(
'divide',
function ($args, $kwargs) {
return $kwargs['dividend'][1] / $kwargs['divisor'][1];
},
array('dividend', 'divisor')
);
$this->assertEquals(
'result: 15;',
$this->compile('result: divide($divisor: 2, $dividend: 30);')
);
}
public function testImportMissing()
{
$this->assertEquals(
'@import "missing";',
$this->compile('@import "missing";')
);
}
public function testImportCustomCallback()
{
$this->scss->addImportPath(function ($path) {
return __DIR__ . '/inputs/' . str_replace('.css', '.scss', $path);
});
$this->assertEquals(
trim(file_get_contents(__DIR__ . '/outputs/variables.css')),
$this->compile('@import "variables.css";')
);
}
/**
* @dataProvider provideSetVariables
*/
public function testSetVariables($expected, $scss, $variables)
{
$this->scss->setVariables($variables);
$this->assertEquals($expected, $this->compile($scss));
}
public function provideSetVariables()
{
return array(
array(
".magic {\n color: red;\n width: 760px; }",
'.magic { color: $color; width: $base - 200; }',
array(
'color' => 'red',
'base' => '960px',
),
),
array(
".logo {\n color: #808080; }",
'.logo { color: desaturate($primary, 100%); }',
array(
'primary' => '#ff0000',
),
),
);
}
public function testCompileByteOrderMarker()
{
// test that BOM is stripped/ignored
$this->assertEquals(
'@import "main";',
$this->compile("\xEF\xBB\xBF@import \"main\";")
);
}
public function compile($str)
{
return trim($this->scss->compile($str));
}
}