1ab1fef66SChristopher Smith<?php 2ab1fef66SChristopher Smith 3ab1fef66SChristopher Smithrequire_once DOKU_INC.'lib/exe/css.php'; 4ab1fef66SChristopher Smith 5ab1fef66SChristopher Smithclass css_at_import_less_test extends DokuWikiTest { 6ab1fef66SChristopher Smith 7ab1fef66SChristopher Smith protected $file = ''; 8ab1fef66SChristopher Smith protected $import = ''; 9ab1fef66SChristopher Smith 10ab1fef66SChristopher Smith public function setUpFiles($subdir = '') { 11ab1fef66SChristopher Smith 12ab1fef66SChristopher Smith $dir = TMP_DIR . $subdir; 13ab1fef66SChristopher Smith if (!is_dir($dir)) { 14ab1fef66SChristopher Smith mkdir($dir, 0777, true); 15ab1fef66SChristopher Smith } 16ab1fef66SChristopher Smith if (!is_dir($dir)) { 17e8da0265SYurii K $this->markTestSkipped('Could not create directory.'); 18ab1fef66SChristopher Smith } 19ab1fef66SChristopher Smith 20ab1fef66SChristopher Smith $this->file = tempnam($dir, 'css'); 21ab1fef66SChristopher Smith 22ab1fef66SChristopher Smith $import = ''; 23e8da0265SYurii K do { 24ab1fef66SChristopher Smith if ($import) unlink($import); 25ab1fef66SChristopher Smith $import = tempnam($dir, 'less'); 26e8da0265SYurii K $ok = rename($import, $import.'.less'); 27e8da0265SYurii K } while (!$ok); 28ab1fef66SChristopher Smith 297b0d379fSYurii K $this->import = $import.'.less'; 30ab1fef66SChristopher Smith } 31ab1fef66SChristopher Smith 32ab1fef66SChristopher Smith private function csstest($input, $expected_css, $expected_less) { 33ab1fef66SChristopher Smith $location = "http://test.com/"; 34ab1fef66SChristopher Smith io_saveFile($this->file, $input); 35ab1fef66SChristopher Smith $css = css_loadfile($this->file, $location); 36ab1fef66SChristopher Smith $less = css_parseless($css); 37e8da0265SYurii K $this->assertEquals($expected_css, $css); 38ab1fef66SChristopher Smith $this->assertEquals($expected_less, $less); 39ab1fef66SChristopher Smith } 40ab1fef66SChristopher Smith 41cd08f3e6SYurii K /** 42cd08f3e6SYurii K * makes proper relative path to be used in CSS @import 43cd08f3e6SYurii K * @param string $path 44cd08f3e6SYurii K * @return string 45cd08f3e6SYurii K */ 46e8da0265SYurii K private function importPath($path) { 47cd08f3e6SYurii K if (isWindows()) { 48cd08f3e6SYurii K return preg_replace('#(^.*[\\\\])#','', $path); 49cd08f3e6SYurii K } 50cd08f3e6SYurii K return preg_replace('#(^.*[/])#','', $path); 51e8da0265SYurii K } 52e8da0265SYurii K 53ab1fef66SChristopher Smith public function test_basic() { 54ab1fef66SChristopher Smith $this->setUpFiles(); 55ab1fef66SChristopher Smith 56e8da0265SYurii K $import = $this->importPath($this->import); 57ab1fef66SChristopher Smith $in_css = '@import "'.$import.'";'; 58ab1fef66SChristopher Smith $in_less = '@foo: "bar"; 59ab1fef66SChristopher Smithcontent: @foo;'; 60ab1fef66SChristopher Smith 61ab1fef66SChristopher Smith $expected_css = '@import "/'.$import.'";'; 62ab1fef66SChristopher Smith $expected_less = 'content: "bar";'; 63ab1fef66SChristopher Smith 64ab1fef66SChristopher Smith io_saveFile($this->import, $in_less); 65ab1fef66SChristopher Smith $this->csstest($in_css, $expected_css, $expected_less); 66ab1fef66SChristopher Smith } 67ab1fef66SChristopher Smith 68ab1fef66SChristopher Smith public function test_subdirectory() { 69ab1fef66SChristopher Smith $this->setUpFiles('/foo/bar'); 70ab1fef66SChristopher Smith 71e8da0265SYurii K $import = $this->importPath($this->import); 72ab1fef66SChristopher Smith $in_css = '@import "'.$import.'";'; 73ab1fef66SChristopher Smith $in_less = '@foo: "bar"; 74ab1fef66SChristopher Smithcontent: @foo;'; 75ab1fef66SChristopher Smith 76e8da0265SYurii K $expected_css = isWindows() ? '@import "\\foo\\bar/'.$import.'";' : '@import "/foo/bar/'.$import.'";'; 77ab1fef66SChristopher Smith $expected_less = 'content: "bar";'; 78ab1fef66SChristopher Smith 79ab1fef66SChristopher Smith io_saveFile($this->import, $in_less); 80ab1fef66SChristopher Smith $this->csstest($in_css, $expected_css, $expected_less); 81ab1fef66SChristopher Smith } 82ab1fef66SChristopher Smith 83*1c33cec3SAndreas Gohr public function tearDown() : void { 84ab1fef66SChristopher Smith unlink($this->file); 85ab1fef66SChristopher Smith unlink($this->import); 86ab1fef66SChristopher Smith unset($this->file, $this->import); 87ab1fef66SChristopher Smith } 88ab1fef66SChristopher Smith} 89ab1fef66SChristopher Smith 90ab1fef66SChristopher Smith//Setup VIM: ex: et ts=4 sw=4 : 91