3 // Copyright (c) 2011 Blue Static
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.
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
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/>.
17 namespace hoplite\test
;
18 use hoplite\http
as http
;
20 require_once HOPLITE_ROOT
. '/http/rest_action.php';
21 require_once HOPLITE_ROOT
. '/http/root_controller.php';
22 require_once TEST_ROOT
. '/tests/http/fixtures.php';
24 class RestActionTest
extends \PHPUnit_Framework_TestCase
26 public function setUp()
29 $this->fixture
= new TestRestAction(new http\
RootController($globals));
30 $this->request
= new http\
Request();
31 $this->response
= new http\
Response();
34 public function RestExpectSingleTrue($true_var)
36 $vars = array('did_get', 'did_post', 'did_delete', 'did_put');
37 foreach ($vars as $var)
38 if ($var == $true_var)
39 $this->assertTrue($this->fixture
->$var);
41 $this->assertFalse($this->fixture
->$var);
44 public function testGet()
46 $this->request
->http_method
= 'GET';
47 $this->fixture
->Invoke($this->request
, $this->response
);
48 $this->RestExpectSingleTrue('did_get');
51 public function testPost()
53 $this->request
->http_method
= 'POST';
54 $this->fixture
->Invoke($this->request
, $this->response
);
55 $this->RestExpectSingleTrue('did_post');
58 public function testDelete()
60 $this->request
->http_method
= 'DELETE';
61 $this->fixture
->Invoke($this->request
, $this->response
);
62 $this->RestExpectSingleTrue('did_delete');
65 public function testPut()
67 $this->request
->http_method
= 'PUT';
68 $this->fixture
->Invoke($this->request
, $this->response
);
69 $this->RestExpectSingleTrue('did_put');
72 public function testInvalid()
75 $mock = $this->getMock('hoplite\http\RootController', array('Stop'), array($globals));
77 $this->fixture
= new TestRestAction($mock);
79 $mock->expects($this->once())
82 $this->request
->http_method
= 'HEAD';
83 $this->fixture
->Invoke($this->request
, $this->response
);
84 $this->RestExpectSingleTrue('___none___');
86 $this->assertEquals(http\ResponseCode
::METHOD_NOT_ALLOWED
, $this->response
->response_code
);