HtmlHelperTest.php 2.3 KB

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