<?php

class RouterTest extends PHPUnit_Framework_TestCase
{
	public function testBaseLinker()
	{
		list($server, $mysqlConfig) = require("test/config.php");
		$dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
		$dbh->exec("DROP DATABASE ".$mysqlConfig[4][1]);
		$dbh->exec("CREATE DATABASE ".$mysqlConfig[4][1]);
		\Entity\ModelBase::init($mysqlConfig);
		$context = new \Tools\Context($server, false);
		\Entity\ModelBase::setup();
		$context->serve();
		$router = $context->router;

		$this->assertNotNull($router);
		$this->assertEquals("http://my.host.name/", $router->rootUrl);
		$this->assertEquals("http://my.host.name/content/modules/", $router->modulesUrl);
		$this->assertEquals("http://my.host.name/content/theme/", $router->themesUrl);
		try {
			$router->getFail;
			$this->fail("Expected exception");
		}
		catch (\Exception $e) {}
	}

	/**
	 * @runInSeparateProcess
	**/
	public function testRedirect()
	{
		list($server, $mysqlConfig) = require("test/config.php");
		$dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
		$dbh->exec("DROP DATABASE ".$mysqlConfig[4][1]);
		$dbh->exec("CREATE DATABASE ".$mysqlConfig[4][1]);
		\Entity\ModelBase::init($mysqlConfig);
		$context = new \Tools\Context($server, false);
		\Entity\ModelBase::setup();
		\Entity\Config::setConfig(null, "siteUrl", "my.host2.name");
		$context = new \Tools\Context($server, false);
		$context->serve();
		$this->fail("Expected redirect then die");
	}

	public function testLinker()
	{
		/*
		list($server, $mysqlConfig) = require("test/config.php");
		$dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
		$dbh->exec("DROP DATABASE ".$mysqlConfig[4][1]);
		$dbh->exec("CREATE DATABASE ".$mysqlConfig[4][1]);
		\Entity\ModelBase::init($mysqlConfig);
		$context = new \Tools\Context($server, false);
		\Entity\ModelBase::setup();
		$context->serve();
		$router = $context->router;
		*/
	}
}

