HtmlExtHelperTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * MyHelperTest::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. * MyHelperTest::testImageFromBlob()
  31. *
  32. * @return void
  33. */
  34. public function testImageFromBlob() {
  35. $folder = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'img' . DS;
  36. $content = file_get_contents($folder . 'hotel.png');
  37. $is = $this->Html->imageFromBlob($content);
  38. $this->assertTrue(!empty($is));
  39. }
  40. /**
  41. * HtmlExtHelperTest::testDefaultUrl()
  42. *
  43. * @return void
  44. */
  45. public function testDefaultUrl() {
  46. $result = $this->Html->defaultUrl(array('controller' => 'foo'));
  47. $this->debug($result);
  48. $expected = '/foo';
  49. $this->assertEquals($expected, $result);
  50. }
  51. /**
  52. * HtmlExtHelperTest::testDefaultLink()
  53. *
  54. * @return void
  55. */
  56. public function testDefaultLink() {
  57. $result = $this->Html->defaultLink('Title', array('controller' => 'foo'));
  58. $this->debug($result);
  59. $expected = '<a href="/foo">Title</a>';
  60. $this->assertEquals($expected, $result);
  61. $result = $this->Html->defaultLink('Title', array('admin' => true, 'controller' => 'foo'));
  62. $this->debug($result);
  63. $expected = '<a href="/admin/foo" rel="nofollow">Title</a>';
  64. $this->assertEquals($expected, $result);
  65. }
  66. /**
  67. * HtmlExtHelperTest::testCompleteUrl()
  68. *
  69. * @return void
  70. */
  71. public function testCompleteUrl() {
  72. $result = $this->Html->completeUrl(array('controller' => 'foo'));
  73. $expected = '/foo';
  74. $this->assertEquals($expected, $result);
  75. $this->Html->request->query = array('x' => 'y');
  76. $result = $this->Html->completeUrl(array('controller' => 'foo'));
  77. $expected = '/foo?x=y';
  78. $this->assertEquals($expected, $result);
  79. }
  80. /**
  81. * HtmlExtHelperTest::testCompleteLink()
  82. *
  83. * @return void
  84. */
  85. public function testCompleteLink() {
  86. $result = $this->Html->completeLink('Title', array('controller' => 'foo'));
  87. $expected = '<a href="/foo">Title</a>';
  88. $this->assertEquals($expected, $result);
  89. $this->Html->request->query = array('x' => 'y');
  90. $result = $this->Html->completeLink('Title', array('controller' => 'foo'));
  91. $expected = '<a href="/foo?x=y">Title</a>';
  92. $this->assertEquals($expected, $result);
  93. }
  94. /**
  95. * HtmlExtHelperTest::testResetCrumbs()
  96. *
  97. * @return void
  98. */
  99. public function testResetCrumbs() {
  100. $this->Html->addCrumb('foo', '/bar');
  101. $result = $this->Html->getCrumbList();
  102. $expected = '<ul><li class="first"><a href="/bar">foo</a></li></ul>';
  103. $this->assertEquals($expected, $result);
  104. $this->Html->resetCrumbs();
  105. $result = $this->Html->getCrumbList();
  106. $this->assertNull($result);
  107. }
  108. }