xref: /dokuwiki/_test/tests/lib/exe/css_css_compress.test.php (revision fe5a50c39e9bd837f887ea7ad8335717a6c6ab92)
1f8369d7dSTobias Sarnowski<?php
2f8369d7dSTobias Sarnowski
3f8369d7dSTobias Sarnowskirequire_once DOKU_INC.'lib/exe/css.php';
4f8369d7dSTobias Sarnowski
5f8369d7dSTobias Sarnowskiclass css_css_compress_test extends DokuWikiTest {
6f8369d7dSTobias Sarnowski
7f8369d7dSTobias Sarnowski    function test_mlcom1(){
8f8369d7dSTobias Sarnowski        $text = '/**
9f8369d7dSTobias Sarnowski                  * A multi
10f8369d7dSTobias Sarnowski                  * line *test*
11f8369d7dSTobias Sarnowski                  * check
12f8369d7dSTobias Sarnowski                  */';
13*fe5a50c3SAndreas Gohr        $this->assertEquals('', css_compress($text));
14f8369d7dSTobias Sarnowski    }
15f8369d7dSTobias Sarnowski
16f8369d7dSTobias Sarnowski    function test_mlcom2(){
17f8369d7dSTobias Sarnowski        $text = '#comment/* */ {
18f8369d7dSTobias Sarnowski                    color: lime;
19f8369d7dSTobias Sarnowski                }';
20*fe5a50c3SAndreas Gohr        $this->assertEquals('#comment/* */{color:lime;}', css_compress($text));
21f8369d7dSTobias Sarnowski    }
22f8369d7dSTobias Sarnowski
23f8369d7dSTobias Sarnowski    function test_slcom1(){
24f8369d7dSTobias Sarnowski        $text = '// this is a comment';
25*fe5a50c3SAndreas Gohr        $this->assertEquals('', css_compress($text));
26f8369d7dSTobias Sarnowski    }
27f8369d7dSTobias Sarnowski
28f8369d7dSTobias Sarnowski    function test_slcom2(){
29f8369d7dSTobias Sarnowski        $text = '#foo {
30f8369d7dSTobias Sarnowski                    color: lime; // another comment
31f8369d7dSTobias Sarnowski                }';
32*fe5a50c3SAndreas Gohr        $this->assertEquals('#foo{color:lime;}', css_compress($text));
33f8369d7dSTobias Sarnowski    }
34f8369d7dSTobias Sarnowski
35f8369d7dSTobias Sarnowski    function test_slcom3(){
36f8369d7dSTobias Sarnowski        $text = '#foo {
37*fe5a50c3SAndreas Gohr                    background-image: url(http://foo.bar/baz.jpg); // this is a comment
38f8369d7dSTobias Sarnowski                }';
39*fe5a50c3SAndreas Gohr        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
40*fe5a50c3SAndreas Gohr    }
41*fe5a50c3SAndreas Gohr
42*fe5a50c3SAndreas Gohr    function test_slcom4(){
43*fe5a50c3SAndreas Gohr        $text = '#foo {
44*fe5a50c3SAndreas Gohr                    background-image: url(http://foo.bar/baz.jpg); background-image: url(http://foo.bar/baz.jpg); // this is a comment
45*fe5a50c3SAndreas Gohr                }';
46*fe5a50c3SAndreas Gohr        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
47*fe5a50c3SAndreas Gohr    }
48*fe5a50c3SAndreas Gohr
49*fe5a50c3SAndreas Gohr    function test_slcom5(){
50*fe5a50c3SAndreas Gohr        $text = '#foo {
51*fe5a50c3SAndreas Gohr                    background-image: url(http://foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented
52*fe5a50c3SAndreas Gohr                }';
53*fe5a50c3SAndreas Gohr        $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text));
54f8369d7dSTobias Sarnowski    }
55f8369d7dSTobias Sarnowski
56f8369d7dSTobias Sarnowski    function test_hack(){
57f8369d7dSTobias Sarnowski        $text = '/* Mac IE will not see this and continue with inline-block */
58f8369d7dSTobias Sarnowski                 /* \\*/
59f8369d7dSTobias Sarnowski                 display: inline;
60f8369d7dSTobias Sarnowski                 /* */';
61*fe5a50c3SAndreas Gohr        $this->assertEquals('/* \\*/display:inline;/* */', css_compress($text));
62f8369d7dSTobias Sarnowski    }
63f8369d7dSTobias Sarnowski
64f8369d7dSTobias Sarnowski    function test_hack2(){
65f8369d7dSTobias Sarnowski        $text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */
66f8369d7dSTobias Sarnowski                 /*\\*/
67f8369d7dSTobias Sarnowski                 * html .page {
68f8369d7dSTobias Sarnowski                     height: 450px;
69f8369d7dSTobias Sarnowski                 }
70f8369d7dSTobias Sarnowski                 /**/';
71*fe5a50c3SAndreas Gohr        $this->assertEquals('/*\\*/* html .page{height:450px;}/**/', css_compress($text));
72f8369d7dSTobias Sarnowski    }
73f8369d7dSTobias Sarnowski
74f8369d7dSTobias Sarnowski    function test_nl1(){
75f8369d7dSTobias Sarnowski        $text = "a{left:20px;\ntop:20px}";
76*fe5a50c3SAndreas Gohr        $this->assertEquals('a{left:20px;top:20px}', css_compress($text));
77f8369d7dSTobias Sarnowski    }
78f8369d7dSTobias Sarnowski
79a467e020SAndreas Gohr    function test_shortening() {
80a467e020SAndreas Gohr        $input = array(
81a467e020SAndreas Gohr            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {',
82a467e020SAndreas Gohr            'margin:  1px 1px 1px 1px;',
83a467e020SAndreas Gohr            'padding: 1px 2px 1px 2px;',
84a467e020SAndreas Gohr            'margin:  1px 2px 3px 1px;',
85a467e020SAndreas Gohr            'padding: 1px 2px 3px 4px;',
86a467e020SAndreas Gohr            'margin:  00.00em 0em 01.00px 0em;',
87a467e020SAndreas Gohr            'padding: 0010em 0010.00em 00.00em 00.00100em;',
88a467e020SAndreas Gohr            'padding: 0010% 0010.00% 00.00% 00.00100xxx;',
89a467e020SAndreas Gohr            'padding: 0.0em .0em 0.em 00.00em;',
90a467e020SAndreas Gohr            'padding: 01.0em;',
91a467e020SAndreas Gohr            'color:   #FFFFFF;',
92a467e020SAndreas Gohr            'color:   #777777;',
93a467e020SAndreas Gohr            'color:   #123456;',
94a467e020SAndreas Gohr            'border:  01.0em solid #ffffff;',
95a467e020SAndreas Gohr        );
96a467e020SAndreas Gohr
97a467e020SAndreas Gohr        $expected = array(
98a467e020SAndreas Gohr            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{',
99a467e020SAndreas Gohr            'margin:1px;',
100a467e020SAndreas Gohr            'padding:1px 2px;',
101a467e020SAndreas Gohr            'margin:1px 2px 3px 1px;',
102a467e020SAndreas Gohr            'padding:1px 2px 3px 4px;',
103a467e020SAndreas Gohr            'margin:0 0 1px 0;',
104a467e020SAndreas Gohr            'padding:10em 10em 0 .001em;',
105a467e020SAndreas Gohr            'padding:10% 10% 0 00.00100xxx;',
106a467e020SAndreas Gohr            'padding:0;',
107a467e020SAndreas Gohr            'padding:1em;',
108a467e020SAndreas Gohr            'color:#FFF;',
109a467e020SAndreas Gohr            'color:#777;',
110a467e020SAndreas Gohr            'color:#123456;',
111a467e020SAndreas Gohr            'border:1em solid #fff;',
112a467e020SAndreas Gohr        );
113a467e020SAndreas Gohr
114a467e020SAndreas Gohr        $input = array_map('css_compress', $input);
115a467e020SAndreas Gohr
116a467e020SAndreas Gohr        $this->assertEquals($expected, $input);
117a467e020SAndreas Gohr    }
118a467e020SAndreas Gohr
1190499ebedSAndreas Gohr    function test_data() {
1200499ebedSAndreas Gohr        $input  = 'list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);';
1210499ebedSAndreas Gohr        $expect = 'list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);';
1220499ebedSAndreas Gohr
1230499ebedSAndreas Gohr        $this->assertEquals($expect, css_compress($input));
1240499ebedSAndreas Gohr    }
1250499ebedSAndreas Gohr
126f8369d7dSTobias Sarnowski}
127f8369d7dSTobias Sarnowski
128f8369d7dSTobias Sarnowski//Setup VIM: ex: et ts=4 :
129