UrlHelperTest.php 2.1 KB

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