root/trunk/trax/test/ActionControllerTest.php

Revision 208, 11.1 KB (checked in by john, 6 years ago)

fixing test for new format

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