uri.test.php 1.49 KB
Newer Older
1 2
<?php

3 4
use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;

5 6 7 8 9 10 11 12 13 14 15 16 17
class URITest extends PHPUnit_Framework_TestCase {

	/**
	 * Destroy the test environment.
	 */
	public function tearDown()
	{
		$_SERVER = array();
		URI::$uri = null;
		URI::$segments = array();
	}

	/**
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
	 * 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();
	}

	/**
33 34 35 36 37 38 39
	 * Test the URI::current method.
	 *
	 * @group laravel
	 * @dataProvider requestUriProvider
	 */
	public function testCorrectURIIsReturnedByCurrentMethod($uri, $expectation)
	{
40 41
		$this->setRequestUri($uri);

42 43 44 45 46 47 48 49 50 51
		$this->assertEquals($expectation, URI::current());
	}

	/**
	 * Test the URI::segment method.
	 *
	 * @group laravel
	 */
	public function testSegmentMethodReturnsAURISegment()
	{
52
		$this->setRequestUri('/user/profile');
53 54 55 56 57 58 59 60 61 62 63

		$this->assertEquals('user', URI::segment(1));
		$this->assertEquals('profile', URI::segment(2));
	}

	/**
	 * Data provider for the URI::current test.
	 */
	public function requestUriProvider()
	{
		return array(
64 65 66 67 68 69 70 71
			array('/user', 'user'),
			array('/user/', 'user'),
			array('', '/'),
			array('/', '/'),
			array('//', '/'),
			array('/user', 'user'),
			array('/user/', 'user'),
			array('/user/profile', 'user/profile'),
72 73 74 75
		);
	}

}