InlineCssLibTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $html = 'チェック
  59. <style>
  60. div#container { margin: 1em auto; }
  61. h1 { font-weight: bold; font-size: 2em; }
  62. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  63. p.small { font-size: 70%; }
  64. </style>
  65. <div id="container">
  66. <h1>チェック</h1>
  67. <p>チェックインは15:00以降です。アーリーチェックインはリクエストにて</p>
  68. <p class="small">チェック\'foo\'</p>
  69. </div>
  70. bla';
  71. $res = $this->InlineCss->process($html);
  72. $this->debug($html);
  73. $this->debug($res);
  74. $this->assertTextStartsWith('チェック', $res);
  75. }
  76. }