Skip to content

Commit

Permalink
Adding valid option checking to fieldParameters.
Browse files Browse the repository at this point in the history
Test case added.
  • Loading branch information
markstory committed Oct 29, 2009
1 parent f299283 commit a334571
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -2489,6 +2489,9 @@ function buildColumn($column) {
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);
Expand Down
32 changes: 31 additions & 1 deletion cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -3612,7 +3612,37 @@ function testBuildColumn() {
$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);
}

/**
Expand Down

0 comments on commit a334571

Please sign in to comment.