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_hack(){ 57 $text = '/* Mac IE will not see this and continue with inline-block */ 58 /* \\*/ 59 display: inline; 60 /* */'; 61 $this->assertEquals('/* \\*/display:inline;/* */', css_compress($text)); 62 } 63 64 function test_hack2(){ 65 $text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */ 66 /*\\*/ 67 * html .page { 68 height: 450px; 69 } 70 /**/'; 71 $this->assertEquals('/*\\*/* html .page{height:450px;}/**/', css_compress($text)); 72 } 73 74 function test_nl1(){ 75 $text = "a{left:20px;\ntop:20px}"; 76 $this->assertEquals('a{left:20px;top:20px}', css_compress($text)); 77 } 78 79 function test_shortening() { 80 $input = array( 81 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {', 82 'margin: 1px 1px 1px 1px;', 83 'padding: 1px 2px 1px 2px;', 84 'margin: 1px 2px 3px 1px;', 85 'padding: 1px 2px 3px 4px;', 86 'margin: 00.00em 0em 01.00px 0em;', 87 'padding: 0010em 0010.00em 00.00em 00.00100em;', 88 'padding: 0010% 0010.00% 00.00% 00.00100xxx;', 89 'padding: 0.0em .0em 0.em 00.00em;', 90 'padding: 01.0em;', 91 'color: #FFFFFF;', 92 'color: #777777;', 93 'color: #123456;', 94 'border: 01.0em solid #ffffff;', 95 ); 96 97 $expected = array( 98 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{', 99 'margin:1px;', 100 'padding:1px 2px;', 101 'margin:1px 2px 3px 1px;', 102 'padding:1px 2px 3px 4px;', 103 'margin:0 0 1px 0;', 104 'padding:10em 10em 0 .001em;', 105 'padding:10% 10% 0 00.00100xxx;', 106 'padding:0;', 107 'padding:1em;', 108 'color:#FFF;', 109 'color:#777;', 110 'color:#123456;', 111 'border:1em solid #fff;', 112 ); 113 114 $input = array_map('css_compress', $input); 115 116 $this->assertEquals($expected, $input); 117 } 118 119 function test_data() { 120 $input = 'list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; 121 $expect = 'list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; 122 123 $this->assertEquals($expect, css_compress($input)); 124 } 125 126} 127 128//Setup VIM: ex: et ts=4 : 129