<?php
/**
 * @package	    Joomla.UnitTest
 * @subpackage  Router
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license	    GNU General Public License version 2 or later; see LICENSE
 */

/**
 * Test class for JRouterAdministrator.
 * Generated by PHPUnit on 2012-07-26 at 20:39:38.
 */
class JRouterAdministratorTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Backup of the SERVER superglobal
	 *
	 * @var    array
	 * @since  3.1
	 */
	protected $backupServer;

	/**
	 * Class being tested
	 *
	 * @var    JRouterAdministrator
	 * @since  3.0
	 */
	protected $object;

	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @return  void
	 *
	 * @since   3.0
	 */
	protected function setUp()
	{
		// Import dependencies
		jimport('joomla.application.router');

		$this->backupServer = $_SERVER;

		$_SERVER['HTTP_HOST'] = 'example.com';
		$_SERVER['SCRIPT_NAME'] = '';

		$this->object = new JRouterAdministrator;
	}

	/**
	 * Tears down the fixture, for example, closes a network connection.
	 * This method is called after a test is executed.
	 *
	 * @return  void
	 *
	 * @since   3.1
	 */
	protected function tearDown()
	{
		$_SERVER = $this->backupServer;
	}

	/**
	 * Tests the parse method
	 *
	 * @return  void
	 *
	 * @since   3.0
	 */
	public function testParse()
	{
		$uri = JUri::getInstance('http://localhost');

		$this->assertThat(
			$this->object->parse($uri),
			$this->isType('array'),
			'JRouterAdministrator::parse() returns an empty array.'
		);
	}

	/**
	 * Tests the build method
	 *
	 * @return  void
	 *
	 * @since   3.1
	 */
	public function testBuild()
	{
		$uri = JUri::getInstance('http://localhost/joomla-cms/intro/to/joomla');

		$this->assertInstanceOf(
			'JUri',
			$this->object->build($uri),
			'JRouterAdministrator::build() returns an instance of JUri.'
		);

		$this->assertEquals(
			$uri->getPath(),
			'/joomla-cms/intro/to/joomla',
			'JRouterAdministrator::build() returns the path as provided.'
		);
	}
}
