uri.test.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class URITest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Destroy the test environment.
  5. */
  6. public function tearDown()
  7. {
  8. $_SERVER = array();
  9. URI::$uri = null;
  10. URI::$segments = array();
  11. }
  12. /**
  13. * Test the URI::current method.
  14. *
  15. * @group laravel
  16. * @dataProvider requestUriProvider
  17. */
  18. public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
  19. {
  20. $_SERVER['REQUEST_URI'] = $uri;
  21. $this->assertEquals($expectation, URI::current());
  22. }
  23. /**
  24. * Test the URI::segment method.
  25. *
  26. * @group laravel
  27. */
  28. public function testSegmentMethodReturnsAURISegment()
  29. {
  30. $_SERVER['REQUEST_URI'] = 'http://localhost/index.php/user/profile';
  31. $this->assertEquals('user', URI::segment(1));
  32. $this->assertEquals('profile', URI::segment(2));
  33. }
  34. /**
  35. * Data provider for the URI::current test.
  36. */
  37. public function requestUriProvider()
  38. {
  39. return array(
  40. array('/index.php', '/'),
  41. array('/index.php/', '/'),
  42. array('http://localhost/user', 'user'),
  43. array('http://localhost/user/', 'user'),
  44. array('http://localhost/index.php', '/'),
  45. array('http://localhost/index.php/', '/'),
  46. array('http://localhost/index.php//', '/'),
  47. array('http://localhost/index.php/user', 'user'),
  48. array('http://localhost/index.php/user/', 'user'),
  49. array('http://localhost/index.php/user/profile', 'user/profile'),
  50. );
  51. }
  52. }