1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
- class URITest extends PHPUnit_Framework_TestCase {
- /**
- * Destroy the test environment.
- */
- public function tearDown()
- {
- $_SERVER = array();
- URI::$uri = null;
- URI::$segments = array();
- }
- /**
- * Set this request's URI to the given string
- *
- * @param string $uri
- */
- protected function setRequestUri($uri)
- {
- // FIXME: Ugly hack, but old contents from previous requests seem to
- // trip up the Foundation class.
- $_FILES = array();
-
- $_SERVER['REQUEST_URI'] = $uri;
- Request::$foundation = RequestFoundation::createFromGlobals();
- }
- /**
- * Test the URI::current method.
- *
- * @group laravel
- * @dataProvider requestUriProvider
- */
- public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
- {
- $this->setRequestUri($uri);
- $this->assertEquals($expectation, URI::current());
- }
- /**
- * Test the URI::segment method.
- *
- * @group laravel
- */
- public function testSegmentMethodReturnsAURISegment()
- {
- $this->setRequestUri('http://localhost/index.php/user/profile');
- $this->assertEquals('user', URI::segment(1));
- $this->assertEquals('profile', URI::segment(2));
- }
- /**
- * Data provider for the URI::current test.
- */
- public function requestUriProvider()
- {
- return array(
- array('/index.php', '/'),
- array('/index.php/', '/'),
- array('http://localhost/user', 'user'),
- array('http://localhost/user/', 'user'),
- array('http://localhost/index.php', '/'),
- array('http://localhost/index.php/', '/'),
- array('http://localhost/index.php//', '/'),
- array('http://localhost/index.php/user', 'user'),
- array('http://localhost/index.php/user/', 'user'),
- array('http://localhost/index.php/user/profile', 'user/profile'),
- );
- }
- }
|