From fee4977deb3742e5e78b7153527574b57ad4c246 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 12 Jun 2011 11:30:20 -0400 Subject: [PATCH] Add ActionControllerTest --- testing/tests/http/action_controller_test.php | 62 +++++++++++++++++++ testing/tests/http/rest_action_test.php | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 testing/tests/http/action_controller_test.php diff --git a/testing/tests/http/action_controller_test.php b/testing/tests/http/action_controller_test.php new file mode 100644 index 0000000..5781b97 --- /dev/null +++ b/testing/tests/http/action_controller_test.php @@ -0,0 +1,62 @@ +. + +namespace hoplite\test; +use hoplite\http as http; + +require_once HOPLITE_ROOT . '/http/action_controller.php'; + +class TestActionController extends http\ActionController +{ + public $did_action = FALSE; + + public function ActionSomething(http\Request $request, http\Response $response) + { + $this->did_action = TRUE; + } +} + +class ActionControllerTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + $globals = array(); + $this->fixture = new TestActionController(new http\RootController($globals)); + $this->request = new http\Request(); + $this->response = new http\Response(); + } + + public function testDispatch() + { + $this->request->data['action'] = 'something'; + $this->fixture->Invoke($this->request, $this->response); + $this->assertTrue($this->fixture->did_action); + } + + public function testFailedDispatch() + { + $globals = array(); + $mock = $this->getMock('hoplite\http\RootController', array(), array($globals)); + $this->fixture = new TestActionController($mock); + + $mock->expects($this->once()) + ->method('Stop'); + + $this->request->data['action'] = 'nothing'; + $this->fixture->Invoke($this->request, $this->response); + $this->assertFalse($this->fixture->did_action); + } +} diff --git a/testing/tests/http/rest_action_test.php b/testing/tests/http/rest_action_test.php index cf39869..217fddf 100644 --- a/testing/tests/http/rest_action_test.php +++ b/testing/tests/http/rest_action_test.php @@ -1,5 +1,5 @@