HtmlExtHelperTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. App::uses('HtmlExtHelper', 'Tools.View/Helper');
  3. App::uses('View', 'View');
  4. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  5. class HtmlExtHelperTest extends MyCakeTestCase {
  6. public $Html;
  7. public function setUp() {
  8. parent::setUp();
  9. Configure::write('Routing.prefixes', array('admin'));
  10. Router::reload();
  11. $this->Html = new HtmlExtHelper(new View(null));
  12. }
  13. public function testObject() {
  14. $this->assertTrue(is_object($this->Html));
  15. $this->assertInstanceOf('HtmlExtHelper', $this->Html);
  16. }
  17. /**
  18. * HtmlExtHelperTest::testTime()
  19. *
  20. * @return void
  21. */
  22. public function testTime() {
  23. $time = time();
  24. $is = $this->Html->time($time);
  25. $time = CakeTime::i18nFormat($time, '%Y-%m-%d %T');
  26. $expected = '<time datetime="' . $time . '">' . $time . '</time>';
  27. $this->assertEquals($expected, $is);
  28. }
  29. /**
  30. * HtmlExtHelperTest::testLinkShim()
  31. *
  32. * @return void
  33. */
  34. public function testLinkShim() {
  35. $result = $this->Html->link('foo', '/bar', array('confirm' => 'Confirm me'));
  36. $expected = '<a href="/bar" onclick="if (confirm(&quot;Confirm me&quot;)) { return true; } return false;">foo</a>';
  37. $this->assertEquals($expected, $result);
  38. }
  39. /**
  40. * HtmlExtHelperTest::testImageFromBlob()
  41. *
  42. * @return void
  43. */
  44. public function testImageFromBlob() {
  45. $folder = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'img' . DS;
  46. $content = file_get_contents($folder . 'hotel.png');
  47. $is = $this->Html->imageFromBlob($content);
  48. $this->assertTrue(!empty($is));
  49. }
  50. /**
  51. * HtmlExtHelperTest::testDefaultUrl()
  52. *
  53. * @return void
  54. */
  55. public function testDefaultUrl() {
  56. $result = $this->Html->defaultUrl(array('controller' => 'foo'));
  57. $this->debug($result);
  58. $expected = '/foo';
  59. $this->assertEquals($expected, $result);
  60. }
  61. /**
  62. * HtmlExtHelperTest::testDefaultLink()
  63. *
  64. * @return void
  65. */
  66. public function testDefaultLink() {
  67. $result = $this->Html->defaultLink('Title', array('controller' => 'foo'));
  68. $this->debug($result);
  69. $expected = '<a href="/foo">Title</a>';
  70. $this->assertEquals($expected, $result);
  71. $result = $this->Html->defaultLink('Title', array('admin' => true, 'controller' => 'foo'));
  72. $this->debug($result);
  73. $expected = '<a href="/admin/foo" rel="nofollow">Title</a>';
  74. $this->assertEquals($expected, $result);
  75. }
  76. /**
  77. * HtmlExtHelperTest::testCompleteUrl()
  78. *
  79. * @return void
  80. */
  81. public function testCompleteUrl() {
  82. $result = $this->Html->completeUrl(array('controller' => 'foo'));
  83. $expected = '/foo';
  84. $this->assertEquals($expected, $result);
  85. $this->Html->request->query = array('x' => 'y');
  86. $result = $this->Html->completeUrl(array('controller' => 'foo'));
  87. $expected = '/foo?x=y';
  88. $this->assertEquals($expected, $result);
  89. }
  90. /**
  91. * HtmlExtHelperTest::testCompleteLink()
  92. *
  93. * @return void
  94. */
  95. public function testCompleteLink() {
  96. $result = $this->Html->completeLink('Title', array('controller' => 'foo'));
  97. $expected = '<a href="/foo">Title</a>';
  98. $this->assertEquals($expected, $result);
  99. $this->Html->request->query = array('x' => 'y');
  100. $result = $this->Html->completeLink('Title', array('controller' => 'foo'));
  101. $expected = '<a href="/foo?x=y">Title</a>';
  102. $this->assertEquals($expected, $result);
  103. }
  104. /**
  105. * HtmlExtHelperTest::testResetCrumbs()
  106. *
  107. * @return void
  108. */
  109. public function testResetCrumbs() {
  110. $this->Html->addCrumb('foo', '/bar');
  111. $result = $this->Html->getCrumbList();
  112. $expected = '<ul><li class="first"><a href="/bar">foo</a></li></ul>';
  113. $this->assertEquals($expected, $result);
  114. $this->Html->resetCrumbs();
  115. $result = $this->Html->getCrumbList();
  116. $this->assertNull($result);
  117. }
  118. }