xref: /dokuwiki/_test/tests/lib/exe/css_css_loadfile.test.php (revision 30f686eb67205a1da8765c992e2f9ee1a158c712)
1<?php
2
3require_once DOKU_INC.'lib/exe/css.php';
4
5class css_css_loadfile_test extends DokuWikiTest {
6
7    protected $file = '';
8
9    public function setUp() {
10        $this->file = tempnam(TMP_DIR, 'css');
11    }
12
13    private function csstest($input, $output = null, $location = 'http://www.example.com/') {
14        io_saveFile($this->file, $input);
15        $this->assertEquals((is_null($output) ? $input : $output), css_loadfile($this->file, $location));
16    }
17
18    public function test_url_relative() {
19        $this->csstest('#test { background: url("test/test.png"); }', '#test { background: url("http://www.example.com/test/test.png"); }');
20        $this->csstest('#test { background: url(\'test/test.png\'); }', '#test { background: url(\'http://www.example.com/test/test.png\'); }');
21    }
22
23    public function test_url_absolute() {
24        $this->csstest('#test { background: url("/test/test.png"); }');
25        $this->csstest('#test { background: url(\'/test/test.png\'); }');
26    }
27
28    public function test_url_with_protocol() {
29        $this->csstest('#test { background: url("http://www.test.com/test/test.png"); }');
30        $this->csstest('#test { background: url("https://www.test.com/test/test.png"); }');
31        $this->csstest('#test { background: url(\'http://www.test.com/test/test.png\'); }');
32        $this->csstest('#test { background: url(\'https://www.test.com/test/test.png\'); }');
33    }
34
35    public function test_import_relative() {
36        $this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";');
37        $this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';');
38        $this->csstest('@import url(test/test.png);', '@import url(http://www.example.com/test/test.png);');
39        $this->csstest('@import url("test/test.png");', '@import url("http://www.example.com/test/test.png");');
40    }
41
42    public function test_import_absolute() {
43        $this->csstest('@import "/test/test.png";');
44        $this->csstest('@import \'/test/test.png\';');
45        $this->csstest('@import url(/test/test.png);');
46        $this->csstest('@import url("/test/test.png");');
47    }
48
49    public function test_import_with_protocol() {
50        $this->csstest('@import "http://www.test.com/test/test.png";');
51        $this->csstest('@import "https://www.test.com/test/test.png";');
52        $this->csstest('@import \'http://www.test.com/test/test.png\';');
53        $this->csstest('@import \'https://www.test.com/test/test.png\';');
54        $this->csstest('@import url(http://www.test.com/test/test.png);');
55        $this->csstest('@import url("http://www.test.com/test/test.png");');
56    }
57
58    public function test_less_basic() {
59        $this->csstest('@import "test.less"', '@import "/test.less"');
60        $this->csstest('@import "/test.less"', '@import "/test.less"');
61        $this->csstest('@import url(http://test.less)');
62    }
63
64    // more expected use, where less @import(ed) from e.g. lib/plugins/plugin_name
65    public function test_less_subdirectories() {
66
67        unlink($this->file);
68
69        $dir = TMP_DIR.'/foo/bar';
70        mkdir($dir,0777,true);
71        $this->file = tempnam($dir, 'css');
72
73        $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"');
74        $this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\'');
75        $this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)');
76    }
77
78    public function tearDown() {
79        unlink($this->file);
80        unset($this->file);
81    }
82}
83
84//Setup VIM: ex: et ts=4 sw=4 :
85