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