Navigation Menu

Skip to content

Commit

Permalink
Start adding tests for Request.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 20, 2012
1 parent 55660bb commit 622de78
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Cake/Network/Http/Request.php
Expand Up @@ -13,6 +13,8 @@
*/
namespace Cake\Network\Http;

use Cake\Error;

/**
* Implements methods for HTTP requests.
*/
Expand Down Expand Up @@ -48,6 +50,10 @@ public function method($method = null) {
if ($method === null) {
return $this->_method;
}
$name = __CLASS__ . '::METHOD_' . strtoupper($method);
if (!defined($name)) {
throw new Error\Exception(__d('cake_dev', 'Invalid method type'));
}
$this->_method = $method;
return $this;
}
Expand Down
90 changes: 90 additions & 0 deletions lib/Cake/Test/TestCase/Network/Http/RequestTest.php
@@ -0,0 +1,90 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Network\Http;

use Cake\Network\Http\Request;
use Cake\TestSuite\TestCase;

/**
* HTTP request test.
*/
class RequestTest extends TestCase {

/**
* test url method
*
* @return void
*/
public function testUrl() {
$request = new Request();
$this->assertSame($request, $request->url('http://example.com'));

$this->assertEquals('http://example.com', $request->url());
}

/**
* test method method.
*
* @return void
*/
public function testMethod() {
$request = new Request();
$this->assertSame($request, $request->method(Request::METHOD_GET));

$this->assertEquals(Request::METHOD_GET, $request->method());
}

/**
* test invalid method.
*
* @expectedException Cake\Error\Exception
* @return void
*/
public function testMethodInvalid() {
$request = new Request();
$request->method('set on fire');
}

/**
* test content method.
*
* @return void
*/
public function testContent() {
$data = '{"json":"data"}';
$request = new Request();
$this->assertSame($request, $request->content($data));

$this->assertEquals($data, $request->content());
}

/**
* test header method.
*
* @return void
*/
public function testHeader() {
$this->markTestIncomplete();
}

/**
* test headers being case insenstive
*
* @return void
*/
public function testHeaderInsensitive() {
$this->markTestIncomplete();
}

}

0 comments on commit 622de78

Please sign in to comment.