InlineCssLibTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. App::uses('InlineCssLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class InlineCssLibTest extends MyCakeTestCase {
  5. public function setUp() {
  6. //Configure::write('InlineCss.engine', 'cssToInline');
  7. $this->InlineCss = new InlineCssLib();
  8. $res = App::import('Vendor', 'CssToInline', array('file' => 'css_to_inline_styles'.DS.'css_to_inline_styles.php'));
  9. $this->skipIf(!$res);
  10. parent::setUp();
  11. }
  12. public function testProcess() {
  13. $res = $this->InlineCss->process($this->testHtml);
  14. $this->debug($this->testHtml);
  15. $this->debug($res);
  16. }
  17. public function testProcessAlternativeEngine() {
  18. //TODO
  19. }
  20. public function testProcessPlainPiece() {
  21. $html = 'blabla
  22. <style>
  23. div#container { margin: 1em auto; }
  24. h1 { font-weight: bold; font-size: 2em; }
  25. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  26. p.small { font-size: 70%; }
  27. </style>
  28. <div id="container">
  29. <h1>Sample Page Title</h1>
  30. <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>
  31. <p class="small">Some small note!</p>
  32. </div>
  33. bla';
  34. $res = $this->InlineCss->process($html);
  35. $this->debug($html);
  36. $this->debug($res);
  37. }
  38. public $testHtml = '<!doctype html>
  39. <html lang="en">
  40. <head>
  41. <style>
  42. body { font: 11px/20px Georgia, "Times New Roman", Times, serif; }
  43. div#container { margin: 1em auto; }
  44. h1 { font-weight: bold; font-size: 2em; }
  45. p { margin-bottom: 1em; font-family: sans-serif; text-align: justify; }
  46. p.small { font-size: 70%; }
  47. </style>
  48. <title>Example</title>
  49. </head>
  50. <body>
  51. <div id="container">
  52. <h1>Sample Page Title</h1>
  53. <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>
  54. <p class="small">Some small note!</p>
  55. </div>
  56. </body>
  57. </html>';
  58. }