/usr/share/php/kohana3.1/system/tests/kohana/FormTest.php is in libkohana3.1-core-php 3.1.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
/**
* Tests Kohana Form helper
*
* @group kohana
* @group kohana.form
*
* @package Kohana
* @category Tests
* @author Kohana Team
* @author Jeremy Bush <contractfrombelow@gmail.com>
* @copyright (c) 2008-2011 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_FormTest extends Unittest_TestCase
{
/**
* Defaults for this test
* @var array
*/
protected $environmentDefault = array(
'Kohana::$base_url' => '/',
'HTTP_HOST' => 'kohanaframework.org',
);
/**
* Provides test data for test_open()
*
* @return array
*/
public function provider_open()
{
return array(
// $value, $result
array(NULL, NULL, '<form action="/" method="post" accept-charset="utf-8">'),
array('foo', NULL),
array('', NULL),
array('foo', array('method' => 'get')),
);
}
/**
* Tests Form::open()
*
* @test
* @dataProvider provider_open
* @param boolean $input Input for Form::open
* @param boolean $expected Output for Form::open
*/
public function test_open($action, $attributes)
{
$tag = Form::open($action, $attributes);
$matcher = array(
'tag' => 'form',
'attributes' => array(
'method' => 'post',
'accept-charset' => 'utf-8',
),
);
if ($attributes !== NULL)
{
$matcher['attributes'] = $attributes + $matcher['attributes'];
}
$this->assertTag($matcher, $tag);
}
/**
* Tests Form::close()
*
* @test
*/
public function test_close()
{
$this->assertSame('</form>', Form::close());
}
/**
* Provides test data for test_input()
*
* @return array
*/
public function provider_input()
{
return array(
// $value, $result
array('input', 'foo', 'bar', NULL, 'input'),
array('input', 'foo', NULL, NULL, 'input'),
array('hidden', 'foo', 'bar', NULL, 'hidden'),
array('password', 'foo', 'bar', NULL, 'password'),
);
}
/**
* Tests Form::input()
*
* @test
* @dataProvider provider_input
* @param boolean $input Input for Form::input
* @param boolean $expected Output for Form::input
*/
public function test_input($type, $name, $value, $attributes)
{
$matcher = array(
'tag' => 'input',
'attributes' => array('name' => $name, 'type' => $type)
);
// Form::input creates a text input
if ($type === 'input')
{
$matcher['attributes']['type'] = 'text';
}
// NULL just means no value
if ($value !== NULL)
{
$matcher['attributes']['value'] = $value;
}
// Add on any attributes
if (is_array($attributes))
{
$matcher['attributes'] = $attributes + $matcher['attributes'];
}
$tag = Form::$type($name, $value, $attributes);
$this->assertTag($matcher, $tag, $tag);
}
/**
* Provides test data for test_file()
*
* @return array
*/
public function provider_file()
{
return array(
// $value, $result
array('foo', NULL, '<input type="file" name="foo" />'),
);
}
/**
* Tests Form::file()
*
* @test
* @dataProvider provider_file
* @param boolean $input Input for Form::file
* @param boolean $expected Output for Form::file
*/
public function test_file($name, $attributes, $expected)
{
$this->assertSame($expected, Form::file($name, $attributes));
}
/**
* Provides test data for test_check()
*
* @return array
*/
public function provider_check()
{
return array(
// $value, $result
array('checkbox', 'foo', NULL, FALSE, NULL),
array('checkbox', 'foo', NULL, TRUE, NULL),
array('checkbox', 'foo', 'bar', TRUE, NULL),
array('radio', 'foo', NULL, FALSE, NULL),
array('radio', 'foo', NULL, TRUE, NULL),
array('radio', 'foo', 'bar', TRUE, NULL),
);
}
/**
* Tests Form::check()
*
* @test
* @dataProvider provider_check
* @param boolean $input Input for Form::check
* @param boolean $expected Output for Form::check
*/
public function test_check($type, $name, $value, $checked, $attributes)
{
$matcher = array('tag' => 'input', 'attributes' => array('name' => $name, 'type' => $type));
if ($value !== NULL)
{
$matcher['attributes']['value'] = $value;
}
if (is_array($attributes))
{
$matcher['attributes'] = $attributes + $matcher['attributes'];
}
if ($checked === TRUE)
{
$matcher['attributes']['checked'] = 'checked';
}
$tag = Form::$type($name, $value, $checked, $attributes);
$this->assertTag($matcher, $tag, $tag);
}
/**
* Provides test data for test_text()
*
* @return array
*/
public function provider_text()
{
return array(
// $value, $result
array('textarea', 'foo', 'bar', NULL),
array('textarea', 'foo', 'bar', array('rows' => 20, 'cols' => 20)),
array('button', 'foo', 'bar', NULL),
array('label', 'foo', 'bar', NULL),
array('label', 'foo', NULL, NULL),
);
}
/**
* Tests Form::textarea()
*
* @test
* @dataProvider provider_text
* @param boolean $input Input for Form::textarea
* @param boolean $expected Output for Form::textarea
*/
public function test_text($type, $name, $body, $attributes)
{
$matcher = array(
'tag' => $type,
'attributes' => array(),
'content' => $body,
);
if ($type !== 'label')
{
$matcher['attributes'] = array('name' => $name);
}
else
{
$matcher['attributes'] = array('for' => $name);
}
if (is_array($attributes))
{
$matcher['attributes'] = $attributes + $matcher['attributes'];
}
$tag = Form::$type($name, $body, $attributes);
$this->assertTag($matcher, $tag, $tag);
}
/**
* Provides test data for test_select()
*
* @return array
*/
public function provider_select()
{
return array(
// $value, $result
array('foo', NULL, NULL, "<select name=\"foo\"></select>"),
array('foo', array('bar' => 'bar'), NULL, "<select name=\"foo\">\n<option value=\"bar\">bar</option>\n</select>"),
array('foo', array('bar' => 'bar'), 'bar', "<select name=\"foo\">\n<option value=\"bar\" selected=\"selected\">bar</option>\n</select>"),
array('foo', array('bar' => array('foo' => 'bar')), NULL, "<select name=\"foo\">\n<optgroup label=\"bar\">\n<option value=\"foo\">bar</option>\n</optgroup>\n</select>"),
array('foo', array('bar' => array('foo' => 'bar')), 'foo', "<select name=\"foo\">\n<optgroup label=\"bar\">\n<option value=\"foo\" selected=\"selected\">bar</option>\n</optgroup>\n</select>"),
// #2286
array('foo', array('bar' => 'bar', 'unit' => 'test', 'foo' => 'foo'), array('bar', 'foo'), "<select name=\"foo\" multiple=\"multiple\">\n<option value=\"bar\" selected=\"selected\">bar</option>\n<option value=\"unit\">test</option>\n<option value=\"foo\" selected=\"selected\">foo</option>\n</select>"),
);
}
/**
* Tests Form::select()
*
* @test
* @dataProvider provider_select
* @param boolean $input Input for Form::select
* @param boolean $expected Output for Form::select
*/
public function test_select($name, $options, $selected, $expected)
{
// Much more efficient just to assertSame() rather than assertTag() on each element
$this->assertSame($expected, Form::select($name, $options, $selected));
}
/**
* Provides test data for test_submit()
*
* @return array
*/
public function provider_submit()
{
return array(
// $value, $result
array('foo', 'Foobar!', '<input type="submit" name="foo" value="Foobar!" />'),
);
}
/**
* Tests Form::submit()
*
* @test
* @dataProvider provider_submit
* @param boolean $input Input for Form::submit
* @param boolean $expected Output for Form::submit
*/
public function test_submit($name, $value, $expected)
{
$matcher = array(
'tag' => 'input',
'attributes' => array('name' => $name, 'type' => 'submit', 'value' => $value)
);
$this->assertTag($matcher, Form::submit($name, $value));
}
/**
* Provides test data for test_image()
*
* @return array
*/
public function provider_image()
{
return array(
// $value, $result
array('foo', 'bar', array('src' => 'media/img/login.png'), '<input type="image" name="foo" value="bar" src="/media/img/login.png" />'),
);
}
/**
* Tests Form::image()
*
* @test
* @dataProvider provider_image
* @param boolean $name Input for Form::image
* @param boolean $value Input for Form::image
* @param boolean $attributes Input for Form::image
* @param boolean $expected Output for Form::image
*/
public function test_image($name, $value, $attributes, $expected)
{
$this->assertSame($expected, Form::image($name, $value, $attributes));
}
/**
* Provides test data for test_label()
*
* @return array
*/
function provider_label()
{
return array(
// $value, $result
// Single for provided
array('email', NULL, NULL, '<label for="email">Email</label>'),
array('email_address', NULL, NULL, '<label for="email_address">Email Address</label>'),
array('email-address', NULL, NULL, '<label for="email-address">Email Address</label>'),
// For and text values provided
array('name', 'First name', NULL, '<label for="name">First name</label>'),
// with attributes
array('lastname', 'Last name', array('class' => 'text'), '<label class="text" for="lastname">Last name</label>'),
array('lastname', 'Last name', array('class' => 'text', 'id'=>'txt_lastname'), '<label id="txt_lastname" class="text" for="lastname">Last name</label>'),
);
}
/**
* Tests Form::label()
*
* @test
* @dataProvider provider_label
* @param boolean $for Input for Form::label
* @param boolean $text Input for Form::label
* @param boolean $attributes Input for Form::label
* @param boolean $expected Output for Form::label
*/
function test_label($for, $text, $attributes, $expected)
{
$this->assertSame($expected, Form::label($for, $text, $attributes));
}
}
|