PageRenderTime 560ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/testapp/tests-jelix/jelix/utils/minifyHTMLResponsePluginTest.php

https://github.com/gmarrot/jelix
PHP | 145 lines | 105 code | 40 blank | 0 comment | 0 complexity | 3f09caeae871aa97679c3ba4f560defe MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. require_once(JELIX_LIB_PATH.'core/response/jResponseHtml.class.php');
  3. require_once(JELIX_LIB_PATH.'plugins/htmlresponse/minify/minify.htmlresponse.php');
  4. class testMinifyHTMLResponsePlugin extends minifyHTMLResponsePlugin {
  5. function testGenerateMinifyList($list, $exclude) {
  6. return $this->generateMinifyList($list, $exclude);
  7. }
  8. function setExcludeList( $excludeList, $excludeType ) {
  9. $this->$excludeType = $excludeList;
  10. }
  11. }
  12. class minifyHTMLResponsePluginTest extends jUnitTestCase
  13. {
  14. public static function setUpBeforeClass() {
  15. self::initJelixConfig();
  16. }
  17. function testStaticJs () {
  18. $minOptions = array( 'type' => 'text/javascript' );
  19. ksort($minOptions);
  20. $inputUrls = array('http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js' => $minOptions,
  21. 'http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js' => $minOptions);
  22. $htmlRep = new jResponseHtml();
  23. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  24. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeJS' );
  25. $this->assertEquals($inputUrls, $minifyList);
  26. }
  27. function testStaticCss () {
  28. $minOptions = array( 'media' => 'screen' , 'type' => 'text/css' );
  29. ksort($minOptions);
  30. $inputUrls = array('http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css' => $minOptions,
  31. 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/black-tie/jquery-ui.css' => $minOptions);
  32. $htmlRep = new jResponseHtml();
  33. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  34. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeCSS' );
  35. $this->assertEquals($inputUrls, $minifyList);
  36. }
  37. function testRelativeJs () {
  38. $minOptions = array( 'type' => 'text/javascript' );
  39. ksort($minOptions);
  40. $inputUrls = array('testminify/js/s1.js' => $minOptions,
  41. 'testminify/js/s2.js' => $minOptions);
  42. $htmlRep = new jResponseHtml();
  43. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  44. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeJS' );
  45. $this->assertEquals(array( 'minify.php?f=testminify/js/s1.js,testminify/js/s2.js' => $minOptions ), $minifyList);
  46. }
  47. function testRelativeCss () {
  48. $minOptions = array( 'media' => 'screen' , 'type' => 'text/css' );
  49. ksort($minOptions);
  50. $inputUrls = array('testminify/css/style1.css' => $minOptions,
  51. 'testminify/css/style2.css' => $minOptions);
  52. $htmlRep = new jResponseHtml();
  53. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  54. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeCSS' );
  55. $this->assertEquals(array( 'minify.php?f=testminify/css/style1.css,testminify/css/style2.css' => $minOptions ), $minifyList);
  56. }
  57. function testRelativeJsDifferentOptions () {
  58. $minOptions1 = array( 'type' => 'text/javascript', 'charset' => 'UTF-8' );
  59. ksort($minOptions1);
  60. $minOptions2 = array( 'type' => 'text/javascript', 'charset' => 'ISO-8859-1' );
  61. ksort($minOptions2);
  62. $inputUrls = array('testminify/js/s1.js' => $minOptions1,
  63. 'testminify/js/s2.js' => $minOptions2);
  64. $htmlRep = new jResponseHtml();
  65. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  66. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeJS' );
  67. $this->assertEquals(array( 'minify.php?f=testminify/js/s1.js' => $minOptions1,
  68. 'minify.php?f=testminify/js/s2.js' => $minOptions2 ), $minifyList);
  69. }
  70. function testRelativeCssDifferentOptions () {
  71. $minOptions1 = array( 'media' => 'screen' , 'type' => 'text/css' );
  72. ksort($minOptions1);
  73. $minOptions2 = array( 'media' => 'print' , 'type' => 'text/css' );
  74. ksort($minOptions2);
  75. $inputUrls = array('testminify/css/style1.css' => $minOptions1,
  76. 'testminify/css/style2.css' => $minOptions2);
  77. $htmlRep = new jResponseHtml();
  78. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  79. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeCSS' );
  80. $this->assertEquals(array( 'minify.php?f=testminify/css/style1.css' => $minOptions1,
  81. 'minify.php?f=testminify/css/style2.css' => $minOptions2 ), $minifyList);
  82. }
  83. function testExcludeJs () {
  84. $minOptions = array( 'type' => 'text/javascript' );
  85. ksort($minOptions);
  86. $inputUrls = array('testminify/js/s1.js' => $minOptions,
  87. 'testminify/js/s2.js' => $minOptions);
  88. $htmlRep = new jResponseHtml();
  89. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  90. $minifyHTMLResponsePluginTester->setExcludeList( array('testminify/js/s1.js'), 'excludeJS' );
  91. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeJS' );
  92. $this->assertEquals(array( 'testminify/js/s1.js' => $minOptions , 'minify.php?f=testminify/js/s2.js' => $minOptions ), $minifyList);
  93. }
  94. function testExcludeCss () {
  95. $minOptions = array( 'media' => 'screen' , 'type' => 'text/css' );
  96. ksort($minOptions);
  97. $inputUrls = array('testminify/css/style1.css' => $minOptions,
  98. 'testminify/css/style2.css' => $minOptions);
  99. $htmlRep = new jResponseHtml();
  100. $minifyHTMLResponsePluginTester = new testMinifyHTMLResponsePlugin( $htmlRep );
  101. $minifyHTMLResponsePluginTester->setExcludeList( array('testminify/css/style1.css'), 'excludeCSS' );
  102. $minifyList = $minifyHTMLResponsePluginTester->testGenerateMinifyList( $inputUrls, 'excludeCSS' );
  103. $this->assertEquals(array( 'testminify/css/style1.css' => $minOptions , 'minify.php?f=testminify/css/style2.css' => $minOptions ), $minifyList);
  104. }
  105. }