uri.test.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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('/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('/user', 'user'),
  55. array('/user/', 'user'),
  56. array('', '/'),
  57. array('/', '/'),
  58. array('//', '/'),
  59. array('/user', 'user'),
  60. array('/user/', 'user'),
  61. array('/user/profile', 'user/profile'),
  62. );
  63. }
  64. }