UriTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Codeception\Util;
  3. class UriTest extends \Codeception\Test\Unit
  4. {
  5. // tests
  6. public function testUrlMerge()
  7. {
  8. $this->assertEquals(
  9. 'http://codeception.com/quickstart',
  10. Uri::mergeUrls('http://codeception.com/hello', '/quickstart'),
  11. 'merge paths'
  12. );
  13. $this->assertEquals(
  14. 'http://codeception.com/hello/davert',
  15. Uri::mergeUrls('http://codeception.com/hello/world', 'davert'),
  16. 'merge relative urls'
  17. );
  18. $this->assertEquals(
  19. 'https://github.com/codeception/codeception',
  20. Uri::mergeUrls('http://codeception.com/hello/world', 'https://github.com/codeception/codeception'),
  21. 'merge absolute urls'
  22. );
  23. }
  24. /**
  25. * @Issue https://github.com/Codeception/Codeception/pull/2141
  26. */
  27. public function testMergingScheme()
  28. {
  29. $this->assertEquals(
  30. 'https://google.com/account/',
  31. Uri::mergeUrls('http://google.com/', 'https://google.com/account/')
  32. );
  33. $this->assertEquals('https://facebook.com/', Uri::mergeUrls('https://google.com/test/', '//facebook.com/'));
  34. $this->assertEquals(
  35. 'https://facebook.com/#anchor2',
  36. Uri::mergeUrls('https://google.com/?param=1#anchor', '//facebook.com/#anchor2')
  37. );
  38. }
  39. /**
  40. * @Issue https://github.com/Codeception/Codeception/pull/2841
  41. */
  42. public function testMergingPath()
  43. {
  44. $this->assertEquals('/form/?param=1#anchor', Uri::mergeUrls('/form/?param=1', '#anchor'));
  45. $this->assertEquals('/form/?param=1#anchor2', Uri::mergeUrls('/form/?param=1#anchor1', '#anchor2'));
  46. $this->assertEquals('/form/?param=2', Uri::mergeUrls('/form/?param=1#anchor', '?param=2'));
  47. $this->assertEquals('/page/', Uri::mergeUrls('/form/?param=1#anchor', '/page/'));
  48. }
  49. /**
  50. * @Issue https://github.com/Codeception/Codeception/pull/2499
  51. */
  52. public function testAppendAnchor()
  53. {
  54. $this->assertEquals(
  55. 'http://codeception.com/quickstart#anchor',
  56. Uri::appendPath('http://codeception.com/quickstart', '#anchor')
  57. );
  58. $this->assertEquals(
  59. 'http://codeception.com/quickstart#anchor',
  60. Uri::appendPath('http://codeception.com/quickstart#first', '#anchor')
  61. );
  62. }
  63. public function testAppendPath()
  64. {
  65. $this->assertEquals(
  66. 'http://codeception.com/quickstart/path',
  67. Uri::appendPath('http://codeception.com/quickstart', 'path')
  68. );
  69. $this->assertEquals(
  70. 'http://codeception.com/quickstart/path',
  71. Uri::appendPath('http://codeception.com/quickstart', '/path')
  72. );
  73. }
  74. public function testAppendEmptyPath()
  75. {
  76. $this->assertEquals(
  77. 'http://codeception.com/quickstart',
  78. Uri::appendPath('http://codeception.com/quickstart', '')
  79. );
  80. }
  81. public function testAppendPathRemovesQueryStringAndAnchor()
  82. {
  83. $this->assertEquals(
  84. 'http://codeception.com/quickstart',
  85. Uri::appendPath('http://codeception.com/quickstart?a=b#c', '')
  86. );
  87. }
  88. }