InlineCssLibTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. App::uses('InlineCssLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class InlineCssLibTest extends MyCakeTestCase {
  5. public function setUp() {
  6. $this->InlineCss = new InlineCssLib();
  7. $res = App::import('Vendor', 'Tools.CssToInlineStyles', array('file' => 'CssToInlineStyles' . DS . 'CssToInlineStyles.php'));
  8. $this->skipIf(!$res);
  9. parent::setUp();
  10. }
  11. public function testProcess() {
  12. $res = $this->InlineCss->process($this->testHtml);
  13. $this->debug($this->testHtml);
  14. $this->debug($res);
  15. }
  16. public function testProcessAlternativeEngine() {
  17. //TODO
  18. }
  19. public function testProcessPlainPiece() {
  20. $html = 'blabla
  21. <style>
  22. div#container { margin: 1em auto; }
  23. h1 { font-weight: bold; font-size: 2em; }
  24. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  25. p.small { font-size: 70%; }
  26. </style>
  27. <div id="container">
  28. <h1>Sample Page Title</h1>
  29. <p>Bacon ipsum dolor sit amet in cow elit, in t-bone qui meatloaf corned beef aute ullamco minim. Consequat swine short ribs pastrami jerky.</p>
  30. <p class="small">Some small note!</p>
  31. </div>
  32. bla';
  33. $res = $this->InlineCss->process($html);
  34. $this->debug($html);
  35. $this->debug($res);
  36. }
  37. public $testHtml = '<!doctype html>
  38. <html lang="en">
  39. <head>
  40. <style>
  41. body { font: 11px/20px Georgia, "Times New Roman", Times, serif; }
  42. div#container { margin: 1em auto; }
  43. h1 { font-weight: bold; font-size: 2em; }
  44. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  45. p.small { font-size: 70%; }
  46. </style>
  47. <title>Example</title>
  48. </head>
  49. <body>
  50. <div id="container">
  51. <h1>Sample Page Title</h1>
  52. <p>Bacon ipsum dolor sit amet in cow elit, in t-bone qui meatloaf corned beef aute ullamco minim. Consequat swine short ribs pastrami jerky.</p>
  53. <p class="small">Some small note!</p>
  54. </div>
  55. </body>
  56. </html>';
  57. public function testProcessUtf8() {
  58. $this->skipIf(version_compare(PHP_VERSION, '5.4.0') < 0, 'UTF8 only works with PHP5.4 and above');
  59. $html = 'チェック
  60. <style>
  61. div#container { margin: 1em auto; }
  62. h1 { font-weight: bold; font-size: 2em; }
  63. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  64. p.small { font-size: 70%; }
  65. </style>
  66. <div id="container">
  67. <h1>チェック</h1>
  68. <p>チェックインは15:00以降です。アーリーチェックインはリクエストにて</p>
  69. <p class="small">チェック\'foo\'</p>
  70. </div>
  71. bla';
  72. $res = $this->InlineCss->process($html);
  73. $this->debug($html);
  74. $this->debug($res);
  75. $this->assertTextStartsWith('チェック', $res);
  76. }
  77. }