Kohana v3.3.5

This commit is contained in:
Deon George
2016-05-01 20:50:24 +10:00
parent 8888719653
commit 68c7f4f159
170 changed files with 4565 additions and 1176 deletions

View File

@@ -23,6 +23,7 @@ class Kohana_RequestTest extends Unittest_TestCase
// @codingStandardsIgnoreEnd
{
parent::setUp();
Kohana::$config->load('url')->set('trusted_hosts', array('localhost'));
$this->_initial_request = Request::$initial;
Request::$initial = new Request('/');
}
@@ -125,16 +126,15 @@ class Kohana_RequestTest extends Unittest_TestCase
{
$route = new Route('(<controller>(/<action>(/<id>)))');
$uri = 'foo/bar/id';
$uri = 'kohana_requesttest_dummy/foobar/some_id';
$request = Request::factory($uri, NULL, TRUE, array($route));
// We need to execute the request before it has matched a route
try
{
$request->execute();
}
catch (Exception $e) {}
$response = $request->execute();
$controller = new Controller_Kohana_RequestTest_Dummy($request, $response);
$this->assertSame(200, $response->status());
$this->assertSame($controller->get_expected_response(), $response->body());
$this->assertArrayHasKey('id', $request->param());
$this->assertArrayNotHasKey('foo', $request->param());
$this->assertEquals($request->uri(), $uri);
@@ -150,17 +150,16 @@ class Kohana_RequestTest extends Unittest_TestCase
$this->assertArrayNotHasKey('route', $params);
$route = new Route('(<uri>)', array('uri' => '.+'));
$route->defaults(array('controller' => 'foobar', 'action' => 'index'));
$request = Request::factory('foobar', NULL, TRUE, array($route));
$route->defaults(array('controller' => 'kohana_requesttest_dummy', 'action' => 'foobar'));
$request = Request::factory('kohana_requesttest_dummy', NULL, TRUE, array($route));
// We need to execute the request before it has matched a route
try
{
$request->execute();
}
catch (Exception $e) {}
$response = $request->execute();
$controller = new Controller_Kohana_RequestTest_Dummy($request, $response);
$this->assertSame('foobar', $request->param('uri'));
$this->assertSame(200, $response->status());
$this->assertSame($controller->get_expected_response(), $response->body());
$this->assertSame('kohana_requesttest_dummy', $request->param('uri'));
}
/**
@@ -270,6 +269,16 @@ class Kohana_RequestTest extends Unittest_TestCase
'http',
'http://localhost/kohana/foo'
),
array(
'http://www.google.com',
'http',
'http://www.google.com'
),
array(
'0',
'http',
'http://localhost/kohana/0'
)
);
}
@@ -296,7 +305,14 @@ class Kohana_RequestTest extends Unittest_TestCase
'Kohana::$index_file' => FALSE,
));
$this->assertEquals(Request::factory($uri)->url($protocol), $expected);
// issue #3967: inject the route so that we don't conflict with the application's default route
$route = new Route('(<controller>(/<action>))');
$route->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
$this->assertEquals(Request::factory($uri, array(), TRUE, array($route))->url($protocol), $expected);
}
/**
@@ -397,8 +413,15 @@ class Kohana_RequestTest extends Unittest_TestCase
*/
public function provider_uri_only_trimed_on_internal()
{
// issue #3967: inject the route so that we don't conflict with the application's default route
$route = new Route('(<controller>(/<action>))');
$route->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
$old_request = Request::$initial;
Request::$initial = new Request(TRUE);
Request::$initial = new Request(TRUE, array(), TRUE, array($route));
$result = array(
array(
@@ -417,6 +440,14 @@ class Kohana_RequestTest extends Unittest_TestCase
new Request('foo/bar'),
'foo/bar'
),
array(
new Request('/0'),
'0'
),
array(
new Request('0'),
'0'
),
array(
new Request('/'),
'/'
@@ -505,18 +536,18 @@ class Kohana_RequestTest extends Unittest_TestCase
{
$x_powered_by = 'Kohana Unit Test';
$content_type = 'application/x-www-form-urlencoded';
$request = new Request('foo/bar', array(), TRUE, array());
return array(
array(
$request = Request::factory('foo/bar')
->headers(array(
$request->headers(array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
)
),
array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
array(
'x-powered-by' => $x_powered_by,
'content-type' => $content_type
)
)
);
@@ -548,7 +579,6 @@ class Kohana_RequestTest extends Unittest_TestCase
{
return array(
array(
Request::factory(),
array(
'content-type' => 'application/x-www-form-urlencoded',
'x-test-header' => 'foo'
@@ -556,7 +586,6 @@ class Kohana_RequestTest extends Unittest_TestCase
"Content-Type: application/x-www-form-urlencoded\r\nX-Test-Header: foo\r\n\r\n"
),
array(
Request::factory(),
array(
'content-type' => 'application/json',
'x-powered-by' => 'kohana'
@@ -571,13 +600,13 @@ class Kohana_RequestTest extends Unittest_TestCase
*
* @dataProvider provider_headers_set
*
* @param Request request object
* @param array header(s) to set to the request object
* @param string expected http header
* @return void
*/
public function test_headers_set(Request $request, $headers, $expected)
public function test_headers_set($headers, $expected)
{
$request = new Request(TRUE, array(), TRUE, array());
$request->headers($headers);
$this->assertSame($expected, (string) $request->headers());
}
@@ -707,14 +736,83 @@ class Kohana_RequestTest extends Unittest_TestCase
$this->assertEquals($client->strict_redirect(), FALSE);
}
/**
* Tests correctness request content-length header after calling render
*/
public function test_content_length_after_render()
{
$request = Request::factory('https://example.org/post')
->client(new Kohana_RequestTest_Header_Spying_Request_Client_External)
->method(Request::POST)
->post(array('aaa' => 'bbb'));
$request->render();
$request->execute();
$headers = $request->client()->get_received_request_headers();
$this->assertEquals(strlen($request->body()), $headers['content-length']);
}
/**
* Tests correctness request content-length header after calling render
* and changing post
*/
public function test_content_length_after_changing_post()
{
$request = Request::factory('https://example.org/post')
->client(new Kohana_RequestTest_Header_Spying_Request_Client_External)
->method(Request::POST)
->post(array('aaa' => 'bbb'));
$request->render();
$request->post(array('one' => 'one', 'two' => 'two', 'three' => 'three'));
$request->execute();
$headers = $request->client()->get_received_request_headers();
$this->assertEquals(strlen($request->body()), $headers['content-length']);
}
} // End Kohana_RequestTest
/**
* A dummy Request_Client_External implementation, that spies on the headers
* of the request
*/
class Kohana_RequestTest_Header_Spying_Request_Client_External extends Request_Client_External
{
private $headers;
protected function _send_message(\Request $request, \Response $response)
{
$this->headers = $request->headers();
return $response;
}
public function get_received_request_headers()
{
return $this->headers;
}
}
class Controller_Kohana_RequestTest_Dummy extends Controller
{
public function action_index()
// hard coded dummy response
protected $dummy_response = "this is a dummy response";
public function action_foobar()
{
$this->response->body($this->dummy_response);
}
public function get_expected_response()
{
return $this->dummy_response;
}
} // End Kohana_RequestTest