Adding tests for habtm data selection. Refs #256

This commit is contained in:
mark_story 2009-11-04 13:56:44 -05:00
parent 5f1d090bf0
commit b974127562

View file

@ -3039,6 +3039,55 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* test generation of habtm select boxes.
*
* @return void
**/
function testHabtmSelectBox() {
$view =& ClassRegistry::getObject('view');
$view->viewVars['contactTags'] = array(
1 => 'blue',
2 => 'red',
3 => 'green'
);
$this->Form->data = array(
'Contact' => array(),
'ContactTag' => array(
array(
'id' => 1,
'name' => 'blue'
),
array(
'id' => 3,
'name' => 'green'
)
)
);
$this->Form->create('Contact');
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => ''
),
'select' => array(
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
'multiple' => 'multiple'
),
array('option' => array('value' => '1', 'selected' => 'selected')),
'blue',
'/option',
array('option' => array('value' => '2')),
'red',
'/option',
array('option' => array('value' => '3', 'selected' => 'selected')),
'green',
'/option',
'/select'
);
$this->assertTags($result, $expected);
}
/**
* test generation of multi select elements in checkbox format
*