CommonHelperTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. App::uses('CommonHelper', 'Tools.View/Helper');
  3. App::uses('HtmlHelper', 'Tools.View/Helper');
  4. App::uses('View', 'View');
  5. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  6. /**
  7. * CommonHelper tests
  8. */
  9. class CommonHelperTest extends MyCakeTestCase {
  10. public $Common;
  11. public function setUp() {
  12. parent::setUp();
  13. $View = new View(null);
  14. $this->Common = new CommonHelper($View);
  15. $this->Html = new CommonHelper($View);
  16. }
  17. /**
  18. * @return void
  19. */
  20. public function testMetaCanonical() {
  21. $is = $this->Common->metaCanonical('/some/url/param1');
  22. $this->assertEquals('<link href="' . $this->Html->url('/some/url/param1') . '" rel="canonical" />', trim($is));
  23. $is = $this->Common->metaCanonical('/some/url/param1', true);
  24. $this->assertEquals('<link href="' . $this->Html->url('/some/url/param1', true) . '" rel="canonical" />', trim($is));
  25. }
  26. /**
  27. * @return void
  28. */
  29. public function testMetaAlternate() {
  30. $is = $this->Common->metaAlternate('/some/url/param1', 'de-de', true);
  31. $this->out(h($is));
  32. $this->assertEquals('<link href="' . $this->Html->url('/some/url/param1', true) . '" rel="alternate" hreflang="de-de" />', trim($is));
  33. $is = $this->Common->metaAlternate(array('controller' => 'some', 'action' => 'url'), 'de', true);
  34. $this->out(h($is));
  35. $this->assertEquals('<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de" />', trim($is));
  36. $is = $this->Common->metaAlternate(array('controller' => 'some', 'action' => 'url'), array('de', 'de-ch'), true);
  37. $this->out(h($is));
  38. $this->assertEquals('<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de" />' . PHP_EOL . '<link href="' . FULL_BASE_URL . $this->Html->url('/some/url') . '" rel="alternate" hreflang="de-ch" />', trim($is));
  39. $is = $this->Common->metaAlternate(array('controller' => 'some', 'action' => 'url'), array('de' => array('ch', 'at'), 'en' => array('gb', 'us')), true);
  40. $this->out(h($is));
  41. $this->assertEquals('<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de-ch" />' . PHP_EOL .
  42. '<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de-at" />' . PHP_EOL .
  43. '<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="en-gb" />' . PHP_EOL .
  44. '<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="en-us" />', trim($is));
  45. }
  46. /**
  47. * @return void
  48. */
  49. public function testEsc() {
  50. $is = $this->Common->esc('Some Cool Text with <b>Html</b>');
  51. $this->assertEquals($is, 'Some Cool Text with &lt;b&gt;Html&lt;/b&gt;');
  52. $is = $this->Common->esc('Some Cool Text' . PHP_EOL . 'with <b>Html</b>');
  53. $this->assertEquals($is, 'Some Cool Text<br />' . PHP_EOL . 'with &lt;b&gt;Html&lt;/b&gt;');
  54. $is = $this->Common->esc('Some Cool' . PHP_EOL . ' 2 indends and' . PHP_EOL . ' 5 indends' . PHP_EOL . 'YEAH');
  55. $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');
  56. $options = array('tabsToSpaces' => 2);
  57. $is = $this->Common->esc('Some Cool' . PHP_EOL . TB . '1 tab and' . PHP_EOL . TB . TB . '2 tabs' . PHP_EOL . 'YEAH', $options);
  58. $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');
  59. }
  60. /**
  61. * CommonHelperTest::testAsp()
  62. *
  63. * @return void
  64. */
  65. public function testAsp() {
  66. $res = $this->Common->asp('House', 2, true);
  67. $expected = __('Houses');
  68. $this->assertEquals($expected, $res);
  69. $res = $this->Common->asp('House', 1, true);
  70. $expected = __('House');
  71. $this->assertEquals($expected, $res);
  72. }
  73. /**
  74. * CommonHelperTest::testSp()
  75. *
  76. * @return void
  77. */
  78. public function testSp() {
  79. $res = $this->Common->sp('House', 'Houses', 0, true);
  80. $expected = __('Houses');
  81. $this->assertEquals($expected, $res);
  82. $res = $this->Common->sp('House', 'Houses', 2, true);
  83. $this->assertEquals($expected, $res);
  84. $res = $this->Common->sp('House', 'Houses', 1, true);
  85. $expected = __('House');
  86. $this->assertEquals($expected, $res);
  87. $res = $this->Common->sp('House', 'Houses', 1);
  88. $expected = 'House';
  89. $this->assertEquals($expected, $res);
  90. }
  91. /**
  92. * TearDown method
  93. *
  94. * @return void
  95. */
  96. public function tearDown() {
  97. parent::tearDown();
  98. unset($this->Common);
  99. }
  100. }