HtmlHelperTest.php 2.7 KB

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