| 1 |
<?php |
| 2 |
|
| 3 |
require_once __DIR__ . "/../scss.inc.php"; |
| 4 |
|
| 5 |
class ApiTest extends PHPUnit_Framework_TestCase |
| 6 |
{ |
| 7 |
public function setUp() |
| 8 |
{ |
| 9 |
$this->scss = new scssc(); |
| 10 |
} |
| 11 |
|
| 12 |
public function testUserFunction() |
| 13 |
{ |
| 14 |
$this->scss->registerFunction("add-two", function ($args) { |
| 15 |
list($a, $b) = $args; |
| 16 |
return $a[1] + $b[1]; |
| 17 |
}); |
| 18 |
|
| 19 |
$this->assertEquals( |
| 20 |
"result: 30;", |
| 21 |
$this->compile("result: add-two(10, 20);") |
| 22 |
); |
| 23 |
} |
| 24 |
|
| 25 |
public function testImportMissing() |
| 26 |
{ |
| 27 |
$this->assertEquals( |
| 28 |
'@import "missing";', |
| 29 |
$this->compile('@import "missing";') |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
public function testImportCustomCallback() |
| 34 |
{ |
| 35 |
$this->scss->addImportPath(function ($path) { |
| 36 |
return __DIR__ . '/inputs/' . str_replace('.css', '.scss', $path); |
| 37 |
}); |
| 38 |
|
| 39 |
$this->assertEquals( |
| 40 |
trim(file_get_contents(__DIR__ . '/outputs/variables.css')), |
| 41 |
$this->compile('@import "variables.css";') |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @dataProvider provideSetVariables |
| 47 |
*/ |
| 48 |
public function testSetVariables($expected, $scss, $variables) |
| 49 |
{ |
| 50 |
$this->scss->setVariables($variables); |
| 51 |
|
| 52 |
$this->assertEquals($expected, $this->compile($scss)); |
| 53 |
} |
| 54 |
|
| 55 |
public function provideSetVariables() |
| 56 |
{ |
| 57 |
return array( |
| 58 |
array( |
| 59 |
".magic {\n color: red;\n width: 760px; }", |
| 60 |
'.magic { color: $color; width: $base - 200; }', |
| 61 |
array( |
| 62 |
'color' => 'red', |
| 63 |
'base' => '960px', |
| 64 |
), |
| 65 |
), |
| 66 |
array( |
| 67 |
".logo {\n color: #808080; }", |
| 68 |
'.logo { color: desaturate($primary, 100%); }', |
| 69 |
array( |
| 70 |
'primary' => '#ff0000', |
| 71 |
), |
| 72 |
), |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
public function compile($str) |
| 77 |
{ |
| 78 |
return trim($this->scss->compile($str)); |
| 79 |
} |
| 80 |
} |
| 81 |
|