uri.test.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
  3. class URITest extends PHPUnit_Framework_TestCase {
  4. /**
  5. * Destroy the test environment.
  6. */
  7. public function tearDown()
  8. {
  9. $_SERVER = array();
  10. URI::$uri = null;
  11. URI::$segments = array();
  12. }
  13. /**
  14. * Set this request's URI to the given string
  15. *
  16. * @param string $uri
  17. */
  18. protected function setRequestUri($uri)
  19. {
  20. // FIXME: Ugly hack, but old contents from previous requests seem to
  21. // trip up the Foundation class.
  22. $_FILES = array();
  23. $_SERVER['REQUEST_URI'] = $uri;
  24. Request::$foundation = RequestFoundation::createFromGlobals();
  25. }
  26. /**
  27. * Test the URI::current method.
  28. *
  29. * @group laravel
  30. * @dataProvider requestUriProvider
  31. */
  32. public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
  33. {
  34. $this->setRequestUri($uri);
  35. $this->assertEquals($expectation, URI::current());
  36. }
  37. /**
  38. * Test the URI::segment method.
  39. *
  40. * @group laravel
  41. */
  42. public function testSegmentMethodReturnsAURISegment()
  43. {
  44. $this->setRequestUri('http://localhost/index.php/user/profile');
  45. $this->assertEquals('user', URI::segment(1));
  46. $this->assertEquals('profile', URI::segment(2));
  47. }
  48. /**
  49. * Data provider for the URI::current test.
  50. */
  51. public function requestUriProvider()
  52. {
  53. return array(
  54. array('/index.php', '/'),
  55. array('/index.php/', '/'),
  56. array('http://localhost/user', 'user'),
  57. array('http://localhost/user/', 'user'),
  58. array('http://localhost/index.php', '/'),
  59. array('http://localhost/index.php/', '/'),
  60. array('http://localhost/index.php//', '/'),
  61. array('http://localhost/index.php/user', 'user'),
  62. array('http://localhost/index.php/user/', 'user'),
  63. array('http://localhost/index.php/user/profile', 'user/profile'),
  64. );
  65. }
  66. }