root/trunk/trax/test/HelpersTest.php

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