| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
echo "testing Helpers\n"; |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
|
|---|
| 25 |
require_once "PHPUnit2/Framework/IncompleteTestError.php"; |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 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 |
|
|---|
| 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 |
} |
|---|
| 57 |
|
|---|
| 58 |
/** |
|---|
| 59 |
* Dummy controller object |
|---|
| 60 |
*/ |
|---|
| 61 |
class DummyController extends ApplicationController |
|---|
| 62 |
{ |
|---|
| 63 |
var $some_attr = 'attr value'; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
/** |
|---|
| 67 |
* Test class for Helpers. |
|---|
| 68 |
* Generated by PHPUnit2_Util_Skeleton on 2006-03-01 at 13:23:35. |
|---|
| 69 |
*/ |
|---|
| 70 |
class 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 139 |
$h = new Helpers; |
|---|
| 140 |
$s = $h->cdata_section('foo'); |
|---|
| 141 |
$this->assertEquals("<![CDATA[foo]]>", $s); |
|---|
| 142 |
|
|---|
| 143 |
$s = cdata_section('foo'); |
|---|
| 144 |
$this->assertEquals("<![CDATA[foo]]>", $s); |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
* Test tag() |
|---|
| 149 |
*/ |
|---|
| 150 |
public function testTag() { |
|---|
| 151 |
|
|---|
| 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&b\" />\n",$s); |
|---|
| 158 |
$h = new Helpers; |
|---|
| 159 |
$s = $h->tag('p', array('id'=>'a&b'),true); |
|---|
| 160 |
$this->assertEquals("<p id=\"a&b\">\n",$s); |
|---|
| 161 |
|
|---|
| 162 |
$s = tag('p'); |
|---|
| 163 |
$this->assertEquals("<p />\n",$s); |
|---|
| 164 |
$s = tag('p', array('id'=>'a&b')); |
|---|
| 165 |
$this->assertEquals("<p id=\"a&b\" />\n",$s); |
|---|
| 166 |
$s = tag('p', array('id'=>'a&b'),true); |
|---|
| 167 |
$this->assertEquals("<p id=\"a&b\">\n",$s); |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
* Test content_tag() |
|---|
| 172 |
*/ |
|---|
| 173 |
public function testContent_tag() { |
|---|
| 174 |
|
|---|
| 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&b\">hello world</p>\n",$s); |
|---|
| 184 |
|
|---|
| 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 |
|
|---|
| 223 |
// calling object with no argument should return null |
|---|
| 224 |
$e = new ExtHelpers; |
|---|
| 225 |
$this->assertNull($e->object()); |
|---|
| 226 |
|
|---|
| 227 |
$d = new DummyController; |
|---|
| 228 |
Trax::$current_controller_object = $d; |
|---|
| 229 |
|
|---|
| 230 |
$e = new ExtHelpers; |
|---|
| 231 |
$this->assertEquals('attr value', $e->object('some_attr')); |
|---|
| 232 |
|
|---|
| 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 |
|
|---|
| 242 |
throw new PHPUnit2_Framework_IncompleteTestError; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
* @todo Implement testTo_content_tag(). |
|---|
| 247 |
*/ |
|---|
| 248 |
public function testTo_content_tag() { |
|---|
| 249 |
|
|---|
| 250 |
throw new PHPUnit2_Framework_IncompleteTestError; |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
if (PHPUnit2_MAIN_METHOD == "HelpersTest::main") { |
|---|
| 256 |
HelpersTest::main(); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
?> |
|---|
| 267 |
|
|---|