mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-02 15:57:53 +02:00
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@56212 467b73ca-7a2a-4603-9d3b-597d59a354a9
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class FormTest extends SapphireTest {
|
|
|
|
public function testLoadDataFromRequest() {
|
|
$form = new Form(
|
|
new Controller(),
|
|
'Form',
|
|
new FieldSet(
|
|
new TextField('key1'),
|
|
new TextField('namespace[key2]'),
|
|
new TextField('namespace[key3][key4]'),
|
|
new TextField('othernamespace[key5][key6][key7]')
|
|
),
|
|
new FieldSet()
|
|
);
|
|
|
|
// url would be ?key1=val1&namespace[key2]=val2&namespace[key3][key4]=val4&othernamespace[key5][key6][key7]=val7
|
|
$requestData = array(
|
|
'key1' => 'val1',
|
|
'namespace' => array(
|
|
'key2' => 'val2',
|
|
'key3' => array(
|
|
'key4' => 'val4',
|
|
)
|
|
),
|
|
'othernamespace' => array(
|
|
'key5' => array(
|
|
'key6' =>array(
|
|
'key7' => 'val7'
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
$form->loadDataFrom($requestData);
|
|
|
|
$fields = $form->Fields();
|
|
$this->assertEquals($fields->fieldByName('key1')->Value(), 'val1');
|
|
$this->assertEquals($fields->fieldByName('namespace[key2]')->Value(), 'val2');
|
|
$this->assertEquals($fields->fieldByName('namespace[key3][key4]')->Value(), 'val4');
|
|
$this->assertEquals($fields->fieldByName('othernamespace[key5][key6][key7]')->Value(), 'val7');
|
|
}
|
|
|
|
}
|
|
?>
|