HtmlHelperTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Tools\Test\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. /**
  18. * @return void
  19. */
  20. public function setUp() {
  21. parent::setUp();
  22. $this->Html = new HtmlHelper(new View(null));
  23. $this->Html->request = new Request();
  24. $this->Html->request->webroot = '';
  25. $this->Html->Url->request = $this->Html->request;
  26. }
  27. /**
  28. * HtmlHelperTest::testImageFromBlob()
  29. *
  30. * @return void
  31. */
  32. public function testImageFromBlob() {
  33. $folder = Plugin::path('Tools') . 'tests' . DS . 'test_files' . DS . 'img' . DS;
  34. $content = file_get_contents($folder . 'hotel.png');
  35. $is = $this->Html->imageFromBlob($content);
  36. $this->assertTrue(!empty($is));
  37. }
  38. /**
  39. * Tests
  40. *
  41. * @return void
  42. */
  43. public function testLinkReset() {
  44. Router::connect('/:controller/:action/*');
  45. $result = $this->Html->linkReset('Foo', ['controller' => 'foobar', 'action' => 'test']);
  46. $expected = '<a href="/foobar/test">Foo</a>';
  47. $this->assertEquals($expected, $result);
  48. $this->Html->request->here = '/admin/foobar/test';
  49. $this->Html->request->params['admin'] = true;
  50. $this->Html->request->params['prefix'] = 'admin';
  51. Router::reload();
  52. Router::connect('/:controller/:action/*');
  53. Router::prefix('admin', function ($routes) {
  54. $routes->connect('/:controller/:action/*');
  55. });
  56. $result = $this->Html->link('Foo', ['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
  57. $expected = '<a href="/admin/foobar/test">Foo</a>';
  58. $this->assertEquals($expected, $result);
  59. $result = $this->Html->link('Foo', ['controller' => 'foobar', 'action' => 'test']);
  60. $expected = '<a href="/admin/foobar/test">Foo</a>';
  61. //debug($result);
  62. //$this->assertEquals($expected, $result);
  63. $result = $this->Html->linkReset('Foo', ['controller' => 'foobar', 'action' => 'test']);
  64. $expected = '<a href="/foobar/test">Foo</a>';
  65. $this->assertEquals($expected, $result);
  66. }
  67. /**
  68. * Tests
  69. *
  70. * @return void
  71. */
  72. public function testLinkComplete() {
  73. $this->Html->request->query['x'] = 'y';
  74. $result = $this->Html->linkComplete('Foo', ['action' => 'test']);
  75. $expected = '<a href="/test?x=y">Foo</a>';
  76. $this->assertEquals($expected, $result);
  77. $result = $this->Html->linkComplete('Foo', ['action' => 'test', '?' => ['a' => 'b']]);
  78. $expected = '<a href="/test?a=b&amp;x=y">Foo</a>';
  79. $this->assertEquals($expected, $result);
  80. }
  81. /**
  82. * TearDown method
  83. *
  84. * @return void
  85. */
  86. public function tearDown() {
  87. parent::tearDown();
  88. unset($this->Html);
  89. }
  90. }