From ab1fef6644927b857c64c9c153915d50ef2607f1 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 5 Nov 2013 20:51:07 +0000 Subject: Test to ensure less can parse the @import rewritten by css_loadfile() This test is horrible, but I believe necessary to ensure that the @import of less files actually works. It is horrible as its not a unit test and its not a true functional test. It probably implies the code in css_out() should be refactored to make it easier to test intermediate results. --- _test/tests/lib/exe/css_at_import_less.test.php | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 _test/tests/lib/exe/css_at_import_less.test.php (limited to '_test/tests/lib') diff --git a/_test/tests/lib/exe/css_at_import_less.test.php b/_test/tests/lib/exe/css_at_import_less.test.php new file mode 100644 index 000000000..4a6efcf44 --- /dev/null +++ b/_test/tests/lib/exe/css_at_import_less.test.php @@ -0,0 +1,78 @@ +markTestSkipped('Could not create directory.'); + } + + $this->file = tempnam($dir, 'css'); + + $import = ''; + do { + if ($import) unlink($import); + $import = tempnam($dir, 'less'); + $ok = rename($import, $import.'.less'); + } while (!$ok); + + $this->import = $import.'.less'; + } + + private function csstest($input, $expected_css, $expected_less) { + $location = "http://test.com/"; + io_saveFile($this->file, $input); + $css = css_loadfile($this->file, $location); + $less = css_parseless($css); + $this->assertEquals($expected_css, $css); + $this->assertEquals($expected_less, $less); + } + + public function test_basic() { + $this->setUpFiles(); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function test_subdirectory() { + $this->setUpFiles('/foo/bar'); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/foo/bar/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function tearDown() { + unlink($this->file); + unlink($this->import); + unset($this->file, $this->import); + } +} + +//Setup VIM: ex: et ts=4 sw=4 : -- cgit v1.2.3