Merge remote branch 'origin/1.2' into 1.3

Conflicts:
	cake/libs/cake_session.php
	cake/libs/controller/components/session.php
	cake/libs/model/model.php
	cake/libs/router.php
This commit is contained in:
Mark Story 2010-03-27 11:48:49 -04:00
commit 0c29fd0094
4 changed files with 130 additions and 54 deletions

View file

@ -2688,7 +2688,7 @@ class Model extends Overloadable {
$field = $this->primaryKey;
}
$db =& ConnectionManager::getDataSource($this->useDbConfig);
if (strpos($field, $db->name($alias)) === 0) {
if (strpos($field, $db->name($alias) . '.') === 0) {
return $field;
}
return $db->name($alias . '.' . $field);

View file

@ -437,7 +437,8 @@ class Set {
$items = array($items);
} elseif (!isset($items[0])) {
$current = current($items);
if ((is_array($current) && count($items) <= 1) || !is_array($current)) {
$currentKey = key($items);
if (!is_array($current) || (is_array($current) && count($items) <= 1 && !is_numeric($currentKey))) {
$items = array($items);
}
}

View file

@ -20,6 +20,27 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once dirname(__FILE__) . DS . 'model.test.php';
App::import('Core', 'DboSource');
/**
* DboMock class
* A Dbo Source driver to mock a connection and a identity name() method
*/
class DboMock extends DboSource {
/**
* Returns the $field without modifications
*/
function name($field) {
return $field;
}
/**
* Returns true to fake a database connection
*/
function connect() {
return true;
}
}
/**
* ModelIntegrationTest
@ -1875,5 +1896,36 @@ class ModelIntegrationTest extends BaseModelTest {
$this->assertEqual($FeaturedModel->create($data), $expected);
}
/**
* testEscapeField to prove it escapes the field well even when it has part of the alias on it
* @see ttp://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/473-escapefield-doesnt-consistently-prepend-modelname
*
* @access public
* @return void
*/
function testEscapeField() {
$TestModel =& new Test();
$db =& $TestModel->getDataSource();
$result = $TestModel->escapeField('test_field');
$expected = $db->name('Test.test_field');
$this->assertEqual($result, $expected);
$result = $TestModel->escapeField('TestField');
$expected = $db->name('Test.TestField');
$this->assertEqual($result, $expected);
$result = $TestModel->escapeField('DomainHandle', 'Domain');
$expected = $db->name('Domain.DomainHandle');
$this->assertEqual($result, $expected);
ConnectionManager::create('mock', array('driver' => 'mock'));
$TestModel->setDataSource('mock');
$db =& $TestModel->getDataSource();
$result = $TestModel->escapeField('DomainHandle', 'Domain');
$expected = $db->name('Domain.DomainHandle');
$this->assertEqual($result, $expected);
}
}
?>

View file

@ -420,43 +420,15 @@ class SetTest extends CakeTestCase {
array('a' => array('II' => array('a' => 3, 'III' => array('a' => array('foo' => 4))))),
);
$nonSequential = array(
'User' => array(
0 => array('id' => 1),
2 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$nonZero = array(
'User' => array(
2 => array('id' => 1),
4 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$expected = array(array('a' => $c[2]['a']));
$r = Set::extract('/a/II[a=3]/..', $c);
$this->assertEqual($r, $expected);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $a), $expected);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');
$expected = array(
array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)
@ -552,30 +524,6 @@ class SetTest extends CakeTestCase {
$r = Set::extract('/User/@*', $tricky);
$this->assertEqual($r, $expected);
$nonZero = array(
1 => array(
'User' => array(
'id' => 1,
'name' => 'John',
)
),
2 => array(
'User' => array(
'id' => 2,
'name' => 'Bob',
)
),
3 => array(
'User' => array(
'id' => 3,
'name' => 'Tony',
)
)
);
$expected = array(1, 2, 3);
$r = Set::extract('/User/id', $nonZero);
$this->assertEqual($r, $expected);
$common = array(
array(
'Article' => array(
@ -1030,6 +978,81 @@ class SetTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* test that extract() still works when arrays don't contain a 0 index.
*
* @return void
*/
function testExtractWithNonZeroArrays() {
$nonZero = array(
1 => array(
'User' => array(
'id' => 1,
'name' => 'John',
)
),
2 => array(
'User' => array(
'id' => 2,
'name' => 'Bob',
)
),
3 => array(
'User' => array(
'id' => 3,
'name' => 'Tony',
)
)
);
$expected = array(1, 2, 3);
$r = Set::extract('/User/id', $nonZero);
$this->assertEqual($r, $expected);
$nonSequential = array(
'User' => array(
0 => array('id' => 1),
2 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$nonZero = array(
'User' => array(
2 => array('id' => 1),
4 => array('id' => 2),
6 => array('id' => 3),
9 => array('id' => 4),
3 => array('id' => 5),
),
);
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual(Set::extract('/User/id', $nonSequential), $expected);
$result = Set::extract('/User/id', $nonZero);
$this->assertEqual($result, $expected, 'Failed non zero array key extract');
$startingAtOne = array(
'Article' => array(
1 => array(
'id' => 1,
'approved' => 1,
),
)
);
$expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1)));
$result = Set::extract('/Article[approved=1]', $startingAtOne);
$this->assertEqual($result, $expected);
}
/**
* testExtractWithArrays method
*