PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.0.6
Responsive Menu – Create Mobile-Friendly Menu v3.0.6
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / src / app / Mappers / scssphp / tests / InputTest.php

InputTest.php in Responsive Menu – Create Mobile-Friendly Menu 3.0.6, at src/app/Mappers/scssphp/tests/InputTest.php

84 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once __DIR__ . "/../scss.inc.php";
4
5 // Runs all the tests in inputs/ and compares their output to ouputs/
6
7 function _dump($value) {
8 fwrite(STDOUT, print_r($value, true));
9 }
10
11 function _quote($str) {
12 return preg_quote($str, "/");
13 }
14
15 class InputTest extends PHPUnit_Framework_TestCase {
16 protected static $inputDir = "inputs";
17 protected static $outputDir = "outputs";
18
19 public function setUp() {
20 $this->scss = new scssc();
21 $this->scss->addImportPath(__DIR__ . "/" . self::$inputDir);
22 }
23
24 /**
25 * @dataProvider fileNameProvider
26 */
27 public function testInputFile($inFname, $outFname) {
28 if (getenv("BUILD")) {
29 return $this->buildInput($inFname,$outFname);
30 }
31
32 if (!is_readable($outFname)) {
33 $this->fail("$outFname is missing, ".
34 "consider building tests with BUILD=true");
35 }
36
37 $input = file_get_contents($inFname);
38 $output = file_get_contents($outFname);
39
40 $this->assertEquals($output, $this->scss->compile($input));
41 }
42
43 public function fileNameProvider() {
44 return array_map(function($a) { return array($a, InputTest::outputNameFor($a)); },
45 self::findInputNames());
46 }
47
48 // only run when env is set
49 public function buildInput($inFname, $outFname) {
50 $css = $this->scss->compile(file_get_contents($inFname));
51 file_put_contents($outFname, $css);
52 }
53
54 static public function findInputNames($pattern="*") {
55 $files = glob(__DIR__ . "/" . self::$inputDir . "/" . $pattern);
56 $files = array_filter($files, "is_file");
57 if ($pattern = getenv("MATCH")) {
58 $files = array_filter($files, function($fname) use ($pattern) {
59 return preg_match("/$pattern/", $fname);
60 });
61 }
62
63 return $files;
64 }
65
66 static public function outputNameFor($input) {
67 $front = _quote(__DIR__ . "/");
68 $out = preg_replace("/^$front/", "", $input);
69
70 $in = _quote(self::$inputDir . "/");
71 $out = preg_replace("/$in/", self::$outputDir . "/", $out);
72 $out = preg_replace("/.scss$/", ".css", $out);
73
74 return __DIR__ . "/" . $out;
75 }
76
77 static public function buildTests($pattern) {
78 $files = self::findInputNames($pattern);
79 foreach ($files as $file) {
80 }
81 }
82 }
83
84