Changeset 163 for trunk/trax/test

Show
Ignore:
Timestamp:
03/07/06 09:44:21 (6 years ago)
Author:
haas
Message:

partial doc, test of ActionController?

Location:
trunk/trax/test
Files:
9 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/test/ActionControllerErrorTest.php

    r159 r163  
    6464    } 
    6565 
     66 
    6667    /** 
    67      *  Empty test to prevent failure 
     68     *  Test exception with default value of code 
    6869     */ 
    69     public function testEmpty() { 
     70    public function testDefault_code() { 
     71        try { 
     72            throw new ActionControllerError('text1','text2'); 
     73        } 
     74        catch(Exception $e) { 
     75            $this->assertTrue(is_a($e,'ActionControllerError')); 
     76            $this->assertEquals('text1',$e->getMessage()); 
     77            $this->assertEquals('text1',$e->error_message); 
     78            $this->assertEquals('text2',$e->error_heading); 
     79            $this->assertEquals('500',$e->error_code); 
     80            return; 
     81        } 
     82        $this->fail('ActionControllerError exception with default code not raised'); 
    7083    } 
     84 
     85    /** 
     86     *  Test exception with specified of code 
     87     */ 
     88    public function testSpecified_code() { 
     89        try { 
     90            throw new ActionControllerError('text3','text4', 250); 
     91        } 
     92        catch(Exception $e) { 
     93            $this->assertTrue(is_a($e,'ActionControllerError')); 
     94            $this->assertEquals('text3',$e->getMessage()); 
     95            $this->assertEquals('text3',$e->error_message); 
     96            $this->assertEquals('text4',$e->error_heading); 
     97            $this->assertEquals(250,$e->error_code); 
     98            return; 
     99        } 
     100        $this->fail('ActionControllerError exception with code 250 not raised'); 
     101    } 
     102 
    71103} 
    72104 
  • trunk/trax/test/ActionControllerTest.php

    r159 r163  
    1414 
    1515echo "testing ActionController\n"; 
     16//  root Trax files in the test directory 
     17define("TRAX_ROOT", dirname(__FILE__) . "/"); 
     18define("TRAX_LIB_ROOT", "../vendor/trax"); 
     19define("TRAX_VIEWS_EXTENTION",  "phtml"); 
     20//  you don't really need a 'haas' account to test, 
     21//  the use of this prefix is purely syntactic 
     22define("TRAX_URL_PREFIX", "~haas"); 
     23$GLOBALS['TRAX_INCLUDES'] = 
     24    array( "config"      => "config", 
     25           "controllers" => "controllers", 
     26           "helpers"     => "helpers", 
     27           "layouts"     => "layouts", 
     28           "views"       => "views"); 
    1629 
    1730// Call ActionControllerTest::main() if this source file is executed directly. 
     
    2639require_once "PHPUnit2/Framework/IncompleteTestError.php"; 
    2740 
     41require_once "../vendor/trax/router.php"; 
     42require_once "../vendor/trax/inflector.php"; 
     43require_once "../vendor/trax/trax_exceptions.php"; 
    2844require_once "../vendor/trax/action_controller.php"; 
     45require_once "../app/controllers/application.php"; 
    2946 
    3047/** 
     
    6582 
    6683    /** 
     84     * @todo Implement test__construct(). 
     85     *  The constructor calls load_router() to load 
     86     *  routes from config/routes.php 
     87     */ 
     88    public function test__construct() { 
     89        $ac = new ActionController; 
     90        $this->assertTrue(is_object($ac->router)); 
     91    } 
     92 
     93    /** 
     94     *  Test recognize_route(). 
     95     *  recognize_route() sets up a lot of private variables that we 
     96     *  don't have access to so we can't test it very thoroughly here 
     97     */ 
     98    public function testRecognize_route() { 
     99        //  read routes from config/routes.php 
     100        $ac = new ActionController; 
     101        //  this URL doesn't match any route 
     102        $_SERVER['REDIRECT_URL'] = '~haas/foo/bar'; 
     103        $this->assertFalse($ac->recognize_route()); 
     104        //  this URL matches but the controller doesn't exist 
     105        $_SERVER['REDIRECT_URL'] = '~haas/nocontroller/foo/bar'; 
     106        $this->assertFalse($ac->recognize_route()); 
     107        //  this URL matches and the controller is where it should be 
     108        $_SERVER['REDIRECT_URL'] = '~haas/products/bar'; 
     109        $this->assertTrue($ac->recognize_route()); 
     110    } 
     111 
     112    /** 
     113     *  Test raise() with default value of code 
     114     */ 
     115    public function testRaise_default_code() { 
     116        $ac = new ActionController; 
     117        try { 
     118            $ac->raise('text1','text2'); 
     119        } 
     120        catch(Exception $e) { 
     121            $this->assertTrue(is_a($e,'ActionControllerError')); 
     122            $this->assertEquals('Error Message: text1',$e->getMessage()); 
     123            $this->assertEquals('Error Message: text1',$e->error_message); 
     124            $this->assertEquals('text2',$e->error_heading); 
     125            $this->assertEquals('404',$e->error_code); 
     126            return; 
     127        } 
     128        $this->fail('raise() exception with default code not raised'); 
     129    } 
     130 
     131    /** 
     132     *  Test raise() with specified of code 
     133     */ 
     134    public function testSpecified_code() { 
     135        $ac = new ActionController; 
     136        try { 
     137            $ac->raise('text3','text4', 250); 
     138        } 
     139        catch(Exception $e) { 
     140            $this->assertTrue(is_a($e,'ActionControllerError')); 
     141            $this->assertEquals('Error Message: text3',$e->getMessage()); 
     142            $this->assertEquals('Error Message: text3',$e->error_message); 
     143            $this->assertEquals('text4',$e->error_heading); 
     144            $this->assertEquals(250,$e->error_code); 
     145            return; 
     146        } 
     147        $this->fail('raise() exception with code 250 not raised'); 
     148    } 
     149 
     150    /** 
     151     *  Test process_route() with an unrecognized route 
     152     */ 
     153    public function testProcess_route_unrecognized() { 
     154        //  read routes from config/routes.php 
     155        $ac = new ActionController; 
     156        //  this URL doesn't match any route 
     157        $_SERVER['REDIRECT_URL'] = '~haas/foo/bar'; 
     158        try { 
     159            $ac->process_route(); 
     160        } 
     161        catch(Exception $e) { 
     162            $this->assertTrue(is_a($e,'ActionControllerError')); 
     163            $this->assertEquals('Error Message: Failed to load any' 
     164                                .' defined routes',$e->getMessage()); 
     165            $this->assertEquals('Error Message: Failed to load any' 
     166                                .' defined routes',$e->error_message); 
     167            $this->assertEquals('Controller foo not found', 
     168                                $e->error_heading); 
     169            $this->assertEquals('404',$e->error_code); 
     170            return; 
     171        } 
     172        $this->fail('raise() exception with default code not raised'); 
     173    } 
     174 
     175    /** 
     176     *  Test process_route() with missing controller file 
     177     */ 
     178    public function testProcess_route_missing_controller() { 
     179        //  read routes from config/routes.php 
     180        $ac = new ActionController; 
     181        //  this URL matches default route 
     182        $_SERVER['REDIRECT_URL'] = '~haas/nocontroller/foo/bar'; 
     183        try { 
     184            $ac->process_route(); 
     185        } 
     186        catch(Exception $e) { 
     187            $this->assertTrue(is_a($e,'ActionControllerError')); 
     188            $this->assertEquals('Error Message: Failed to load any' 
     189                               .' defined routes',$e->getMessage()); 
     190            $this->assertEquals('Error Message: Failed to load any' 
     191                               .' defined routes',$e->error_message); 
     192            $this->assertEquals('Controller nocontroller not found', 
     193                                $e->error_heading); 
     194            $this->assertEquals('404',$e->error_code); 
     195            return; 
     196        } 
     197        $this->fail('process_route() missing controller file' 
     198                    .' exception not raised'); 
     199    } 
     200 
     201    /** 
     202     *  Test process_route() with missing controller class 
     203     */ 
     204    public function testProcess_route_missing_class() { 
     205        //  read routes from config/routes.php 
     206        $ac = new ActionController; 
     207        //  this URL matches default route, but the controller 
     208        //  file doesn't have a Noclass class 
     209        $_SERVER['REDIRECT_URL'] = '~haas/noclass/foo/bar'; 
     210        try { 
     211            $ac->process_route(); 
     212        } 
     213        catch(Exception $e) { 
     214            return; 
     215            $this->assertTrue(is_a($e,'ActionControllerError')); 
     216            $this->assertEquals('Error Message: Failed to instantiate' 
     217                               .' controller object "noclass"', 
     218                                $e->getMessage()); 
     219            $this->assertEquals('Error Message: Failed to instantiate' 
     220                               .' controller object "noclass"', 
     221                                $e->error_message); 
     222            $this->assertEquals('ActionController error', 
     223                                $e->error_heading); 
     224            $this->assertEquals('500',$e->error_code); 
     225            return; 
     226        } 
     227        $this->fail('process_route() missing class exception not raised'); 
     228    } 
     229 
     230    /** 
     231     * @todo Implement testProcess_route(). 
     232     */ 
     233//    public function testProcess_route() { 
     234//        $ac = new ActionController; 
     235//        //  should invoke CatalogController 
     236//        $_SERVER['REDIRECT_URL'] = '~haas/products/bar'; 
     237//        $ac->process_route(); 
     238//        // Remove the following line when you implement this test. 
     239//        throw new PHPUnit2_Framework_IncompleteTestError; 
     240//    } 
     241 
     242    /** 
     243     *  FIXME: need controllers with layout undefined, layout=null, 
     244     *  layout=false, layout=file, layout=method 
     245     * @todo Implement testDetermine_layout(). 
     246     */ 
     247    public function testDetermine_layout() { 
     248        // Remove the following line when you implement this test. 
     249        throw new PHPUnit2_Framework_IncompleteTestError; 
     250    } 
     251 
     252    /** 
    67253     * @todo Implement test__set(). 
    68254     */ 
     
    81267 
    82268    /** 
    83      * @todo Implement testLoad_router(). 
    84      */ 
    85     public function testLoad_router() { 
    86         // Remove the following line when you implement this test. 
    87         throw new PHPUnit2_Framework_IncompleteTestError; 
    88     } 
    89  
    90     /** 
    91      * @todo Implement testRecognize_route(). 
    92      */ 
    93     public function testRecognize_route() { 
    94         // Remove the following line when you implement this test. 
    95         throw new PHPUnit2_Framework_IncompleteTestError; 
    96     } 
    97  
    98     /** 
    99      * @todo Implement testProcess_route(). 
    100      */ 
    101     public function testProcess_route() { 
    102         // Remove the following line when you implement this test. 
    103         throw new PHPUnit2_Framework_IncompleteTestError; 
    104     } 
    105  
    106     /** 
    107269     * @todo Implement testSet_paths(). 
    108270     */ 
     
    161323 
    162324    /** 
    163      * @todo Implement testDetermine_layout(). 
    164      */ 
    165     public function testDetermine_layout() { 
    166         // Remove the following line when you implement this test. 
    167         throw new PHPUnit2_Framework_IncompleteTestError; 
    168     } 
    169  
    170     /** 
    171325     * @todo Implement testRedirect_to(). 
    172326     */ 
    173327    public function testRedirect_to() { 
    174         // Remove the following line when you implement this test. 
    175         throw new PHPUnit2_Framework_IncompleteTestError; 
    176     } 
    177  
    178     /** 
    179      * @todo Implement testRaise(). 
    180      */ 
    181     public function testRaise() { 
    182328        // Remove the following line when you implement this test. 
    183329        throw new PHPUnit2_Framework_IncompleteTestError; 
  • trunk/trax/test/ActiveRecordErrorTest.php

    r159 r163  
    6464    } 
    6565 
     66 
    6667    /** 
    67      *  Empty test to prevent failure 
     68     *  Test exception with default value of code 
    6869     */ 
    69     public function testEmpty() { 
     70    public function testDefault_code() { 
     71        try { 
     72            throw new ActiveRecordError('text1','text2'); 
     73        } 
     74        catch(Exception $e) { 
     75            $this->assertTrue(is_a($e,'ActiveRecordError')); 
     76            $this->assertEquals('text1',$e->getMessage()); 
     77            $this->assertEquals('text1',$e->error_message); 
     78            $this->assertEquals('text2',$e->error_heading); 
     79            $this->assertEquals('500',$e->error_code); 
     80            return; 
     81        } 
     82        $this->fail('ActiveRecordErrorError exception with default code not raised'); 
    7083    } 
     84 
     85    /** 
     86     *  Test exception with specified of code 
     87     */ 
     88    public function testSpecified_code() { 
     89        try { 
     90            throw new ActiveRecordError('text3','text4', 250); 
     91        } 
     92        catch(Exception $e) { 
     93            $this->assertTrue(is_a($e,'ActiveRecordError')); 
     94            $this->assertEquals('text3',$e->getMessage()); 
     95            $this->assertEquals('text3',$e->error_message); 
     96            $this->assertEquals('text4',$e->error_heading); 
     97            $this->assertEquals(250,$e->error_code); 
     98            return; 
     99        } 
     100        $this->fail('ActiveRecordErrorError exception with code 250 not raised'); 
     101    } 
     102 
    71103} 
    72104 
  • trunk/trax/test/TraxErrorTest.php

    r159 r163  
    6565 
    6666    /** 
    67      *  Empty test to prevent failure 
     67     *  Test exception with default value of code 
    6868     */ 
    69     public function testEmpty() { 
     69    public function testDefault_code() { 
     70        try { 
     71            throw new TraxError('text1','text2'); 
     72        } 
     73        catch(Exception $e) { 
     74            $this->assertTrue(is_a($e,'TraxError')); 
     75            $this->assertEquals('text1',$e->getMessage()); 
     76            $this->assertEquals('text1',$e->error_message); 
     77            $this->assertEquals('text2',$e->error_heading); 
     78            $this->assertEquals('500',$e->error_code); 
     79            return; 
     80        } 
     81        $this->fail('TraxError exception with default code not raised'); 
     82    } 
     83 
     84    /** 
     85     *  Test exception with specified of code 
     86     */ 
     87    public function testSpecified_code() { 
     88        try { 
     89            throw new TraxError('text3','text4', 250); 
     90        } 
     91        catch(Exception $e) { 
     92            $this->assertTrue(is_a($e,'TraxError')); 
     93            $this->assertEquals('text3',$e->getMessage()); 
     94            $this->assertEquals('text3',$e->error_message); 
     95            $this->assertEquals('text4',$e->error_heading); 
     96            $this->assertEquals(250,$e->error_code); 
     97            return; 
     98        } 
     99        $this->fail('TraxError exception with code 250 not raised'); 
    70100    } 
    71101} 
  • trunk/trax/test/runtests.php

    r159 r163  
    1515//  Control order of tests 
    1616$tests = array( 
     17               //  TraxError used by ActiveRecordError, ActionControllerError 
     18               'TraxErrorTest.php', 
     19               'ActionControllerErrorTest.php', 
     20               'ActiveRecordErrorTest.php', 
     21               //  Inflector is used by many classes 
     22               'InflectorTest.php', 
     23               //  Router is used by ActionController 
     24               'RouterTest.php', 
    1725               'ActionControllerTest.php', 
    18                'ActionControllerErrorTest.php', 
     26               //  ScaffoldController extends ActionController 
     27               'ScaffoldControllerTest.php', 
     28               //  ApplicationController extends ActionController 
     29               'ApplicationControllerTest.php', 
    1930               'ActionMailerTest.php', 
    2031               'ActiveRecordTest.php', 
    21                'ActiveRecordErrorTest.php', 
    2232               'ActiveRecordHelperTest.php', 
    23                'ApplicationControllerTest.php', 
    2433               'ApplicationMailerTest.php', 
    2534               'AssetTagHelperTest.php', 
     
    3039               'FormTagHelperTest.php', 
    3140               'HelpersTest.php', 
    32                'InflectorTest.php', 
    3341               'InputFilterTest.php', 
    3442               'JavaScriptHelperTest.php', 
    35                'RouterTest.php', 
    36                'ScaffoldControllerTest.php', 
    3743               'SessionTest.php', 
    38                'TraxErrorTest.php', 
    3944               'TraxGeneratorTest.php', 
    4045               'UrlHelperTest.php',