xref: /dokuwiki/_test/tests/lib/exe/css_css_loadfile.test.php (revision 4eb5f931edaaabdd436f4c2802d0d293f8ef76cd)
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 "foo/test.less"', '@import "/foo/test.less"');
62        $this->csstest('@import url(http://test.less)');
63    }
64
65    // more expected use, where less @import(ed) from e.g. lib/plugins/plugin_name
66    public function test_less_subdirectories() {
67
68        unlink($this->file);
69
70        $dir = TMP_DIR.'/foo/bar';
71        mkdir($dir,0777,true);
72        $this->file = tempnam($dir, 'css');
73
74        $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"');
75        $this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\'');
76        $this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)');
77
78        $this->csstest('@import "abc/test.less"', '@import "/foo/bar/abc/test.less"');
79    }
80
81    public function tearDown() {
82        unlink($this->file);
83        unset($this->file);
84    }
85}
86
87//Setup VIM: ex: et ts=4 sw=4 :
88