CommonHelperTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. App::uses('CommonHelper', 'Tools.View/Helper');
  3. App::uses('View', 'View');
  4. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  5. /**
  6. * 2012-11-23 ms
  7. */
  8. class CommonHelperTest extends MyCakeTestCase {
  9. public $Common;
  10. public function setUp() {
  11. parent::setUp();
  12. $this->Common = new CommonHelper(new View(null));
  13. }
  14. /**
  15. */
  16. public function testMetaCanonical() {
  17. $is = $this->Common->metaCanonical('/some/url/param1');
  18. $this->out(h($is));
  19. $this->assertEquals('<link rel="canonical" href="'.$this->Common->url('/some/url/param1').'" />', trim($is));
  20. }
  21. /**
  22. */
  23. public function testMetaAlternate() {
  24. $is = $this->Common->metaAlternate('/some/url/param1', 'de-de');
  25. $this->out(h($is));
  26. $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url/param1').'" rel="alternate" hreflang="de-de" />', trim($is));
  27. $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), 'de', true);
  28. $this->out(h($is));
  29. $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />', trim($is));
  30. $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de', 'de-ch'), true);
  31. $this->out(h($is));
  32. $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />'.PHP_EOL.'<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />', trim($is));
  33. $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de' => array('ch', 'at'), 'en'=>array('gb', 'us')), true);
  34. $this->out(h($is));
  35. $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />'.PHP_EOL.
  36. '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-at" />'.PHP_EOL.
  37. '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-gb" />'.PHP_EOL.
  38. '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-us" />', trim($is));
  39. }
  40. /**
  41. */
  42. public function testEsc() {
  43. $is = $this->Common->esc('Some Cool Text with <b>Html</b>');
  44. $this->assertEquals($is, 'Some Cool Text with &lt;b&gt;Html&lt;/b&gt;');
  45. $is = $this->Common->esc('Some Cool Text'.PHP_EOL.'with <b>Html</b>');
  46. $this->assertEquals($is, 'Some Cool Text<br />'.PHP_EOL.'with &lt;b&gt;Html&lt;/b&gt;');
  47. $is = $this->Common->esc('Some Cool'.PHP_EOL.' 2 indends and'.PHP_EOL.' 5 indends'.PHP_EOL.'YEAH');
  48. $this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.'&nbsp;&nbsp;2 indends and<br />'.PHP_EOL.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5 indends<br />'.PHP_EOL.'YEAH');
  49. $options = array('tabsToSpaces'=>2);
  50. $is = $this->Common->esc('Some Cool'.PHP_EOL.TB.'1 tab and'.PHP_EOL.TB.TB.'2 tabs'.PHP_EOL.'YEAH', $options);
  51. $this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.'&nbsp;&nbsp;1 tab and<br />'.PHP_EOL.'&nbsp;&nbsp;&nbsp;&nbsp;2 tabs<br />'.PHP_EOL.'YEAH');
  52. }
  53. /**
  54. * tearDown method
  55. *
  56. * @access public
  57. * @return void
  58. */
  59. public function tearDown() {
  60. parent::tearDown();
  61. unset($this->Common);
  62. }
  63. }