Switching FixtureTask to use var_export() instead of custom

escaping code.
Fixes issues with quotes in text.
Fixes #1922
This commit is contained in:
Mark Story 2011-08-20 20:08:45 -04:00
parent f9ff4e1e68
commit 9daa969783
2 changed files with 31 additions and 13 deletions

View file

@ -296,35 +296,30 @@ class FixtureTask extends BakeTask {
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2); $insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
} }
} }
$insert = "'$insert'";
break; break;
case 'timestamp': case 'timestamp':
$ts = time(); $insert = time();
$insert = "'$ts'";
break; break;
case 'datetime': case 'datetime':
$ts = date('Y-m-d H:i:s'); $insert = date('Y-m-d H:i:s');
$insert = "'$ts'";
break; break;
case 'date': case 'date':
$ts = date('Y-m-d'); $insert = date('Y-m-d');
$insert = "'$ts'";
break; break;
case 'time': case 'time':
$ts = date('H:i:s'); $insert = date('H:i:s');
$insert = "'$ts'";
break; break;
case 'boolean': case 'boolean':
$insert = 1; $insert = 1;
break; break;
case 'text': case 'text':
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat."; $insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
$insert .= " Convallis morbi fringilla gravida,"; $insert .= " Convallis morbi fringilla gravida,";
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin"; $insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla"; $insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
$insert .= " vestibulum massa neque ut et, id hendrerit sit,"; $insert .= " vestibulum massa neque ut et, id hendrerit sit,";
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus"; $insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
$insert .= " duis vestibulum nunc mattis convallis.'"; $insert .= " duis vestibulum nunc mattis convallis.";
break; break;
} }
$record[$field] = $insert; $record[$field] = $insert;
@ -346,7 +341,8 @@ class FixtureTask extends BakeTask {
foreach ($records as $record) { foreach ($records as $record) {
$values = array(); $values = array();
foreach ($record as $field => $value) { foreach ($record as $field => $value) {
$values[] = "\t\t\t'$field' => $value"; $val = var_export($value, true);
$values[] = "\t\t\t'$field' => $val";
} }
$out .= "\t\tarray(\n"; $out .= "\t\tarray(\n";
$out .= implode(",\n", $values); $out .= implode(",\n", $values);
@ -387,7 +383,7 @@ class FixtureTask extends BakeTask {
foreach ($records as $record) { foreach ($records as $record) {
$row = array(); $row = array();
foreach ($record[$modelObject->alias] as $field => $value) { foreach ($record[$modelObject->alias] as $field => $value) {
$row[$field] = $db->value($value, $schema[$field]['type']); $row[$field] = $value;
} }
$out[] = $row; $out[] = $row;
} }

View file

@ -167,6 +167,28 @@ class FixtureTaskTest extends CakeTestCase {
$this->assertPattern('/Third Article/', $result, 'Missing import data %s'); $this->assertPattern('/Third Article/', $result, 'Missing import data %s');
} }
/**
* Ensure that fixture data doesn't get overly escaped.
*
* @return void
*/
function testImportRecordsNoEscaping() {
$Article = ClassRegistry::init('Article');
$Article->updateAll(array('body' => "'Body \"value\"'"));
$this->Task->interactive = true;
$this->Task->setReturnValueAt(0, 'in', 'WHERE 1=1 LIMIT 10');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$result = $this->Task->bake('Article', false, array(
'fromTable' => true,
'schema' => 'Article',
'records' => false
));
$this->assertPattern("/'body' => 'Body \"value\"'/", $result, 'Data has escaping %s');
}
/** /**
* test that execute passes runs bake depending with named model. * test that execute passes runs bake depending with named model.
* *