Skip to content
Snippets Groups Projects
Commit ab1fef66 authored by Christopher Smith's avatar Christopher Smith
Browse files

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.
parent 6d7e4640
No related branches found
No related tags found
No related merge requests found
<?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 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment