Skip to content

Commit

Permalink
Merge pull request #610 from kohana/3.3/test/use-dummy-controller-in-…
Browse files Browse the repository at this point in the history
…request-test

Use a dummy controller in RequestTest::test_param
  • Loading branch information
acoulton committed May 29, 2015
2 parents d41d2d0 + 86d3466 commit f7342d7
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions tests/kohana/RequestTest.php
Expand Up @@ -125,16 +125,15 @@ public function test_param()
{
$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);
Expand All @@ -150,17 +149,16 @@ public function test_param()
$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'));
}

/**
Expand Down Expand Up @@ -732,8 +730,17 @@ public function test_passes_client_params()

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

0 comments on commit f7342d7

Please sign in to comment.