summaryrefslogtreecommitdiff
path: root/_test/tests/lib/exe/css_css_compress.test.php
blob: 807317ca6c2bb2ca7653d7bca1860cfa74e89f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php

require_once DOKU_INC.'lib/exe/css.php';

class css_css_compress_test extends DokuWikiTest {

    function test_mlcom1(){
        $text = '/**
                  * A multi
                  * line *test*
                  * check
                  */';
        $this->assertEquals('', css_compress($text));
    }

    function test_mlcom2(){
        $text = '#comment/* */ {
                    color: lime;
                }';
        $this->assertEquals('#comment/* */{color:lime;}', css_compress($text));
    }

    function test_slcom1(){
        $text = '// this is a comment';
        $this->assertEquals('', css_compress($text));
    }

    function test_slcom2(){
        $text = '#foo {
                    color: lime; // another comment
                }';
        $this->assertEquals('#foo{color:lime;}', css_compress($text));
    }

    function test_slcom3(){
        $text = '#foo {
                    background-image: url(http://foo.bar/baz.jpg); // this is a comment
                }';
        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
    }

    function test_slcom4(){
        $text = '#foo {
                    background-image: url(http://foo.bar/baz.jpg); background-image: url(http://foo.bar/baz.jpg); // this is a comment
                }';
        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
    }

    function test_slcom5(){
        $text = '#foo {
                    background-image: url(http://foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented
                }';
        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
    }

    function test_slcom6(){
        $text = '#foo {
                    background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented
                }';
        $this->assertEquals('#foo{background-image:url(//foo.bar/baz.jpg);}', css_compress($text));
    }

    function test_slcom7(){
        $text = '#foo a[href ^="https://"], #foo a[href ^=\'https://\'] {
                    background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is \'all\' "commented"
                }';
        $this->assertEquals('#foo a[href ^="https://"],#foo a[href ^=\'https://\']{background-image:url(//foo.bar/baz.jpg);}', css_compress($text));
    }


    function test_hack(){
        $text = '/* Mac IE will not see this and continue with inline-block */
                 /* \\*/
                 display: inline; 
                 /* */';
        $this->assertEquals('/* \\*/display:inline;/* */', css_compress($text));
    }

    function test_hack2(){
        $text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */
                 /*\\*/
                 * html .page {
                     height: 450px;
                 }
                 /**/';
        $this->assertEquals('/*\\*/* html .page{height:450px;}/**/', css_compress($text));
    }

    function test_nl1(){
        $text = "a{left:20px;\ntop:20px}";
        $this->assertEquals('a{left:20px;top:20px}', css_compress($text));
    }

    function test_shortening() {
        $input = array(
            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {',
            'margin:  1px 1px 1px 1px;',
            'padding: 1px 2px 1px 2px;',
            'margin:  1px 2px 3px 1px;',
            'padding: 1px 2px 3px 4px;',
            'margin:  00.00em 0em 01.00px 0em;',
            'padding: 0010em 0010.00em 00.00em 00.00100em;',
            'padding: 0010% 0010.00% 00.00% 00.00100xxx;',
            'padding: 0.0em .0em 0.em 00.00em;',
            'padding: 01.0em;',
            'color:   #FFFFFF;',
            'color:   #777777;',
            'color:   #123456;',
            'border:  01.0em solid #ffffff;',
        );

        $expected = array(
            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{',
            'margin:1px;',
            'padding:1px 2px;',
            'margin:1px 2px 3px 1px;',
            'padding:1px 2px 3px 4px;',
            'margin:0 0 1px 0;',
            'padding:10em 10em 0 .001em;',
            'padding:10% 10% 0 00.00100xxx;',
            'padding:0;',
            'padding:1em;',
            'color:#FFF;',
            'color:#777;',
            'color:#123456;',
            'border:1em solid #fff;',
        );

        $input = array_map('css_compress', $input);

        $this->assertEquals($expected, $input);
    }

    function test_data() {
        $input  = 'list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);';
        $expect = 'list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);';

        $this->assertEquals($expect, css_compress($input));
    }

}

//Setup VIM: ex: et ts=4 :