Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '1.3' of git://github.com/cakephp/cakephp into 1.3

  • Loading branch information...
commit 1f473f5bcdf4bda8630af724dcae4fe8befad239 2 parents 5e27561 + d9c7f4d
ceeram ceeram authored
1  cake/console/libs/schema.php
View
@@ -504,6 +504,7 @@ function help() {
parameter will only update one table.
To use a snapshot pass the `-s` param with the snapshot number.
To preview the changes that will be done use `-dry`.
+ To force update of all tables into the schema, use the -f param.
TEXT;
$this->out($help);
$this->_stop();
2  cake/dispatcher.php
View
@@ -627,7 +627,7 @@ function _deliverAsset($assetFile, $ext) {
ob_start('ob_gzhandler');
}
- App::import('View', 'Media', false);
+ App::import('View', 'Media');
$controller = null;
$Media = new MediaView($controller);
if (isset($Media->mimeType[$ext])) {
10 cake/libs/cake_socket.php
View
@@ -212,8 +212,14 @@ function write($data) {
return false;
}
}
-
- return fwrite($this->connection, $data, strlen($data));
+ $totalBytes = strlen($data);
+ for ($written = 0, $rv = 0; $written < $totalBytes; $written += $rv) {
+ $rv = fwrite($this->connection, substr($data, $written));
+ if ($rv === false || $rv === 0) {
+ return $written;
+ }
+ }
+ return $written;
}
/**
8 cake/libs/controller/components/cookie.php
View
@@ -281,8 +281,14 @@ function delete($key) {
$this->read();
}
if (strpos($key, '.') === false) {
+ if (isset($this->__values[$key]) && is_array($this->__values[$key])) {
+ foreach ($this->__values[$key] as $idx => $val) {
+ $this->__delete("[$key][$idx]");
+ }
+ } else {
+ $this->__delete("[$key]");
+ }
unset($this->__values[$key]);
- $this->__delete("[$key]");
return;
}
$names = explode('.', $key, 2);
2  cake/libs/http_socket.php
View
@@ -945,7 +945,7 @@ function _parseHeader($header) {
* Parses cookies in response headers.
*
* @param array $header Header array containing one ore more 'Set-Cookie' headers.
- * @return mixed Either false on no cookies, or an array of cookies recieved.
+ * @return mixed Either false on no cookies, or an array of cookies received.
* @access public
* @todo Make this 100% RFC 2965 confirm
*/
4 cake/libs/model/behaviors/tree.php
View
@@ -437,7 +437,7 @@ function getpath(&$Model, $id = null, $fields = null, $recursive = null) {
*
* @param AppModel $Model Model instance
* @param mixed $id The ID of the record to move
- * @param mixed $number how many places to move the node or true to move to last position
+ * @param int|bool $number how many places to move the node or true to move to last position
* @return boolean true on success, false on failure
* @access public
* @link http://book.cakephp.org/view/1352/moveDown
@@ -496,7 +496,7 @@ function movedown(&$Model, $id = null, $number = 1) {
*
* @param AppModel $Model Model instance
* @param mixed $id The ID of the record to move
- * @param mixed $number how many places to move the node, or true to move to first position
+ * @param int|bool $number how many places to move the node, or true to move to first position
* @return boolean true on success, false on failure
* @access public
* @link http://book.cakephp.org/view/1353/moveUp
14 cake/libs/set.php
View
@@ -431,6 +431,13 @@ function extract($path, $data = null, $options = array()) {
'key' => $key,
'item' => array_keys($context['item']),
);
+ } elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.')) {
+ $context['trace'][] = $key;
+ $matches[] = array(
+ 'trace' => $context['trace'],
+ 'key' => $key,
+ 'item' => $context['item'],
+ );
} elseif (is_array($context['item']) && array_key_exists($token, $context['item'])) {
$items = $context['item'][$token];
if (!is_array($items)) {
@@ -470,13 +477,6 @@ function extract($path, $data = null, $options = array()) {
'item' => $item,
);
}
- } elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.')) {
- $context['trace'][] = $key;
- $matches[] = array(
- 'trace' => $context['trace'],
- 'key' => $key,
- 'item' => $context['item'],
- );
}
}
if ($conditions) {
6 cake/libs/view/helpers/form.php
View
@@ -678,7 +678,9 @@ function inputs($fields = null, $blacklist = null) {
* ### Options
*
* See each field type method for more information. Any options that are part of
- * $attributes or $options for the different **type** methods can be included in `$options` for input().
+ * $attributes or $options for the different **type** methods can be included in `$options` for input().i
+ * Additionally, any unknown keys that are not in the list below, or part of the selected type's options
+ * will be treated as a regular html attribute for the generated input.
*
* - `type` - Force the type of widget you want. e.g. `type => 'select'`
* - `label` - Either a string label, or an array of options for the label. See FormHelper::label()
@@ -1454,7 +1456,7 @@ function select($fieldName, $options = array(), $selected = null, $attributes =
$selected = $attributes['value'];
}
- if (isset($attributes) && array_key_exists('multiple', $attributes)) {
+ if (!empty($attributes['multiple'])) {
$style = ($attributes['multiple'] === 'checkbox') ? 'checkbox' : null;
$template = ($style) ? 'checkboxmultiplestart' : 'selectmultiplestart';
$tag = $this->Html->tags[$template];
36 cake/libs/view/helpers/time.php
View
@@ -33,7 +33,7 @@ class TimeHelper extends AppHelper {
* Converts a string representing the format for the function strftime and returns a
* windows safe and i18n aware format.
*
- * @param string $format Format with specifiers for strftime function.
+ * @param string $format Format with specifiers for strftime function.
* Accepts the special specifier %S which mimics th modifier S for date()
* @param string UNIX timestamp
* @return string windows safe and date() function compatible format for strftime
@@ -343,7 +343,7 @@ function isThisYear($dateString, $userOffset = null) {
* @return boolean True if datetime string was yesterday
* @access public
* @link http://book.cakephp.org/view/1472/Testing-Time
- *
+ *
*/
function wasYesterday($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
@@ -589,33 +589,33 @@ function timeAgoInWords($dateTime, $options = array()) {
} else {
if ($years > 0) {
// years and months and days
- $relativeDate .= ($relativeDate ? ', ' : '') . $years . ' ' . __n('year', 'years', $years, true);
- $relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true) : '';
- $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
- $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d year', '%d years', $years, true), $years);
+ $relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months) : '';
+ $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
+ $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($months) > 0) {
// months, weeks and days
- $relativeDate .= ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true);
- $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
- $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months);
+ $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
+ $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($weeks) > 0) {
// weeks and days
- $relativeDate .= ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true);
- $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks);
+ $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($days) > 0) {
// days and hours
- $relativeDate .= ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true);
- $relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true) : '';
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days);
+ $relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours) : '';
} elseif (abs($hours) > 0) {
// hours and minutes
- $relativeDate .= ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true);
- $relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true) : '';
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours);
+ $relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes) : '';
} elseif (abs($minutes) > 0) {
// minutes only
- $relativeDate .= ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true);
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes);
} else {
// seconds only
- $relativeDate .= ($relativeDate ? ', ' : '') . $seconds . ' ' . __n('second', 'seconds', $seconds, true);
+ $relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d second', '%d seconds', $seconds, true), $seconds);
}
if (!$backwards) {
@@ -644,7 +644,7 @@ function relativeTime($dateTime, $options = array()) {
/**
* Returns true if specified datetime was within the interval specified, else false.
*
- * @param mixed $timeInterval the numeric value with space then time type.
+ * @param mixed $timeInterval the numeric value with space then time type.
* Example of valid types: 6 hours, 2 days, 1 minute.
* @param mixed $dateString the datestring or unix timestamp to compare
* @param int $userOffset User's offset from GMT (in hours)
11 cake/libs/view/helpers/xml.php
View
@@ -38,6 +38,8 @@ class XmlHelper extends AppHelper {
*/
var $encoding = 'UTF-8';
+ var $Xml;
+ var $XmlElement;
/**
* Constructor
*
@@ -136,7 +138,7 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
if (!$endTag) {
- $this->Xml =& $elem;
+ $this->XmlElement =& $elem;
}
return $out;
}
@@ -148,9 +150,10 @@ function elem($name, $attrib = array(), $content = null, $endTag = true) {
* @access public
*/
function closeElem() {
- $name = $this->Xml->name();
- if ($parent =& $this->Xml->parent()) {
- $this->Xml =& $parent;
+ $elem = (empty($this->XmlElement)) ? $this->Xml : $this->XmlElement;
+ $name = $elem->name();
+ if ($parent =& $elem->parent()) {
+ $this->XmlElement =& $parent;
}
return '</' . $name . '>';
}
47 cake/libs/xml.php
View
@@ -687,11 +687,11 @@ function toString($options = array(), $depth = 0) {
*/
function toArray($camelize = true) {
$out = $this->attributes;
- $multi = null;
foreach ($this->children as $child) {
$key = $camelize ? Inflector::camelize($child->name) : $child->name;
+ $leaf = false;
if (is_a($child, 'XmlTextNode')) {
$out['value'] = $child->value;
continue;
@@ -700,47 +700,34 @@ function toArray($camelize = true) {
if ($child->attributes) {
$value = array_merge(array('value' => $value), $child->attributes);
}
- if (isset($out[$child->name]) || isset($multi[$key])) {
- if (!isset($multi[$key])) {
- $multi[$key] = array($out[$child->name]);
- unset($out[$child->name]);
- }
- $multi[$key][] = $value;
- } else {
- $out[$child->name] = $value;
+ if (count($child->children) == 1) {
+ $leaf = true;
}
- continue;
} elseif (count($child->children) === 0 && $child->value == '') {
$value = $child->attributes;
- if (isset($out[$key]) || isset($multi[$key])) {
- if (!isset($multi[$key])) {
- $multi[$key] = array($out[$key]);
- //unset($out[$key]);
- }
- $multi[$key][] = $value;
- } elseif (!empty($value)) {
- $out[$key] = $value;
- } else {
- $out[$child->name] = $value;
+ if (empty($value)) {
+ $leaf = true;
}
- continue;
} else {
$value = $child->toArray($camelize);
}
- if (!isset($out[$key])) {
- $out[$key] = $value;
- } else {
- if (!is_array($out[$key]) || !isset($out[$key][0])) {
+ if (isset($out[$key])) {
+ if(!isset($out[$key][0]) || !is_array($out[$key]) || !is_int(key($out[$key]))) {
$out[$key] = array($out[$key]);
- }
+ }
$out[$key][] = $value;
+ } elseif (isset($out[$child->name])) {
+ $t = $out[$child->name];
+ unset($out[$child->name]);
+ $out[$key] = array($t);
+ $out[$key][] = $value;
+ } elseif ($leaf) {
+ $out[$child->name] = $value;
+ } else {
+ $out[$key] = $value;
}
}
-
- if (isset($multi)) {
- $out = array_merge($out, $multi);
- }
return $out;
}
2  cake/tests/cases/libs/cache.test.php
View
@@ -227,7 +227,7 @@ function testConfigured() {
* @return void
*/
function testInitSettings() {
- Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
+ Cache::config('for_test', array('engine' => 'File', 'path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array(
104 cake/tests/cases/libs/cake_test_fixture.test.php
View
@@ -65,6 +65,53 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
}
/**
+ * StringFieldsTestFixture class
+ *
+ * @package cake
+ * @subpackage cake.cake.tests.cases.libs
+ */
+class StringsTestFixture extends CakeTestFixture {
+
+/**
+ * name Property
+ *
+ * @var string
+ */
+ var $name = 'Strings';
+
+/**
+ * table property
+ *
+ * @var string
+ */
+ var $table = 'strings';
+
+/**
+ * Fields array
+ *
+ * @var array
+ */
+ var $fields = array(
+ 'id' => array('type' => 'integer', 'key' => 'primary'),
+ 'name' => array('type' => 'string', 'length' => '255'),
+ 'email' => array('type' => 'string', 'length' => '255'),
+ 'age' => array('type' => 'integer', 'default' => 10)
+ );
+
+/**
+ * Records property
+ *
+ * @var array
+ */
+ var $records = array(
+ array('name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 20),
+ array('email' => 'jane.doe@email.com', 'name' => 'Jane Doe', 'age' => 30),
+ array('name' => 'Mark Doe', 'email' => 'mark.doe@email.com')
+ );
+}
+
+
+/**
* CakeTestFixtureImportFixture class
*
* @package cake
@@ -122,7 +169,20 @@ class FixturePrefixTest extends Model {
var $useDbConfig = 'test_suite';
}
-Mock::generate('DboSource', 'FixtureMockDboSource');
+Mock::generate('DboSource', 'BaseFixtureMockDboSource');
+
+class FixtureMockDboSource extends BaseFixtureMockDboSource {
+ var $insertMulti;
+
+ function value($string) {
+ return is_string($string) ? '\'' . $string . '\'' : $string;
+ }
+
+ function insertMulti($table, $fields, $values) {
+ $this->insertMulti = compact('table', 'fields', 'values');
+ return true;
+ }
+}
/**
* Test case for CakeTestFixture
@@ -203,7 +263,7 @@ function testInitDbPrefix() {
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$this->assertEqual($Fixture->table, 'fixture_tests');
-
+
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
@@ -301,7 +361,7 @@ function testImport() {
}
/**
- * test that importing with records works. Make sure to try with postgres as its
+ * test that importing with records works. Make sure to try with postgres as its
* handling of aliases is a workaround at best.
*
* @return void
@@ -334,7 +394,7 @@ function testImportWithRecords() {
$defaultDb->config = $defaultConfig;
- $Source->drop($newTestSuiteDb);
+ $Source->drop($newTestSuiteDb);
}
/**
@@ -364,12 +424,44 @@ function testCreate() {
*/
function testInsert() {
$Fixture =& new CakeTestFixtureTestFixture();
- $this->criticDb->setReturnValue('insertMulti', true);
- $this->criticDb->expectAtLeastOnce('insertMulti');
+ $this->criticDb->insertMulti = array();
$return = $Fixture->insert($this->criticDb);
+ $this->assertTrue(!empty($this->criticDb->insertMulti));
$this->assertTrue($this->criticDb->fullDebug);
$this->assertTrue($return);
+ $this->assertEqual('fixture_tests', $this->criticDb->insertMulti['table']);
+ $this->assertEqual(array('name', 'created'), $this->criticDb->insertMulti['fields']);
+ $expected = array(
+ '(\'Gandalf\', \'2009-04-28 19:20:00\')',
+ '(\'Captain Picard\', \'2009-04-28 19:20:00\')',
+ '(\'Chewbacca\', \'2009-04-28 19:20:00\')'
+ );
+ $this->assertEqual($expected, $this->criticDb->insertMulti['values']);
+ }
+
+/**
+ * test the insert method
+ *
+ * @access public
+ * @return void
+ */
+ function testInsertStrings() {
+ $Fixture =& new StringsTestFixture();
+
+ $this->criticDb->insertMulti = array();
+ $return = $Fixture->insert($this->criticDb);
+ $this->assertTrue(!empty($this->criticDb->insertMulti));
+ $this->assertTrue($this->criticDb->fullDebug);
+ $this->assertTrue($return);
+ $this->assertEqual('strings', $this->criticDb->insertMulti['table']);
+ $this->assertEqual(array('name', 'email', 'age'), $this->criticDb->insertMulti['fields']);
+ $expected = array(
+ '(\'John Doe\', \'john.doe@email.com\', 20)',
+ '(\'Jane Doe\', \'jane.doe@email.com\', 30)',
+ '(\'Mark Doe\', \'mark.doe@email.com\', NULL)',
+ );
+ $this->assertEqual($expected, $this->criticDb->insertMulti['values']);
}
/**
18 cake/tests/cases/libs/controller/components/cookie.test.php
View
@@ -451,6 +451,24 @@ function testNoErrorOnNonArrayData() {
}
/**
+ * test that deleting a top level keys kills the child elements too.
+ *
+ * @return void
+ */
+ function testDeleteRemovesChildren() {
+ $_COOKIE['CakeTestCookie'] = array(
+ 'User' => array('email' => 'example@example.com', 'name' => 'mark'),
+ 'other' => 'value'
+ );
+ $this->Controller->Cookie->startup();
+ $this->assertEqual('mark', $this->Controller->Cookie->read('User.name'));
+
+ $this->Controller->Cookie->delete('User');
+ $this->assertFalse($this->Controller->Cookie->read('User.email'));
+ $this->Controller->Cookie->destroy();
+ }
+
+/**
* encrypt method
*
* @param mixed $value
34 cake/tests/cases/libs/set.test.php
View
@@ -939,6 +939,40 @@ function testExtract() {
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($result, $expected);
+
+ $data = array(
+ array(
+ 'Category' => array(
+ 'id' => 1,
+ 'name' => 'First'
+ ),
+ 0 => array(
+ 'value' => 50
+ )
+ ),
+ array(
+ 'Category' => array(
+ 'id' => 2,
+ 'name' => 'Second'
+ ),
+ 0 => array(
+ 'value' => 60
+ )
+ )
+ );
+ $expected = array(
+ array(
+ 'Category' => array(
+ 'id' => 1,
+ 'name' => 'First'
+ ),
+ 0 => array(
+ 'value' => 50
+ )
+ )
+ );
+ $result = Set::extract('/Category[id=1]/..', $data);
+ $this->assertEqual($result, $expected);
}
/**
20 cake/tests/cases/libs/view/helpers/form.test.php
View
@@ -3360,6 +3360,26 @@ function testSelectMultiple() {
'/select'
);
$this->assertTags($result, $expected);
+
+ $result = $this->Form->select(
+ 'Model.multi_field', $options, array(0, 1), array('multiple' => false)
+ );
+ $expected = array(
+ 'select' => array(
+ 'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField'
+ ),
+ array('option' => array('value' => '0', 'selected' => 'selected')),
+ 'first',
+ '/option',
+ array('option' => array('value' => '1', 'selected' => 'selected')),
+ 'second',
+ '/option',
+ array('option' => array('value' => '2')),
+ 'third',
+ '/option',
+ '/select'
+ );
+ $this->assertTags($result, $expected);
}
/**
13 cake/tests/cases/libs/view/helpers/xml.test.php
View
@@ -159,7 +159,8 @@ function testRenderElementWithNamespace() {
$result .= $this->Xml->closeElem();
$this->assertEqual($result, $expected);
}
- /**
+
+/**
* testRenderElementWithComplexContent method
*
* @access public
@@ -284,4 +285,14 @@ function testHeader() {
$expected = '<?xml encoding="UTF-8" someOther="value" ?>';
$this->assertIdentical($result, $expected);
}
+
+/**
+ * test that calling elem() and then header() doesn't break
+ *
+ * @return void
+ */
+ function testElemThenHeader() {
+ $this->Xml->elem('test', array(), 'foo', false);
+ $this->assertPattern('/<\?xml/', $this->Xml->header());
+ }
}
190 cake/tests/cases/libs/xml.test.php
View
@@ -1434,4 +1434,194 @@ function testMemoryLeakInConstructor() {
$end = memory_get_usage();
$this->assertWithinMargin($start, $end, 3600, 'Memory leaked %s');
}
+
+/**
+ * Test toArray with alternate inputs.
+ *
+ * @return void
+ */
+ function testToArrayAlternate() {
+ $sXml =
+ '<t1>
+ <t2>A</t2>
+ <t2><t3>AAA</t3>B</t2>
+ <t2>C</t2>
+ </t1>';
+ $xml = new Xml($sXml);
+ $result = $xml->toArray();
+ $expected = array(
+ 'T1' => array(
+ 'T2' => array(
+ 'A',
+ array('t3' => 'AAA', 'value' => 'B'),
+ 'C'
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+ $result = $xml->toArray(false);
+ $expected = array(
+ 't1' => array(
+ 't2' => array(
+ 'A',
+ array('t3' => 'AAA', 'value' => 'B'),
+ 'C'
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+ $sXml =
+ '<t1>
+ <t2>A</t2>
+ <t2>B</t2>
+ <t2>
+ <t3>CCC</t3>
+ </t2>
+ </t1>';
+ $xml = new Xml($sXml);
+ $result = $xml->toArray();
+ $expected = array(
+ 'T1' => array(
+ 'T2' => array(
+ 'A',
+ 'B',
+ array('t3' => 'CCC'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+ $result = $xml->toArray(false);
+ $expected = array(
+ 't1' => array(
+ 't2' => array(
+ 'A',
+ 'B',
+ array('t3' => 'CCC'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+ $sXml =
+ '<t1>
+ <t2>A</t2>
+ <t2></t2>
+ <t2>C</t2>
+ </t1>';
+ $xml = new Xml($sXml);
+ $result = $xml->toArray();
+ $expected = array(
+ 'T1' => array(
+ 'T2' => array(
+ 'A',
+ array(),
+ 'C'
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+ $result = $xml->toArray(false);
+ $expected = array(
+ 't1' => array(
+ 't2' => array(
+ 'A',
+ array(),
+ 'C'
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+ $sXml =
+ '<stuff>
+ <foo name="abc-16" profile-id="Default" />
+ <foo name="abc-17" profile-id="Default" >
+ <bar id="HelloWorld" />
+ </foo>
+ <foo name="abc-asdf" profile-id="Default" />
+ <foo name="cba-1A" profile-id="Default">
+ <bar id="Baz" />
+ </foo>
+ <foo name="cba-2A" profile-id="Default">
+ <bar id="Baz" />
+ </foo>
+ <foo name="qa" profile-id="Default" />
+</stuff>';
+ $xml = new Xml($sXml);
+ $result = $xml->toArray();
+ $expected = array(
+ 'Stuff' => array(
+ 'Foo' => array(
+ array('name' => 'abc-16', 'profile-id' => 'Default'),
+ array('name' => 'abc-17', 'profile-id' => 'Default',
+ 'Bar' => array('id' => 'HelloWorld')),
+ array('name' => 'abc-asdf', 'profile-id' => 'Default'),
+ array('name' => 'cba-1A', 'profile-id' => 'Default',
+ 'Bar' => array('id' => 'Baz')),
+ array('name' => 'cba-2A', 'profile-id' => 'Default',
+ 'Bar' => array('id' => 'Baz')),
+ array('name' => 'qa', 'profile-id' => 'Default'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+ $result = $xml->toArray(false);
+ $expected = array(
+ 'stuff' => array(
+ 'foo' => array(
+ array('name' => 'abc-16', 'profile-id' => 'Default'),
+ array('name' => 'abc-17', 'profile-id' => 'Default',
+ 'bar' => array('id' => 'HelloWorld')),
+ array('name' => 'abc-asdf', 'profile-id' => 'Default'),
+ array('name' => 'cba-1A', 'profile-id' => 'Default',
+ 'bar' => array('id' => 'Baz')),
+ array('name' => 'cba-2A', 'profile-id' => 'Default',
+ 'bar' => array('id' => 'Baz')),
+ array('name' => 'qa', 'profile-id' => 'Default'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+
+ $sXml =
+ '<root>
+ <node name="first" />
+ <node name="second"><subnode name="first sub" /><subnode name="second sub" /></node>
+ <node name="third" />
+</root>';
+ $xml = new Xml($sXml);
+ $result = $xml->toArray();
+ $expected = array(
+ 'Root' => array(
+ 'Node' => array(
+ array('name' => 'first'),
+ array('name' => 'second',
+ 'Subnode' => array(
+ array('name' => 'first sub'),
+ array('name' => 'second sub'))),
+ array('name' => 'third'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+
+ $result = $xml->toArray(false);
+ $expected = array(
+ 'root' => array(
+ 'node' => array(
+ array('name' => 'first'),
+ array('name' => 'second',
+ 'subnode' => array(
+ array('name' => 'first sub'),
+ array('name' => 'second sub'))),
+ array('name' => 'third'),
+ )
+ )
+ );
+ $this->assertIdentical($result, $expected);
+ }
+
}
16 cake/tests/lib/cake_test_fixture.php
View
@@ -69,7 +69,7 @@ function __construct() {
function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
$import = array_merge(
- array('connection' => 'default', 'records' => false),
+ array('connection' => 'default', 'records' => false),
is_array($this->import) ? $this->import : array('model' => $this->import)
);
@@ -175,9 +175,18 @@ function insert(&$db) {
$values = array();
if (isset($this->records) && !empty($this->records)) {
+ $fields = array();
+ foreach($this->records as $record) {
+ $fields = array_merge($fields, array_keys(array_intersect_key($record, $this->fields)));
+ }
+ $fields = array_unique($fields);
+ $default = array_fill_keys($fields, null);
foreach ($this->records as $record) {
- $fields = array_keys($record);
- $values[] = '(' . implode(', ', array_map(array(&$db, 'value'), array_values($record))) . ')';
+ $recordValues = array();
+ foreach(array_merge($default, array_map(array(&$db, 'value'), $record)) as $value) {
+ $recordValues[] = is_null($value) ? 'NULL' : $value;
+ }
+ $values[] = '(' . implode(', ', $recordValues) . ')';
}
return $db->insertMulti($this->table, $fields, $values);
}
@@ -185,6 +194,7 @@ function insert(&$db) {
}
}
+
/**
* Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after
* truncate.
Please sign in to comment.
Something went wrong with that request. Please try again.