PageRenderTime 32ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/tests/Core/Url/Resolver/PathUrlResolverTest.php

http://github.com/concrete5/concrete5
PHP | 98 lines | 78 code | 20 blank | 0 comment | 1 complexity | 4e8adc3673a5f0430ffe0369d4602e53 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. require_once __DIR__ . "/ResolverTestCase.php";
  3. class PathUrlResolverTest extends ResolverTestCase
  4. {
  5. protected function setUp()
  6. {
  7. parent::setUp();
  8. $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
  9. $this->urlResolver = $app->make('Concrete\Core\Url\Resolver\PathUrlResolver');
  10. }
  11. public function testResolveSinglePath()
  12. {
  13. $path = '/some/path/to/something';
  14. $url = $this->canonicalUrlWithPath($path);
  15. $this->assertEquals($this->urlResolver->resolve(array($path)), (string) $url);
  16. }
  17. public function testSkipResolved()
  18. {
  19. $path = '/some/path/to/something';
  20. $resolved = uniqid();
  21. $this->assertEquals(
  22. $resolved,
  23. $this->urlResolver->resolve(array($path), $resolved));
  24. }
  25. public function testBadArguments()
  26. {
  27. $this->assertEquals(
  28. null,
  29. $this->urlResolver->resolve(array()));
  30. }
  31. public function testObjectPath()
  32. {
  33. $path = '/some/path/to/something';
  34. $this->assertEquals(
  35. $this->canonicalUrlWithPath($path),
  36. $this->urlResolver->resolve(
  37. array(new \Concrete\Core\Url\Components\Path($path))));
  38. }
  39. public function testUrlWithQuery()
  40. {
  41. $this->assertEquals(
  42. null,
  43. $this->urlResolver->resolve(array()));
  44. }
  45. public function testSegmentedPath()
  46. {
  47. $path = "/some/path/1/to/something";
  48. $segments = explode('/', trim($path, '/'));
  49. $this->assertEquals(
  50. $this->canonicalUrlWithPath($path),
  51. $this->urlResolver->resolve($segments));
  52. }
  53. public function testFragmentAndQuery()
  54. {
  55. $url = $this->urlResolver->resolve(array('/path/to/nothing/?query=true#fragment'));
  56. $this->assertEquals('fragment', $url->getFragment());
  57. $this->assertEquals('query=true', $url->getQuery());
  58. }
  59. public function testDispatcher()
  60. {
  61. $old_value = \Config::get('concrete.seo.url_rewriting');
  62. \Config::set('concrete.seo.url_rewriting', false);
  63. $canonical_path = $this->canonicalUrl->getPath();
  64. $url = $this->urlResolver->resolve(array('test'));
  65. $this->assertNotNull($url);
  66. if (!is_null($url)) {
  67. $dispatcher = DISPATCHER_FILENAME;
  68. $relative_path = $url->getPath()->getRelativePath($canonical_path);
  69. $this->assertEquals("{$dispatcher}/test", $relative_path);
  70. }
  71. \Config::set('concrete.seo.url_rewriting', $old_value);
  72. }
  73. public function testPassedUrl()
  74. {
  75. $url = $this->urlResolver->resolve(array('http://google.com/', 'testing'));
  76. $this->assertEquals('http://google.com/testing', (string) $url);
  77. }
  78. }