CommonHelperTest.php 4.1 KB

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