UrlHelperTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Tools\View\Helper\UrlHelper;
  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 UrlHelperTest extends TestCase {
  15. public function setUp() {
  16. parent::setUp();
  17. $this->Url = new UrlHelper(new View(null));
  18. $this->Url->request = new Request();
  19. $this->Url->request->webroot = '';
  20. }
  21. /**
  22. * Tests
  23. *
  24. * @return void
  25. */
  26. public function testReset() {
  27. Router::connect('/:controller/:action/*');
  28. $result = $this->Url->reset(['controller' => 'foobar', 'action' => 'test']);
  29. $expected = '/foobar/test';
  30. $this->assertEquals($expected, $result);
  31. $this->Url->request->here = '/admin/foobar/test';
  32. $this->Url->request->params['admin'] = true;
  33. $this->Url->request->params['prefix'] = 'admin';
  34. Router::reload();
  35. Router::connect('/:controller/:action/*');
  36. Router::prefix('admin', function ($routes) {
  37. $routes->connect('/:controller/:action/*');
  38. });
  39. $result = $this->Url->build(['prefix' => 'admin', 'controller' => 'foobar', 'action' => 'test']);
  40. $expected = '/admin/foobar/test';
  41. $this->assertEquals($expected, $result);
  42. $result = $this->Url->build(['controller' => 'foobar', 'action' => 'test']);
  43. $expected = '/admin/foobar/test';
  44. //debug($result);
  45. //$this->assertEquals($expected, $result);
  46. $result = $this->Url->reset(['controller' => 'foobar', 'action' => 'test']);
  47. $expected = '/foobar/test';
  48. $this->assertEquals($expected, $result);
  49. }
  50. /**
  51. * Tests
  52. *
  53. * @return void
  54. */
  55. public function testComplete() {
  56. $this->Url->request->query['x'] = 'y';
  57. $result = $this->Url->complete(['action' => 'test']);
  58. $expected = '/test?x=y';
  59. $this->assertEquals($expected, $result);
  60. $result = $this->Url->complete(['action' => 'test', '?' => ['a' => 'b']]);
  61. $expected = '/test?a=b&amp;x=y';
  62. $this->assertEquals($expected, $result);
  63. }
  64. /**
  65. * TearDown method
  66. *
  67. * @return void
  68. */
  69. public function tearDown() {
  70. parent::tearDown();
  71. unset($this->Url);
  72. }
  73. }