Introduce FrontController as the replacement for RootController.
[hoplite.git] / testing / tests / http / action_controller_test.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2011 Blue Static
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
16
17 namespace hoplite\test;
18 use hoplite\http as http;
19
20 require_once HOPLITE_ROOT . '/http/action_controller.php';
21
22 class TestActionController extends http\ActionController
23 {
24 public $did_action = FALSE;
25
26 public function ActionSomething(http\Request $request, http\Response $response)
27 {
28 $this->did_action = TRUE;
29 }
30 }
31
32 class ActionControllerTest extends \PHPUnit_Framework_TestCase
33 {
34 public function setUp()
35 {
36 $globals = array();
37 $this->fixture = new TestActionController(new http\FrontController($globals));
38 $this->request = new http\Request();
39 $this->response = new http\Response();
40 }
41
42 public function testDispatch()
43 {
44 $this->request->data['action'] = 'something';
45 $this->fixture->Invoke($this->request, $this->response);
46 $this->assertTrue($this->fixture->did_action);
47 }
48
49 public function testFailedDispatch()
50 {
51 $globals = array();
52 $mock = $this->getMock('hoplite\http\FrontController', array('SendResponse'), array($globals));
53 $this->fixture = new TestActionController($mock);
54
55 $mock->expects($this->once())
56 ->method('SendResponse');
57
58 $this->request->data['action'] = 'nothing';
59 $this->fixture->Invoke($this->request, $this->response);
60 $this->assertFalse($this->fixture->did_action);
61 }
62 }