Changeset 165 for trunk/trax/test

Show
Ignore:
Timestamp:
03/09/06 12:50:58 (6 years ago)
Author:
haas
Message:

improve various test, documents

Files:
1 modified

Legend:

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

    r159 r165  
    2626require_once "PHPUnit2/Framework/IncompleteTestError.php"; 
    2727 
     28//  root Trax files in the test directory 
     29define("TRAX_ROOT", dirname(__FILE__) . "/"); 
     30define("TRAX_LIB_ROOT", "../vendor/trax"); 
     31define("TRAX_VIEWS_EXTENTION",  "phtml"); 
     32$GLOBALS['TRAX_INCLUDES'] = 
     33    array( "config"      => "config", 
     34           "controllers" => "controllers", 
     35           "helpers"     => "helpers", 
     36           "layouts"     => "layouts", 
     37           "views"       => "views"); 
     38 
    2839require_once "../vendor/trax/action_view/helpers.php"; 
     40require_once "../vendor/trax/action_controller.php"; 
     41require_once "../vendor/trax/router.php"; 
     42require_once "../app/controllers/application.php"; 
     43 
     44/** 
     45 *  Extend Helpers class to test protected methods 
     46 */ 
     47class ExtHelpers extends Helpers 
     48{ 
     49    function __construct($object_name = null, $attribute_name = null) { 
     50        parent::__construct($object_name, $attribute_name); 
     51    } 
     52 
     53    function boolean_attribute(&$options, $attribute) { 
     54        parent::boolean_attribute($options, $attribute); 
     55    } 
     56 
     57    function convert_options($options = array()) { 
     58        return parent::convert_options($options); 
     59    } 
     60 
     61    function object($object_name = null) { 
     62        return parent::object($object_name); 
     63    } 
     64}                         // class ExtHelpers extends Helpers 
     65 
     66/** 
     67 *  Dummy controller object 
     68 */ 
     69class DummyController extends ApplicationController 
     70{ 
     71    var $some_attr = 'attr value'; 
     72}                         // class DummyController 
    2973 
    3074/** 
     
    5397     */ 
    5498    protected function setUp() { 
     99        $GLOBALS['current_controller_name'] = 'foo_controller'; 
     100        $GLOBALS['current_controller_path'] = '/foo/bar/mumble'; 
     101        $GLOBALS['current_controller_object'] = 'nonobject'; 
    55102    } 
    56103 
     
    64111    } 
    65112 
    66     /** 
    67      * @todo Implement testCdata_section(). 
    68      */ 
    69     public function testCdata_section() { 
     113 
     114    /** 
     115     *  Test constructor 
     116     * @todo Figure out how to test first argument 
     117     */ 
     118    public function test__construct() { 
     119        //  No arguments to constructor 
     120        $h = new Helpers; 
     121        $this->assertFalse($h->auto_index); 
     122        $this->assertEquals('', $h->object_name); 
     123        $this->assertNull($h->attribute_name); 
     124        $this->assertEquals('foo_controller', $h->controller_name); 
     125        $this->assertEquals('/foo/bar/mumble', $h->controller_path); 
     126        $this->assertEquals('nonobject', $h->controller_object); 
     127        //  Only attribute argument to constructor 
     128        $h = new Helpers(null,'someattr'); 
     129        $this->assertFalse($h->auto_index); 
     130        $this->assertEquals('', $h->object_name); 
     131        $this->assertEquals('someattr', $h->attribute_name); 
     132        $this->assertEquals('foo_controller', $h->controller_name); 
     133        $this->assertEquals('/foo/bar/mumble', $h->controller_path); 
     134        $this->assertEquals('nonobject', $h->controller_object); 
     135 
     136        //  Need to figure out how the first argument is used 
     137        //  and write a test for it. 
    70138        // Remove the following line when you implement this test. 
    71139        throw new PHPUnit2_Framework_IncompleteTestError; 
     
    73141 
    74142    /** 
    75      * @todo Implement testTag(). 
     143     * Test cdata_section(). 
     144     */ 
     145    public function testCdata_section() { 
     146        //  Test the cdata_section() method of the object 
     147        $h = new Helpers; 
     148        $s = $h->cdata_section('foo'); 
     149        $this->assertEquals("<![CDATA[foo]]>", $s); 
     150        //  Test the file function that calls cdata_section() 
     151        $s = cdata_section('foo'); 
     152        $this->assertEquals("<![CDATA[foo]]>", $s); 
     153    } 
     154 
     155    /** 
     156     *  Test tag() 
    76157     */ 
    77158    public function testTag() { 
     159        //  Test the tag() method of the object 
     160        $h = new Helpers; 
     161        $s = $h->tag('p'); 
     162        $this->assertEquals("<p  />\n",$s); 
     163        $h = new Helpers; 
     164        $s = $h->tag('p', array('id'=>'a&b')); 
     165        $this->assertEquals("<p id=\"a&amp;b\" />\n",$s); 
     166        $h = new Helpers; 
     167        $s = $h->tag('p', array('id'=>'a&b'),true); 
     168        $this->assertEquals("<p id=\"a&amp;b\">\n",$s); 
     169        //  Test the file function that calls tag() 
     170        $s = tag('p'); 
     171        $this->assertEquals("<p  />\n",$s); 
     172        $s = tag('p', array('id'=>'a&b')); 
     173        $this->assertEquals("<p id=\"a&amp;b\" />\n",$s); 
     174        $s = tag('p', array('id'=>'a&b'),true); 
     175        $this->assertEquals("<p id=\"a&amp;b\">\n",$s); 
     176    } 
     177 
     178    /** 
     179     *  Test content_tag() 
     180     */ 
     181    public function testContent_tag() { 
     182        //  Test the content_tag() method of the object 
     183        $h = new Helpers; 
     184        $s = $h->content_tag('p','hello world'); 
     185        $this->assertEquals("<p >hello world</p>\n",$s); 
     186        $h = new Helpers; 
     187        $s = $h->content_tag('p','hello world',array('class'=>'content')); 
     188        $this->assertEquals("<p class=\"content\">hello world</p>\n",$s); 
     189        $h = new Helpers; 
     190        $s = $h->content_tag('p','hello world',array('id'=>'a&b')); 
     191        $this->assertEquals("<p id=\"a&amp;b\">hello world</p>\n",$s); 
     192        //  Test the file function that calls content_tag() 
     193        $s = content_tag('p','hello world'); 
     194        $this->assertEquals("<p >hello world</p>\n",$s); 
     195        $s = content_tag('p','hello world',array('class'=>'content')); 
     196        $this->assertEquals("<p class=\"content\">hello world</p>\n",$s); 
     197    } 
     198 
     199    /** 
     200     * Test boolean_attribute(). 
     201     */ 
     202    public function testBoolean_attribute() { 
     203        $e = new ExtHelpers; 
     204        $k = array('foo'=>'bar', 'mumble'=>'grumble'); 
     205        $e->boolean_attribute($k,'foo'); 
     206        $this->assertEquals(array('foo'=>'foo', 'mumble'=>'grumble'), $k); 
     207    } 
     208 
     209    /** 
     210     * Test convert_options(). 
     211     */ 
     212    public function testConvert_options() { 
     213        $e = new ExtHelpers; 
     214        $k = array('disabled'=>'foo', 
     215                   'readonly'=>'bar', 
     216                   'multiple'=>'whocares', 
     217                   'mumble'=>'grumble'); 
     218        $r = $e->convert_options($k); 
     219        $this->assertEquals(array('disabled'=>'disabled', 
     220                                  'readonly'=>'readonly', 
     221                                  'multiple'=>'multiple', 
     222                                  'mumble'=>'grumble'), 
     223                            $r); 
     224    } 
     225 
     226    /** 
     227     * Test object() 
     228     */ 
     229    public function testObject() { 
     230        //  Constructing with no object name and then 
     231        //  calling object with no argument should return null 
     232        $e = new ExtHelpers; 
     233        $this->assertNull($e->object()); 
     234        //  Create a dummy controller object 
     235        $d = new DummyController; 
     236        $GLOBALS['current_controller_object'] = $d; 
     237        //  This should inherit value of current_controller_object 
     238        $e = new ExtHelpers; 
     239        $this->assertEquals('attr value', $e->object('some_attr')); 
     240        //  This should inherit object name from constructor 
     241        $e = new ExtHelpers('some_attr'); 
     242        $this->assertEquals('attr value', $e->object()); 
     243    } 
     244 
     245    /** 
     246     * @todo Implement testTo_content_tag(). 
     247     */ 
     248    public function testTo_content_tag() { 
    78249        // Remove the following line when you implement this test. 
    79250        throw new PHPUnit2_Framework_IncompleteTestError; 
     
    81252 
    82253    /** 
    83      * @todo Implement testContent_tag(). 
    84      */ 
    85     public function testContent_tag() { 
    86         // Remove the following line when you implement this test. 
    87         throw new PHPUnit2_Framework_IncompleteTestError; 
    88     } 
    89  
    90     /** 
    91      * @todo Implement testTo_content_tag(). 
    92      */ 
    93     public function testTo_content_tag() { 
     254     * @todo Implement testValue(). 
     255     */ 
     256    public function testValue() { 
    94257        // Remove the following line when you implement this test. 
    95258        throw new PHPUnit2_Framework_IncompleteTestError;