UrlHelperTest.php 2.0 KB

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