| | 40 | require_once "../vendor/trax/action_controller.php"; |
| | 41 | require_once "../vendor/trax/router.php"; |
| | 42 | require_once "../app/controllers/application.php"; |
| | 43 | |
| | 44 | /** |
| | 45 | * Extend Helpers class to test protected methods |
| | 46 | */ |
| | 47 | class 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 | */ |
| | 69 | class DummyController extends ApplicationController |
| | 70 | { |
| | 71 | var $some_attr = 'attr value'; |
| | 72 | } // class DummyController |
| 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. |
| | 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&b\" />\n",$s); |
| | 166 | $h = new Helpers; |
| | 167 | $s = $h->tag('p', array('id'=>'a&b'),true); |
| | 168 | $this->assertEquals("<p id=\"a&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&b\" />\n",$s); |
| | 174 | $s = tag('p', array('id'=>'a&b'),true); |
| | 175 | $this->assertEquals("<p id=\"a&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&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() { |