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

Source for file HelpersTest.php

Documentation is available at HelpersTest.php

  1. <?php
  2. /**
  3.  *  File for the HelpersTest 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: HelpersTest.php 208 2006-05-28 17:59:55Z john $
  11.  * @author Walt Haas <haas@xmission.com>
  12.  */
  13.  
  14. echo "testing Helpers\n";
  15.  
  16. // Call HelpersTest::main() if this source file is executed directly.
  17. if (!defined("PHPUnit2_MAIN_METHOD")) {
  18.     define("PHPUnit2_MAIN_METHOD""HelpersTest::main");
  19. }
  20.  
  21. require_once "PHPUnit2/Framework/TestCase.php";
  22. require_once "PHPUnit2/Framework/TestSuite.php";
  23.  
  24. // You may remove the following line when all tests have been implemented.
  25. require_once "PHPUnit2/Framework/IncompleteTestError.php";
  26.  
  27. //  root Trax files in the test directory
  28. define("TRAX_ROOT"dirname(__FILE__));
  29. require_once 'testenv.php';
  30.  
  31. require_once "action_view/helpers.php";
  32. require_once "action_controller.php";
  33. require_once "router.php";
  34. require_once "controllers/application.php";
  35.  
  36. /**
  37.  *  Extend Helpers class to test protected methods
  38.  */
  39. class ExtHelpers extends Helpers
  40. {
  41.     function __construct($object_name null$attribute_name null{
  42.         parent::__construct($object_name$attribute_name);
  43.     }
  44.  
  45.     function boolean_attribute(&$options$attribute{
  46.         parent::boolean_attribute($options$attribute);
  47.     }
  48.  
  49.     function convert_options($options array()) {
  50.         return parent::convert_options($options);
  51.     }
  52.  
  53.     function object($object_name null{
  54.         return parent::object($object_name);
  55.     }
  56. }                         // class ExtHelpers extends Helpers
  57.  
  58. /**
  59.  *  Dummy controller object
  60.  */
  61. {
  62.     var $some_attr = 'attr value';
  63. }                         // class DummyController
  64.  
  65. /**
  66.  * Test class for Helpers.
  67.  * Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:23:35.
  68.  */
  69. class HelpersTest extends PHPUnit2_Framework_TestCase {
  70.     /**
  71.      * Runs the test methods of this class.
  72.      *
  73.      * @access public
  74.      * @static
  75.      */
  76.     public static function main({
  77.         require_once "PHPUnit2/TextUI/TestRunner.php";
  78.  
  79.         $suite  new PHPUnit2_Framework_TestSuite("HelpersTest");
  80.         $result PHPUnit2_TextUI_TestRunner::run($suite);
  81.     }
  82.  
  83.     /**
  84.      * Sets up the fixture, for example, open a network connection.
  85.      * This method is called before a test is executed.
  86.      *
  87.      * @access protected
  88.      */
  89.     protected function setUp({
  90.         Trax::$current_controller_name 'foo_controller';
  91.         Trax::$current_controller_path '/foo/bar/mumble';
  92.         Trax::$current_controller_object 'nonobject';
  93.     }
  94.  
  95.     /**
  96.      * Tears down the fixture, for example, close a network connection.
  97.      * This method is called after a test is executed.
  98.      *
  99.      * @access protected
  100.      */
  101.     protected function tearDown({
  102.     }
  103.  
  104.  
  105.     /**
  106.      *  Test constructor
  107.      * @todo Figure out how to test first argument
  108.      */
  109.     public function test__construct({
  110.         //  No arguments to constructor
  111.         $h new Helpers;
  112.         $this->assertFalse($h->auto_index);
  113.         $this->assertEquals(''$h->object_name);
  114.         $this->assertNull($h->attribute_name);
  115.         $this->assertEquals('foo_controller'$h->controller_name);
  116.         $this->assertEquals('/foo/bar/mumble'$h->controller_path);
  117.         $this->assertEquals('nonobject'$h->controller_object);
  118.         //  Only attribute argument to constructor
  119.         $h new Helpers(null,'someattr');
  120.         $this->assertFalse($h->auto_index);
  121.         $this->assertEquals(''$h->object_name);
  122.         $this->assertEquals('someattr'$h->attribute_name);
  123.         $this->assertEquals('foo_controller'$h->controller_name);
  124.         $this->assertEquals('/foo/bar/mumble'$h->controller_path);
  125.         $this->assertEquals('nonobject'$h->controller_object);
  126.  
  127.         //  Need to figure out how the first argument is used
  128.         //  and write a test for it.
  129.         // Remove the following line when you implement this test.
  130.         throw new PHPUnit2_Framework_IncompleteTestError;
  131.     }
  132.  
  133.     /**
  134.      * Test cdata_section().
  135.      */
  136.     public function testCdata_section({
  137.         //  Test the cdata_section() method of the object
  138.         $h new Helpers;
  139.         $s $h->cdata_section('foo');
  140.         $this->assertEquals("<![CDATA[foo]]>"$s);
  141.         //  Test the file function that calls cdata_section()
  142.         $s cdata_section('foo');
  143.         $this->assertEquals("<![CDATA[foo]]>"$s);
  144.     }
  145.  
  146.     /**
  147.      *  Test tag()
  148.      */
  149.     public function testTag({
  150.         //  Test the tag() method of the object
  151.         $h new Helpers;
  152.         $s $h->tag('p');
  153.         $this->assertEquals("<p  />\n",$s);
  154.         $h new Helpers;
  155.         $s $h->tag('p'array('id'=>'a&b'));
  156.         $this->assertEquals("<p id=\"a&amp;b\" />\n",$s);
  157.         $h new Helpers;
  158.         $s $h->tag('p'array('id'=>'a&b'),true);
  159.         $this->assertEquals("<p id=\"a&amp;b\">\n",$s);
  160.         //  Test the file function that calls tag()
  161.         $s tag('p');
  162.         $this->assertEquals("<p  />\n",$s);
  163.         $s tag('p'array('id'=>'a&b'));
  164.         $this->assertEquals("<p id=\"a&amp;b\" />\n",$s);
  165.         $s tag('p'array('id'=>'a&b'),true);
  166.         $this->assertEquals("<p id=\"a&amp;b\">\n",$s);
  167.     }
  168.  
  169.     /**
  170.      *  Test content_tag()
  171.      */
  172.     public function testContent_tag({
  173.         //  Test the content_tag() method of the object
  174.         $h new Helpers;
  175.         $s $h->content_tag('p','hello world');
  176.         $this->assertEquals("<p >hello world</p>\n",$s);
  177.         $h new Helpers;
  178.         $s $h->content_tag('p','hello world',array('class'=>'content'));
  179.         $this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
  180.         $h new Helpers;
  181.         $s $h->content_tag('p','hello world',array('id'=>'a&b'));
  182.         $this->assertEquals("<p id=\"a&amp;b\">hello world</p>\n",$s);
  183.         //  Test the file function that calls content_tag()
  184.         $s content_tag('p','hello world');
  185.         $this->assertEquals("<p >hello world</p>\n",$s);
  186.         $s content_tag('p','hello world',array('class'=>'content'));
  187.         $this->assertEquals("<p class=\"content\">hello world</p>\n",$s);
  188.     }
  189.  
  190.     /**
  191.      * Test boolean_attribute().
  192.      */
  193.     public function testBoolean_attribute({
  194.         $e new ExtHelpers;
  195.         $k array('foo'=>'bar''mumble'=>'grumble');
  196.         $e->boolean_attribute($k,'foo');
  197.         $this->assertEquals(array('foo'=>'foo''mumble'=>'grumble')$k);
  198.     }
  199.  
  200.     /**
  201.      * Test convert_options().
  202.      */
  203.     public function testConvert_options({
  204.         $e new ExtHelpers;
  205.         $k array('disabled'=>'foo',
  206.                    'readonly'=>'bar',
  207.                    'multiple'=>'whocares',
  208.                    'mumble'=>'grumble');
  209.         $r $e->convert_options($k);
  210.         $this->assertEquals(array('disabled'=>'disabled',
  211.                                   'readonly'=>'readonly',
  212.                                   'multiple'=>'multiple',
  213.                                   'mumble'=>'grumble'),
  214.                             $r);
  215.     }
  216.  
  217.     /**
  218.      * Test object()
  219.      */
  220.     public function testObject({
  221.         //  Constructing with no object name and then
  222.         //  calling object with no argument should return null
  223.         $e new ExtHelpers;
  224.         $this->assertNull($e->object());
  225.         //  Create a dummy controller object
  226.         $d new DummyController;
  227.         Trax::$current_controller_object $d;
  228.         //  This should inherit value of current_controller_object
  229.         $e new ExtHelpers;
  230.         $this->assertEquals('attr value'$e->object('some_attr'));
  231.         //  This should inherit object name from constructor
  232.         $e new ExtHelpers('some_attr');
  233.         $this->assertEquals('attr value'$e->object());
  234.     }
  235.  
  236.     /**
  237.      * @todo Implement testValue().
  238.      */
  239.     public function testValue({
  240.         // Remove the following line when you implement this test.
  241.         throw new PHPUnit2_Framework_IncompleteTestError;
  242.     }
  243.  
  244.     /**
  245.      * @todo Implement testTo_content_tag().
  246.      */
  247.     public function testTo_content_tag({
  248.         // Remove the following line when you implement this test.
  249.         throw new PHPUnit2_Framework_IncompleteTestError;
  250.     }
  251. }
  252.  
  253. // Call HelpersTest::main() if this source file is executed directly.
  254. if (PHPUnit2_MAIN_METHOD == "HelpersTest::main"{
  255.     HelpersTest::main();
  256. }
  257.  
  258. // -- set Emacs parameters --
  259. // Local variables:
  260. // tab-width: 4
  261. // c-basic-offset: 4
  262. // c-hanging-comment-ender-p: nil
  263. // indent-tabs-mode: nil
  264. // End:
  265. ?>

Documentation generated on Mon, 21 May 2007 22:28:36 -0600 by phpDocumentor 1.3.2