CommonHelperTest.php 3.8 KB

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