HtmlHelperTest.php 2.8 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->getView()->setRequest(new ServerRequest(['webroot' => '']));
  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 testLinkReset() {
  43. Router::connect('/:controller/:action/*');
  44. $result = $this->Html->linkReset('Foo', ['controller' => 'foobar', 'action' => 'test']);
  45. $expected = '<a href="/foobar/test">Foo</a>';
  46. $this->assertEquals($expected, $result);
  47. $request = $this->Html->getView()->getRequest();
  48. $request = $request->withAttribute('here', '/admin/foobar/test')
  49. ->withParam('admin', true)
  50. ->withParam('prefix', 'admin');
  51. $this->Html->getView()->setRequest($request);
  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->getView()->setRequest($this->Html->getView()->getRequest()->withQueryParams(['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. }