PHPonTraxTest
[ class tree: PHPonTraxTest ] [ index: PHPonTraxTest ] [ all elements ]

Source for file ActionControllerTest.php

Documentation is available at ActionControllerTest.php

  1. <?php
  2. /**
  3. * File for the ActionControllerTest class
  4. *
  5. * (PHP 5)
  6. *
  7. * @package PHPonTraxTest
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @copyright (c) Walter O. Haas 2006
  10. * @version $Id: ActionControllerTest.php 192 2006-03-27 22:02:53Z haas $
  11. * @author Walt Haas <haas@xmission.com>
  12. */
  13.  
  14. echo "testing ActionController\n";
  15. require_once 'testenv.php';
  16.  
  17. // root Trax files in the test directory
  18. define("TRAX_ROOT", dirname(__FILE__) . "/");
  19. define("TRAX_VIEWS_EXTENTION", "phtml");
  20. // you don't really need a 'haas' account to test,
  21. // the use of this prefix is purely syntactic
  22. define("TRAX_URL_PREFIX", "/~haas");
  23. $GLOBALS['TRAX_INCLUDES'] =
  24. array( "config" => "config",
  25. "controllers" => "controllers",
  26. "helpers" => "helpers",
  27. "layouts" => "layouts",
  28. "views" => "views");
  29.  
  30. // Call ActionControllerTest::main() if this source file is executed directly.
  31. if (!defined("PHPUnit2_MAIN_METHOD")) {
  32. define("PHPUnit2_MAIN_METHOD", "ActionControllerTest::main");
  33. }
  34.  
  35. require_once "PHPUnit2/Framework/TestCase.php";
  36. require_once "PHPUnit2/Framework/TestSuite.php";
  37.  
  38. // You may remove the following line when all tests have been implemented.
  39. require_once "PHPUnit2/Framework/IncompleteTestError.php";
  40.  
  41. require_once "router.php";
  42. require_once "inflector.php";
  43. require_once "trax_exceptions.php";
  44. require_once "action_controller.php";
  45.  
  46. /**
  47. * Test class for ActionController.
  48. * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:16:01.
  49. */
  50. class ActionControllerTest extends PHPUnit2_Framework_TestCase {
  51. /**
  52. * Runs the test methods of this class.
  53. *
  54. * @access public
  55. * @static
  56. */
  57. public static function main() {
  58. require_once "PHPUnit2/TextUI/TestRunner.php";
  59.  
  60. $suite = new PHPUnit2_Framework_TestSuite("ActionControllerTest");
  61. $result = PHPUnit2_TextUI_TestRunner::run($suite);
  62. }
  63.  
  64. /**
  65. * Sets up the fixture, for example, open a network connection.
  66. * This method is called before a test is executed.
  67. *
  68. * @access protected
  69. */
  70. protected function setUp() {
  71. }
  72.  
  73. /**
  74. * Tears down the fixture, for example, close a network connection.
  75. * This method is called after a test is executed.
  76. *
  77. * @access protected
  78. */
  79. protected function tearDown() {
  80. }
  81.  
  82. /**
  83. * @todo Implement test__construct().
  84. * The constructor calls load_router() to load
  85. * routes from config/routes.php
  86. */
  87. public function test__construct() {
  88. $ac = new ActionController;
  89. $this->assertTrue(is_object($ac->router));
  90. }
  91.  
  92. /**
  93. * Test recognize_route().
  94. * recognize_route() sets up a lot of private variables that we
  95. * don't have access to so we can't test it very thoroughly here
  96. */
  97. public function testRecognize_route() {
  98. // read routes from config/routes.php
  99. $ac = new ActionController;
  100. // this URL doesn't match any route
  101. $_SERVER['REDIRECT_URL'] = '/~haas/foo/bar';
  102. $this->assertFalse($ac->recognize_route());
  103. // this URL matches but the controller doesn't exist
  104. $_SERVER['REDIRECT_URL'] = '/~haas/nocontroller/foo/bar';
  105. $this->assertFalse($ac->recognize_route());
  106. // this URL matches and the controller is where it should be
  107. $_SERVER['REDIRECT_URL'] = '/~haas/products/bar';
  108. $this->assertTrue($ac->recognize_route());
  109. }
  110.  
  111. /**
  112. * Test raise() with default value of code
  113. */
  114. public function testRaise_default_code() {
  115. $ac = new ActionController;
  116. try {
  117. $ac->raise('text1','text2');
  118. }
  119. catch(Exception $e) {
  120. $this->assertTrue(is_a($e,'ActionControllerError'));
  121. $this->assertEquals('Error Message: text1',$e->getMessage());
  122. $this->assertEquals('Error Message: text1',$e->error_message);
  123. $this->assertEquals('text2',$e->error_heading);
  124. $this->assertEquals('404',$e->error_code);
  125. return;
  126. }
  127. $this->fail('raise() exception with default code not raised');
  128. }
  129.  
  130. /**
  131. * Test raise() with specified of code
  132. */
  133. public function testSpecified_code() {
  134. $ac = new ActionController;
  135. try {
  136. $ac->raise('text3','text4', 250);
  137. }
  138. catch(Exception $e) {
  139. $this->assertTrue(is_a($e,'ActionControllerError'));
  140. $this->assertEquals('Error Message: text3',$e->getMessage());
  141. $this->assertEquals('Error Message: text3',$e->error_message);
  142. $this->assertEquals('text4',$e->error_heading);
  143. $this->assertEquals(250,$e->error_code);
  144. return;
  145. }
  146. $this->fail('raise() exception with code 250 not raised');
  147. }
  148.  
  149. /**
  150. * Test process_route() with an unrecognized route
  151. */
  152. public function testProcess_route_unrecognized() {
  153. // read routes from config/routes.php
  154. $ac = new ActionController;
  155. // this URL doesn't match any route
  156. $_SERVER['REDIRECT_URL'] = '/~haas/foo/bar';
  157. try {
  158. $ac->process_route();
  159. }
  160. catch(Exception $e) {
  161. $this->assertTrue(is_a($e,'ActionControllerError'));
  162. $this->assertEquals('Error Message: Failed to load any'
  163. .' defined routes',$e->getMessage());
  164. $this->assertEquals('Error Message: Failed to load any'
  165. .' defined routes',$e->error_message);
  166. $this->assertEquals('Controller foo not found',
  167. $e->error_heading);
  168. $this->assertEquals('404',$e->error_code);
  169. return;
  170. }
  171. $this->fail('raise() exception with default code not raised');
  172. }
  173.  
  174. /**
  175. * Test process_route() with missing controller file
  176. */
  177. public function testProcess_route_missing_controller() {
  178. // read routes from config/routes.php
  179. $ac = new ActionController;
  180. // this URL matches default route
  181. $_SERVER['REDIRECT_URL'] = '/~haas/nocontroller/foo/bar';
  182. try {
  183. $ac->process_route();
  184. }
  185. catch(Exception $e) {
  186. $this->assertTrue(is_a($e,'ActionControllerError'));
  187. $this->assertEquals('Error Message: Failed to load any'
  188. .' defined routes',$e->getMessage());
  189. $this->assertEquals('Error Message: Failed to load any'
  190. .' defined routes',$e->error_message);
  191. $this->assertEquals('Controller nocontroller not found',
  192. $e->error_heading);
  193. $this->assertEquals('404',$e->error_code);
  194. return;
  195. }
  196. $this->fail('process_route() missing controller file'
  197. .' exception not raised');
  198. }
  199.  
  200. /**
  201. * Test process_route() with missing controller class
  202. */
  203. public function testProcess_route_missing_class() {
  204. // read routes from config/routes.php
  205. $ac = new ActionController;
  206. // this URL matches default route, but the controller
  207. // file doesn't have a Noclass class
  208. $_SERVER['REDIRECT_URL'] = '/~haas/noclass/foo/bar';
  209. try {
  210. $ac->process_route();
  211. }
  212. catch(Exception $e) {
  213. return;
  214. $this->assertTrue(is_a($e,'ActionControllerError'));
  215. $this->assertEquals('Error Message: Failed to instantiate'
  216. .' controller object "noclass"',
  217. $e->getMessage());
  218. $this->assertEquals('Error Message: Failed to instantiate'
  219. .' controller object "noclass"',
  220. $e->error_message);
  221. $this->assertEquals('ActionController error',
  222. $e->error_heading);
  223. $this->assertEquals('500',$e->error_code);
  224. return;
  225. }
  226. $this->fail('process_route() missing class exception not raised');
  227. }
  228.  
  229. /**
  230. * @todo Implement testProcess_route().
  231. */
  232. // public function testProcess_route() {
  233. // $ac = new ActionController;
  234. // // should invoke CatalogController
  235. // $_SERVER['REDIRECT_URL'] = '/~haas/products/bar';
  236. // $ac->process_route();
  237. // // Remove the following line when you implement this test.
  238. // throw new PHPUnit2_Framework_IncompleteTestError;
  239. // }
  240.  
  241. /**
  242. * FIXME: need controllers with layout undefined, layout=null,
  243. * layout=false, layout=file, layout=method
  244. * @todo Implement testDetermine_layout().
  245. */
  246. public function testDetermine_layout() {
  247. // Remove the following line when you implement this test.
  248. throw new PHPUnit2_Framework_IncompleteTestError;
  249. }
  250.  
  251. /**
  252. * @todo Implement test__set().
  253. */
  254. public function test__set() {
  255. // Remove the following line when you implement this test.
  256. throw new PHPUnit2_Framework_IncompleteTestError;
  257. }
  258.  
  259. /**
  260. * @todo Implement test__call().
  261. */
  262. public function test__call() {
  263. // Remove the following line when you implement this test.
  264. throw new PHPUnit2_Framework_IncompleteTestError;
  265. }
  266.  
  267. /**
  268. * @todo Implement testSet_paths().
  269. */
  270. public function testSet_paths() {
  271. // Remove the following line when you implement this test.
  272. throw new PHPUnit2_Framework_IncompleteTestError;
  273. }
  274.  
  275. /**
  276. * @todo Implement testExecute_before_filters().
  277. */
  278. public function testExecute_before_filters() {
  279. // Remove the following line when you implement this test.
  280. throw new PHPUnit2_Framework_IncompleteTestError;
  281. }
  282.  
  283. /**
  284. * @todo Implement testAdd_before_filter().
  285. */
  286. public function testAdd_before_filter() {
  287. // Remove the following line when you implement this test.
  288. throw new PHPUnit2_Framework_IncompleteTestError;
  289. }
  290.  
  291. /**
  292. * @todo Implement testExecute_after_filters().
  293. */
  294. public function testExecute_after_filters() {
  295. // Remove the following line when you implement this test.
  296. throw new PHPUnit2_Framework_IncompleteTestError;
  297. }
  298.  
  299. /**
  300. * @todo Implement testAdd_after_filter().
  301. */
  302. public function testAdd_after_filter() {
  303. // Remove the following line when you implement this test.
  304. throw new PHPUnit2_Framework_IncompleteTestError;
  305. }
  306.  
  307. /**
  308. * @todo Implement testAdd_helper().
  309. */
  310. public function testAdd_helper() {
  311. // Remove the following line when you implement this test.
  312. throw new PHPUnit2_Framework_IncompleteTestError;
  313. }
  314.  
  315. /**
  316. * @todo Implement testRender_partial().
  317. */
  318. public function testRender_partial() {
  319. // Remove the following line when you implement this test.
  320. throw new PHPUnit2_Framework_IncompleteTestError;
  321. }
  322.  
  323. /**
  324. * @todo Implement testRedirect_to().
  325. */
  326. public function testRedirect_to() {
  327. // Remove the following line when you implement this test.
  328. throw new PHPUnit2_Framework_IncompleteTestError;
  329. }
  330.  
  331. /**
  332. * @todo Implement testProcess_with_exception().
  333. */
  334. public function testProcess_with_exception() {
  335. // Remove the following line when you implement this test.
  336. throw new PHPUnit2_Framework_IncompleteTestError;
  337. }
  338. }
  339.  
  340. // Call ActionControllerTest::main() if this source file is executed directly.
  341. if (PHPUnit2_MAIN_METHOD == "ActionControllerTest::main") {
  342. ActionControllerTest::main();
  343. }
  344.  
  345. // -- set Emacs parameters --
  346. // Local variables:
  347. // tab-width: 4
  348. // c-basic-offset: 4
  349. // c-hanging-comment-ender-p: nil
  350. // indent-tabs-mode: nil
  351. // End:
  352. ?>

Documentation generated on Thu, 04 May 2006 19:46:58 -0600 by phpDocumentor 1.3.0RC4