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