HtmlHelperTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Cake\Core\Configure;
  4. use Cake\Core\Plugin;
  5. use Cake\Network\Request;
  6. use Cake\Routing\Router;
  7. use Cake\View\View;
  8. use Tools\TestSuite\TestCase;
  9. use Tools\Utility\Time;
  10. use Tools\View\Helper\HtmlHelper;
  11. /**
  12. * Datetime Test Case
  13. */
  14. class HtmlHelperTest extends TestCase {
  15. /**
  16. * @var \Tools\View\Helper\HtmlHelper
  17. */
  18. protected $Html;
  19. public function setUp() {
  20. parent::setUp();
  21. $this->Html = new HtmlHelper(new View(null));
  22. $this->Html->request = new Request();
  23. $this->Html->request->webroot = '';
  24. $this->Html->Url->request = $this->Html->request;
  25. }
  26. /**
  27. * HtmlHelperTest::testImageFromBlob()
  28. *
  29. * @return void
  30. */
  31. public function testImageFromBlob() {
  32. $folder = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS;
  33. $content = file_get_contents($folder . 'hotel.png');
  34. $is = $this->Html->imageFromBlob($content);
  35. $this->assertTrue(!empty($is));
  36. }
  37. /**
  38. * Tests
  39. *
  40. * @return void
  41. */
  42. public function testResetLink() {
  43. Router::connect('/:controller/:action/*');
  44. $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
  45. $expected = '<a href="/foobar/test">Foo</a>';
  46. $this->assertEquals($expected, $result);
  47. $this->Html->request->here = '/admin/foobar/test';
  48. $this->Html->request->params['admin'] = true;
  49. $this->Html->request->params['prefix'] = 'admin';
  50. Router::reload();
  51. Router::connect('/:controller/:action/*');
  52. Router::prefix('admin', function ($routes) {
  53. $routes->connect('/:controller/:action/*');
  54. });
  55. $result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
  56. $expected = '<a href="/admin/foobar/test">Foo</a>';
  57. $this->assertEquals($expected, $result);
  58. $result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']);
  59. $expected = '<a href="/admin/foobar/test">Foo</a>';
  60. //debug($result);
  61. //$this->assertEquals($expected, $result);
  62. $result = $this->Html->resetLink('Foo', ['controller' => 'foobar', 'action' => 'test']);
  63. $expected = '<a href="/foobar/test">Foo</a>';
  64. $this->assertEquals($expected, $result);
  65. }
  66. /**
  67. * Tests
  68. *
  69. * @return void
  70. */
  71. public function testCompleteLink() {
  72. $this->Html->request->query['x'] = 'y';
  73. $result = $this->Html->completeLink('Foo', ['action' => 'test']);
  74. $expected = '<a href="/test?x=y">Foo</a>';
  75. $this->assertEquals($expected, $result);
  76. $result = $this->Html->completeLink('Foo', ['action' => 'test', '?' => ['a' => 'b']]);
  77. $expected = '<a href="/test?a=b&amp;x=y">Foo</a>';
  78. $this->assertEquals($expected, $result);
  79. }
  80. /**
  81. * TearDown method
  82. *
  83. * @return void
  84. */
  85. public function tearDown() {
  86. parent::tearDown();
  87. unset($this->Html);
  88. }
  89. }