diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2013-11-05 20:51:07 +0000 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2013-11-05 20:51:07 +0000 |
commit | ab1fef6644927b857c64c9c153915d50ef2607f1 (patch) | |
tree | cce51caaed2e8ed0d99b3cfaf5b7f4f9ebb20f90 /_test | |
parent | 6d7e4640bed01599dac4bbf5c00b0aff8d3dd4ba (diff) | |
download | rpg-ab1fef6644927b857c64c9c153915d50ef2607f1.tar.gz rpg-ab1fef6644927b857c64c9c153915d50ef2607f1.tar.bz2 |
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.
Diffstat (limited to '_test')
-rw-r--r-- | _test/tests/lib/exe/css_at_import_less.test.php | 78 |
1 files changed, 78 insertions, 0 deletions
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 @@ +<?php + +require_once DOKU_INC.'lib/exe/css.php'; + +class css_at_import_less_test extends DokuWikiTest { + + protected $file = ''; + protected $import = ''; + + public function setUpFiles($subdir = '') { + + $dir = TMP_DIR . $subdir; + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + if (!is_dir($dir)) { + $this->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 : |