HtmlHelperTest.php 2.7 KB

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