diff options
-rw-r--r-- | system/classes/request.php | 15 | ||||
-rw-r--r-- | tests/modules/database/driver/pdo/resultTest.php | 52 | ||||
-rw-r--r-- | tests/system/requestTest.php | 79 |
3 files changed, 96 insertions, 50 deletions
diff --git a/system/classes/request.php b/system/classes/request.php index 0fcfad0..4105901 100644 --- a/system/classes/request.php +++ b/system/classes/request.php @@ -131,29 +131,18 @@ class Request { } /** - * Initializes the Request and process the URI into a Route + * Creates a Request representing current HTTP request. * * @return Request Request * @access public * @static */ public static function create() { - return new Request(Route::match(static::getURI()), $_SERVER['REQUEST_METHOD'], $_POST, $_GET, $_SERVER); - } - - /** - * Gets URI of the current HTTP Request - * - * @return string URI of the HTTP Request - * @access public - * @static - */ - public static function getURI() { $uri = $_SERVER['REQUEST_URI']; $basepath=Config::get('core.basepath','/'); $uri = preg_replace("#^{$basepath}(?:index\.php/)?#i", '/', $uri); $url_parts = parse_url($uri); - return $url_parts['path']; + return new Request(Route::match($url_parts['path']), $_SERVER['REQUEST_METHOD'], $_POST, $_GET, $_SERVER); } }
\ No newline at end of file diff --git a/tests/modules/database/driver/pdo/resultTest.php b/tests/modules/database/driver/pdo/resultTest.php new file mode 100644 index 0000000..6cdbed4 --- /dev/null +++ b/tests/modules/database/driver/pdo/resultTest.php @@ -0,0 +1,52 @@ +<?php +/** + * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-06 at 20:48:50. + */ +class Result_PDO_DriverTest extends PHPUnit_Framework_TestCase +{ + /** + * @var Result_PDO_Driver + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + $this->object = new Result_PDO_Driver; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers Result_PDO_Driver::rewind + * @todo Implement testRewind(). + */ + public function testRewind() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers Result_PDO_Driver::next + * @todo Implement testNext(). + */ + public function testNext() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} diff --git a/tests/system/requestTest.php b/tests/system/requestTest.php index e40eb8c..2193533 100644 --- a/tests/system/requestTest.php +++ b/tests/system/requestTest.php @@ -1,4 +1,6 @@ <?php +require_once('/../../system/classes/request.php'); +require_once('/../../system/classes/route.php'); /** * Generated by PHPUnit_SkeletonGenerator on 2013-02-06 at 16:12:22. */ @@ -15,7 +17,8 @@ class requestTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->object = new Request; + $route=(object)array('params'=>array('controller'=>'test','action'=>'index','fairy_param'=>'Trixie')); + $this->object = new Request($route,'GET',array('fairy_post'=>'Trixie'),array('fairy_get'=>'Trixie'),array('fairy_server'=>'Trixie')); } /** @@ -32,10 +35,8 @@ class requestTest extends PHPUnit_Framework_TestCase */ public function testGet() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertEquals($this->object->get('fairy_get'), 'Trixie'); + $this->assertEquals($this->object->get('bogus','default'),'default'); } /** @@ -44,10 +45,8 @@ class requestTest extends PHPUnit_Framework_TestCase */ public function testPost() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertEquals($this->object->post('fairy_post'), 'Trixie'); + $this->assertEquals($this->object->post('bogus','default'),'default'); } /** @@ -56,10 +55,8 @@ class requestTest extends PHPUnit_Framework_TestCase */ public function testServer() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertEquals($this->object->server('fairy_server'), 'Trixie'); + $this->assertEquals($this->object->server('bogus','default'),'default'); } /** @@ -68,10 +65,8 @@ class requestTest extends PHPUnit_Framework_TestCase */ public function testParam() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->assertEquals($this->object->param('fairy_param'), 'Trixie'); + $this->assertEquals($this->object->param('bogus','default'),'default'); } /** @@ -80,33 +75,43 @@ class requestTest extends PHPUnit_Framework_TestCase */ public function testExecute() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->object->execute(); } - - /** - * @covers Request::create - * @todo Implement testCreate(). + + /** + * @covers Request::execute + * @todo Implement testExecute(). */ - public function testCreate() + public function testExecuteException() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $route=(object)array('params'=>array('controller'=>'bogus','action'=>'bogus')); + $req = new Request($route); + $except = false; + try{ + $req->execute(); + }catch (Exception $e) { + $except=true; + } + $this->assertEquals($except,true); } - /** - * @covers Request::getURI + * @covers Request::create * @todo Implement testGetURI(). */ - public function testGetURI() + public function testCreate() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + Route::add('default','/<controller>/<action>'); + Config::set('core.basepath','/tester/'); + $_SERVER['REQUEST_URI'] = "/tester/home/index"; + $_POST['post'] = "test"; + $_GET['get'] = "test"; + $_SERVER['REQUEST_METHOD'] = "POST"; + $req = Request::create(); + $this->assertEquals($req->get('get'), 'test'); + $this->assertEquals($req->post('post'), 'test'); + $this->assertEquals($req->server('REQUEST_METHOD'), 'POST'); + $this->assertEquals($req->method, 'POST'); + $this->assertEquals($req->param('controller'), 'home'); + $this->assertEquals($req->param('action'), 'index'); } } |