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 */'; 13fe5a50c3SAndreas 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 }'; 20fe5a50c3SAndreas 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'; 25fe5a50c3SAndreas 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 }'; 32fe5a50c3SAndreas Gohr $this->assertEquals('#foo{color:lime;}', css_compress($text)); 33f8369d7dSTobias Sarnowski } 34f8369d7dSTobias Sarnowski 35f8369d7dSTobias Sarnowski function test_slcom3(){ 36f8369d7dSTobias Sarnowski $text = '#foo { 37fe5a50c3SAndreas Gohr background-image: url(http://foo.bar/baz.jpg); // this is a comment 38f8369d7dSTobias Sarnowski }'; 39fe5a50c3SAndreas Gohr $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); 40fe5a50c3SAndreas Gohr } 41fe5a50c3SAndreas Gohr 42fe5a50c3SAndreas Gohr function test_slcom4(){ 43fe5a50c3SAndreas Gohr $text = '#foo { 44fe5a50c3SAndreas Gohr background-image: url(http://foo.bar/baz.jpg); background-image: url(http://foo.bar/baz.jpg); // this is a comment 45fe5a50c3SAndreas Gohr }'; 46fe5a50c3SAndreas Gohr $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); 47fe5a50c3SAndreas Gohr } 48fe5a50c3SAndreas Gohr 49fe5a50c3SAndreas Gohr function test_slcom5(){ 50fe5a50c3SAndreas Gohr $text = '#foo { 51fe5a50c3SAndreas Gohr background-image: url(http://foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented 52fe5a50c3SAndreas Gohr }'; 53fe5a50c3SAndreas Gohr $this->assertEquals('#foo{background-image:url(http://foo.bar/baz.jpg);}', css_compress($text)); 54f8369d7dSTobias Sarnowski } 55f8369d7dSTobias Sarnowski 56e80146ebSAndreas Gohr function test_slcom6(){ 57e80146ebSAndreas Gohr $text = '#foo { 58e80146ebSAndreas Gohr background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is all commented 59e80146ebSAndreas Gohr }'; 60e80146ebSAndreas Gohr $this->assertEquals('#foo{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); 61e80146ebSAndreas Gohr } 62e80146ebSAndreas Gohr 63918a4468SAndreas Gohr function test_slcom7(){ 64918a4468SAndreas Gohr $text = '#foo a[href ^="https://"], #foo a[href ^=\'https://\'] { 65918a4468SAndreas Gohr background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is \'all\' "commented" 66918a4468SAndreas Gohr }'; 67918a4468SAndreas Gohr $this->assertEquals('#foo a[href ^="https://"],#foo a[href ^=\'https://\']{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); 68918a4468SAndreas Gohr } 69918a4468SAndreas Gohr 70918a4468SAndreas Gohr 71f8369d7dSTobias Sarnowski function test_hack(){ 72f8369d7dSTobias Sarnowski $text = '/* Mac IE will not see this and continue with inline-block */ 73f8369d7dSTobias Sarnowski /* \\*/ 74f8369d7dSTobias Sarnowski display: inline; 75f8369d7dSTobias Sarnowski /* */'; 76fe5a50c3SAndreas Gohr $this->assertEquals('/* \\*/display:inline;/* */', css_compress($text)); 77f8369d7dSTobias Sarnowski } 78f8369d7dSTobias Sarnowski 79f8369d7dSTobias Sarnowski function test_hack2(){ 80f8369d7dSTobias Sarnowski $text = '/* min-height hack for Internet Explorer http://www.cssplay.co.uk/boxes/minheight.html */ 81f8369d7dSTobias Sarnowski /*\\*/ 82f8369d7dSTobias Sarnowski * html .page { 83f8369d7dSTobias Sarnowski height: 450px; 84f8369d7dSTobias Sarnowski } 85f8369d7dSTobias Sarnowski /**/'; 86fe5a50c3SAndreas Gohr $this->assertEquals('/*\\*/* html .page{height:450px;}/**/', css_compress($text)); 87f8369d7dSTobias Sarnowski } 88f8369d7dSTobias Sarnowski 89f8369d7dSTobias Sarnowski function test_nl1(){ 90f8369d7dSTobias Sarnowski $text = "a{left:20px;\ntop:20px}"; 91fe5a50c3SAndreas Gohr $this->assertEquals('a{left:20px;top:20px}', css_compress($text)); 92f8369d7dSTobias Sarnowski } 93f8369d7dSTobias Sarnowski 94a467e020SAndreas Gohr function test_shortening() { 95a467e020SAndreas Gohr $input = array( 96a467e020SAndreas Gohr 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {', 97a467e020SAndreas Gohr 'margin: 1px 1px 1px 1px;', 98a467e020SAndreas Gohr 'padding: 1px 2px 1px 2px;', 99a467e020SAndreas Gohr 'margin: 1px 2px 3px 1px;', 100a467e020SAndreas Gohr 'padding: 1px 2px 3px 4px;', 101a467e020SAndreas Gohr 'margin: 00.00em 0em 01.00px 0em;', 102a467e020SAndreas Gohr 'padding: 0010em 0010.00em 00.00em 00.00100em;', 103a467e020SAndreas Gohr 'padding: 0010% 0010.00% 00.00% 00.00100xxx;', 104a467e020SAndreas Gohr 'padding: 0.0em .0em 0.em 00.00em;', 105a467e020SAndreas Gohr 'padding: 01.0em;', 106a467e020SAndreas Gohr 'color: #FFFFFF;', 107a467e020SAndreas Gohr 'color: #777777;', 108a467e020SAndreas Gohr 'color: #123456;', 109a467e020SAndreas Gohr 'border: 01.0em solid #ffffff;', 110a467e020SAndreas Gohr ); 111a467e020SAndreas Gohr 112a467e020SAndreas Gohr $expected = array( 113a467e020SAndreas Gohr 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{', 114a467e020SAndreas Gohr 'margin:1px;', 115a467e020SAndreas Gohr 'padding:1px 2px;', 116a467e020SAndreas Gohr 'margin:1px 2px 3px 1px;', 117a467e020SAndreas Gohr 'padding:1px 2px 3px 4px;', 118a467e020SAndreas Gohr 'margin:0 0 1px 0;', 119a467e020SAndreas Gohr 'padding:10em 10em 0 .001em;', 120a467e020SAndreas Gohr 'padding:10% 10% 0 00.00100xxx;', 121a467e020SAndreas Gohr 'padding:0;', 122a467e020SAndreas Gohr 'padding:1em;', 123a467e020SAndreas Gohr 'color:#FFF;', 124a467e020SAndreas Gohr 'color:#777;', 125a467e020SAndreas Gohr 'color:#123456;', 126a467e020SAndreas Gohr 'border:1em solid #fff;', 127a467e020SAndreas Gohr ); 128a467e020SAndreas Gohr 129a467e020SAndreas Gohr $input = array_map('css_compress', $input); 130a467e020SAndreas Gohr 131a467e020SAndreas Gohr $this->assertEquals($expected, $input); 132a467e020SAndreas Gohr } 133a467e020SAndreas Gohr 1340499ebedSAndreas Gohr function test_data() { 1350499ebedSAndreas Gohr $input = 'list-style-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; 1360499ebedSAndreas Gohr $expect = 'list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7);'; 137a9bd2f2fSPhy 138a9bd2f2fSPhy $this->assertEquals($expect, css_compress($input)); 139a9bd2f2fSPhy } 140a9bd2f2fSPhy 141a9bd2f2fSPhy function test_quotes() { 142*2f5645efSPhy $input = '/* "blockcomment" */ content: "/* STR2 : STR1 */ thisis : inquote"; STR1: 10px; STR2:"STR1"; STR3:\'STR1\';'; 143*2f5645efSPhy $expect = 'content:"/* STR2 : STR1 */ thisis : inquote";STR1:10px;STR2:"STR1";STR3:\'STR1\';'; 1440499ebedSAndreas Gohr 1450499ebedSAndreas Gohr $this->assertEquals($expect, css_compress($input)); 1460499ebedSAndreas Gohr } 1470499ebedSAndreas Gohr 148c52c9e2bSHenry Pan function test_escapedQuotes() { 149c52c9e2bSHenry Pan $inputEscapedQuote = 'content:"one quote visible: \\" "; foo: bar;//"'; 150c52c9e2bSHenry Pan $expectedOutput = 'content:"one quote visible: \\" ";foo:bar;'; 151c52c9e2bSHenry Pan 152c52c9e2bSHenry Pan $this->assertEquals($expectedOutput, css_compress($inputEscapedQuote)); 153c52c9e2bSHenry Pan } 154f8369d7dSTobias Sarnowski} 155f8369d7dSTobias Sarnowski 156f8369d7dSTobias Sarnowski//Setup VIM: ex: et ts=4 : 157