xref: /dokuwiki/_test/tests/lib/exe/css_css_compress.test.php (revision a467e020fa551217347181ffd6915c7d29e6ff59)
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                  */';
13f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '');
14f8369d7dSTobias Sarnowski    }
15f8369d7dSTobias Sarnowski
16f8369d7dSTobias Sarnowski    function test_mlcom2(){
17f8369d7dSTobias Sarnowski        $text = '#comment/* */ {
18f8369d7dSTobias Sarnowski                    color: lime;
19f8369d7dSTobias Sarnowski                }';
20f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '#comment/* */{color:lime;}');
21f8369d7dSTobias Sarnowski    }
22f8369d7dSTobias Sarnowski
23f8369d7dSTobias Sarnowski    function test_slcom1(){
24f8369d7dSTobias Sarnowski        $text = '// this is a comment';
25f8369d7dSTobias Sarnowski        $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                }';
32f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '#foo{color:lime;}');
33f8369d7dSTobias Sarnowski    }
34f8369d7dSTobias Sarnowski
35f8369d7dSTobias Sarnowski    function test_slcom3(){
36f8369d7dSTobias Sarnowski        $text = '#foo {
37f8369d7dSTobias Sarnowski                    background-image: url(http://foo.bar/baz.jpg);
38f8369d7dSTobias Sarnowski                }';
39f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '#foo{background-image:url(http://foo.bar/baz.jpg);}');
40f8369d7dSTobias Sarnowski    }
41f8369d7dSTobias Sarnowski
42f8369d7dSTobias Sarnowski    function test_hack(){
43f8369d7dSTobias Sarnowski        $text = '/* Mac IE will not see this and continue with inline-block */
44f8369d7dSTobias Sarnowski                 /* \\*/
45f8369d7dSTobias Sarnowski                 display: inline;
46f8369d7dSTobias Sarnowski                 /* */';
47f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '/* \\*/display:inline;/* */');
48f8369d7dSTobias Sarnowski    }
49f8369d7dSTobias Sarnowski
50f8369d7dSTobias Sarnowski    function test_hack2(){
51f8369d7dSTobias Sarnowski        $text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */
52f8369d7dSTobias Sarnowski                 /*\\*/
53f8369d7dSTobias Sarnowski                 * html .page {
54f8369d7dSTobias Sarnowski                     height: 450px;
55f8369d7dSTobias Sarnowski                 }
56f8369d7dSTobias Sarnowski                 /**/';
57f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), '/*\\*/* html .page{height:450px;}/**/');
58f8369d7dSTobias Sarnowski    }
59f8369d7dSTobias Sarnowski
60f8369d7dSTobias Sarnowski    function test_nl1(){
61f8369d7dSTobias Sarnowski        $text = "a{left:20px;\ntop:20px}";
62f8369d7dSTobias Sarnowski        $this->assertEquals(css_compress($text), 'a{left:20px;top:20px}');
63f8369d7dSTobias Sarnowski    }
64f8369d7dSTobias Sarnowski
65*a467e020SAndreas Gohr    function test_shortening() {
66*a467e020SAndreas Gohr        $input = array(
67*a467e020SAndreas Gohr            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {',
68*a467e020SAndreas Gohr            'margin:  1px 1px 1px 1px;',
69*a467e020SAndreas Gohr            'padding: 1px 2px 1px 2px;',
70*a467e020SAndreas Gohr            'margin:  1px 2px 3px 1px;',
71*a467e020SAndreas Gohr            'padding: 1px 2px 3px 4px;',
72*a467e020SAndreas Gohr            'margin:  00.00em 0em 01.00px 0em;',
73*a467e020SAndreas Gohr            'padding: 0010em 0010.00em 00.00em 00.00100em;',
74*a467e020SAndreas Gohr            'padding: 0010% 0010.00% 00.00% 00.00100xxx;',
75*a467e020SAndreas Gohr            'padding: 0.0em .0em 0.em 00.00em;',
76*a467e020SAndreas Gohr            'padding: 01.0em;',
77*a467e020SAndreas Gohr            'color:   #FFFFFF;',
78*a467e020SAndreas Gohr            'color:   #777777;',
79*a467e020SAndreas Gohr            'color:   #123456;',
80*a467e020SAndreas Gohr            'border:  01.0em solid #ffffff;',
81*a467e020SAndreas Gohr        );
82*a467e020SAndreas Gohr
83*a467e020SAndreas Gohr        $expected = array(
84*a467e020SAndreas Gohr            'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{',
85*a467e020SAndreas Gohr            'margin:1px;',
86*a467e020SAndreas Gohr            'padding:1px 2px;',
87*a467e020SAndreas Gohr            'margin:1px 2px 3px 1px;',
88*a467e020SAndreas Gohr            'padding:1px 2px 3px 4px;',
89*a467e020SAndreas Gohr            'margin:0 0 1px 0;',
90*a467e020SAndreas Gohr            'padding:10em 10em 0 .001em;',
91*a467e020SAndreas Gohr            'padding:10% 10% 0 00.00100xxx;',
92*a467e020SAndreas Gohr            'padding:0;',
93*a467e020SAndreas Gohr            'padding:1em;',
94*a467e020SAndreas Gohr            'color:#FFF;',
95*a467e020SAndreas Gohr            'color:#777;',
96*a467e020SAndreas Gohr            'color:#123456;',
97*a467e020SAndreas Gohr            'border:1em solid #fff;',
98*a467e020SAndreas Gohr        );
99*a467e020SAndreas Gohr
100*a467e020SAndreas Gohr        $input = array_map('css_compress', $input);
101*a467e020SAndreas Gohr
102*a467e020SAndreas Gohr        $this->assertEquals($expected, $input);
103*a467e020SAndreas Gohr    }
104*a467e020SAndreas Gohr
105f8369d7dSTobias Sarnowski}
106f8369d7dSTobias Sarnowski
107f8369d7dSTobias Sarnowski//Setup VIM: ex: et ts=4 :
108