Adding valid option checking to fieldParameters.

Test case added.
This commit is contained in:
mark_story 2009-10-29 02:03:21 -04:00
parent f299283dc4
commit a33457155f
2 changed files with 34 additions and 1 deletions

View file

@ -2489,6 +2489,9 @@ class DboSource extends DataSource {
function _buildFieldParameters($columnString, $columnData, $position) {
foreach ($this->fieldParameters as $paramName => $value) {
if (isset($columnData[$paramName]) && $value['position'] == $position) {
if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) {
continue;
}
$val = $columnData[$paramName];
if ($value['quote']) {
$val = $this->value($val);

View file

@ -3612,7 +3612,37 @@ class DboSourceTest extends CakeTestCase {
$this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), );
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertTrue($result, $expected);
$this->assertEqual($result, $expected);
$this->testDb->fieldParameters['param'] = array(
'value' => 'COLLATE',
'quote' => false,
'join' => ' ',
'column' => 'Collate',
'position' => 'beforeDefault',
'options' => array('GOOD', 'OK')
);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'BAD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) NOT NULL';
$this->assertEqual($result, $expected);
$data = array(
'name' => 'int_field',
'type' => 'integer',
'default' => '',
'null' => false,
'param' => 'GOOD'
);
$result = $this->testDb->buildColumn($data);
$expected = '`int_field` int(11) COLLATE GOOD NOT NULL';
$this->assertEqual($result, $expected);
}
/**