Skip to content
Permalink
Browse files

Making a bunch of properties public so containable can hack around. N…

…eed to refactor and fix visibility issues.

Fixing failing tests in containable.
  • Loading branch information...
markstory committed Dec 12, 2010
1 parent 10c3587 commit df21d19c4ca2f5b89e36fbc5dc006b6298ce916f
@@ -96,7 +96,10 @@ public function setup($Model, $settings = array()) {
*/
public function beforeFind($Model, $query) {
$reset = (isset($query['reset']) ? $query['reset'] : true);
$noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
$noContain = (
(isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) ||
(isset($query['contain']) && empty($query['contain']))
);
$contain = array();
if (isset($this->runtime[$Model->alias]['contain'])) {
$contain = $this->runtime[$Model->alias]['contain'];
@@ -105,7 +108,10 @@ public function beforeFind($Model, $query) {
if (isset($query['contain'])) {
$contain = array_merge($contain, (array)$query['contain']);
}
if ($noContain || !$contain || in_array($contain, array(null, false), true) || (isset($contain[0]) && $contain[0] === null)) {
if (
$noContain || !$contain || in_array($contain, array(null, false), true) ||
(isset($contain[0]) && $contain[0] === null)
) {
if ($noContain) {
$query['recursive'] = -1;
}
@@ -177,6 +183,7 @@ public function beforeFind($Model, $query) {
$autoFields = ($this->settings[$Model->alias]['autoFields']
&& !in_array($Model->findQueryType, array('list', 'count'))
&& !empty($query['fields']));
if (!$autoFields) {
return $query;
}
@@ -264,7 +271,7 @@ public function resetBindings($Model) {
$Model->resetAssociations();
if (!empty($Model->__backInnerAssociation)) {
$assocs = $Model->__backInnerAssociation;
unset($Model->__backInnerAssociation);
$Model->__backInnerAssociation = array();
foreach ($assocs as $currentModel) {
$this->resetBindings($Model->$currentModel);
}
@@ -330,7 +330,13 @@ class Model extends Object {
* @var array
* @access private
*/
private $__backAssociation = array();
public $__backAssociation = array();
public $__backInnerAssociation = array();
public $__backOriginalAssociation = array();
public $__backContainableAssociation = array();
/**
* The ID of the model record that was last inserted.
@@ -2139,6 +2145,7 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
array(&$this, $query),
array('break' => true, 'breakOn' => false, 'modParams' => 1)
);
$query = (is_array($return)) ? $return : $query;
if ($return === false) {
@@ -2403,7 +2410,7 @@ protected function _findThreaded($state, $query, $results = array()) {
function __filterResults($results, $primary = true) {
$return = $this->Behaviors->trigger(
'afterFind',
array(&$this, $results, $primary),
array(&$this, $results, $primary),
array('modParams' => 1)
);
if ($return !== true) {
@@ -35,18 +35,20 @@ class ContainableBehaviorTest extends CakeTestCase {
* @access public
*/
public $fixtures = array(
'core.article', 'core.article_featured', 'core.article_featureds_tags', 'core.articles_tag', 'core.attachment', 'core.category',
'core.article', 'core.article_featured', 'core.article_featureds_tags',
'core.articles_tag', 'core.attachment', 'core.category',
'core.comment', 'core.featured', 'core.tag', 'core.user'
);
/**
* Method executed before each test
*
*/
public function startTest() {
$this->User =& ClassRegistry::init('User');
$this->Article =& ClassRegistry::init('Article');
$this->Tag =& ClassRegistry::init('Tag');
public function setUp() {
parent::setUp();
$this->User = ClassRegistry::init('User');
$this->Article = ClassRegistry::init('Article');
$this->Tag = ClassRegistry::init('Tag');
$this->User->bindModel(array(
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
@@ -67,12 +69,11 @@ public function startTest() {
* Method executed after each test
*
*/
public function endTest() {
public function tearDown() {
unset($this->Article);
unset($this->User);
unset($this->Tag);
ClassRegistry::flush();
parent::tearDown();
}
/**
@@ -116,15 +117,23 @@ function testContainments() {
$r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
$this->assertEqual(array_keys($r), array('Comment', 'Article'));
$this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array()));
$result = Set::extract('/Comment/keep', $r);
$this->assertEqual(array_shift($result), array('keep' => array()));
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
$this->assertEqual(array_shift(Set::extract('/Article/keep/Comment/.', $r)), array('limit' => 1));
$result = Set::extract('/Article/keep/Comment/.', $r);
$this->assertEqual(array_shift($result), array('limit' => 1));
$r = $this->__containments($this->Article, array('Comment.User'));
$this->assertEqual(array_keys($r), array('User', 'Comment', 'Article'));
$this->assertEqual(array_shift(Set::extract('/User/keep', $r)), array('keep' => array()));
$this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array('User' => array())));
$this->assertEqual(array_shift(Set::extract('/Article/keep', $r)), array('keep' => array('Comment' => array())));
$result = Set::extract('/User/keep', $r);
$this->assertEqual(array_shift($result), array('keep' => array()));
$result = Set::extract('/Comment/keep', $r);
$this->assertEqual(array_shift($result), array('keep' => array('User' => array())));
$result = Set::extract('/Article/keep', $r);
$this->assertEqual(array_shift($result), array('keep' => array('Comment' => array())));
$r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
'Attachment' => array('conditions' => array('Attachment.id >' => 1))
@@ -3189,10 +3198,11 @@ function testOtherFinds() {
* @return void
*/
function testPaginate() {
$Controller = new Controller();
App::import('Core', 'Controller');
$Controller = new Controller($this->getMock('CakeRequest'));
$Controller->uses = array('Article');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->request->params['url'] = array();
$Controller->constructClasses();
$Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
@@ -3396,6 +3406,7 @@ public function testResetAddedAssociation() {
'conditions' => array('Article.id' => 1),
'contain' => array('ArticlesTag')
));
$expected = array('Article', 'ArticlesTag');
$this->assertTrue(!empty($result));
$this->assertEqual('First Article', $result['Article']['title']);
@@ -3605,7 +3616,7 @@ function testAutoFieldsWithMultipleDatabases() {
return;
}
$db =& ConnectionManager::getDataSource('test2');
$db = ConnectionManager::getDataSource('test2');
$this->_fixtures[$this->_fixtureClassMap['User']]->create($db);
$this->_fixtures[$this->_fixtureClassMap['User']]->insert($db);
@@ -3641,7 +3652,7 @@ function testFindAllReturn() {
$result = $this->Article->find('all', array(
'conditions' => array('Article.id' => 999999999)
));
$this->assertEqual($result, array(), 'Should be empty.');
$this->assertEmpty($result, 'Should be empty.');
}
/**

0 comments on commit df21d19

Please sign in to comment.
You can’t perform that action at this time.