Skip to content
Snippets Groups Projects
Commit 6e0b4b67 authored by Michael Hamann's avatar Michael Hamann
Browse files

Fixed css_loadfile and removed unneeded complexity, added testcases

parent f7d780b9
No related branches found
No related tags found
No related merge requests found
<?php
require_once DOKU_INC.'lib/exe/css.php';
class css_css_loadfile_test extends UnitTestCase {
public function setUp() {
$this->file = tempnam('/tmp', 'css');
parent::setUp();
}
private function csstest($input, $output = null, $location = 'http://www.example.com/') {
io_saveFile($this->file, $input);
$this->assertEqual(css_loadfile($this->file, $location), (is_null($output) ? $input : $output));
}
public function test_url_relative() {
$this->csstest('#test { background: url("test/test.png"); }', '#test { background: url("http://www.example.com/test/test.png"); }');
$this->csstest('#test { background: url(\'test/test.png\'); }', '#test { background: url(\'http://www.example.com/test/test.png\'); }');
}
public function test_url_absolute() {
$this->csstest('#test { background: url("/test/test.png"); }');
$this->csstest('#test { background: url(\'/test/test.png\'); }');
}
public function test_url_with_protocol() {
$this->csstest('#test { background: url("http://www.test.com/test/test.png"); }');
$this->csstest('#test { background: url("https://www.test.com/test/test.png"); }');
$this->csstest('#test { background: url(\'http://www.test.com/test/test.png\'); }');
$this->csstest('#test { background: url(\'https://www.test.com/test/test.png\'); }');
}
public function test_import_relative() {
$this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";');
$this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';');
}
public function test_import_absolute() {
$this->csstest('@import "/test/test.png";');
$this->csstest('@import \'/test/test.png\';');
}
public function test_import_with_protocol() {
$this->csstest('@import "http://www.test.com/test/test.png";');
$this->csstest('@import "https://www.test.com/test/test.png";');
$this->csstest('@import \'http://www.test.com/test/test.png\';');
$this->csstest('@import \'https://www.test.com/test/test.png\';');
}
public function tearDown() {
unlink($this->file);
unset($this->file);
parent::tearDown();
}
}
//Setup VIM: ex: et ts=4 sw=4 :
......@@ -267,8 +267,8 @@ function css_loadfile($file,$location=''){
$css = io_readFile($file);
if(!$location) return $css;
$css = preg_replace('#(url\([ \'"]*)((?!/|http://|https://| |\'|"))#','\\1'.$location.'\\3',$css);
$css = preg_replace('#(@import\s+[\'"])((?!/|http://|https://))#', '\\1'.$location.'\\2"', $css);
$css = preg_replace('#(url\([ \'"]*)(?!/|http://|https://| |\'|")#','\\1'.$location,$css);
$css = preg_replace('#(@import\s+[\'"])(?!/|http://|https://)#', '\\1'.$location, $css);
return $css;
}
......
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