mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making a bunch of properties public so containable can hack around. Need to refactor and fix visibility issues.
Fixing failing tests in containable.
This commit is contained in:
parent
10c358742b
commit
df21d19c4c
3 changed files with 47 additions and 22 deletions
|
@ -96,7 +96,10 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
*/
|
*/
|
||||||
public function beforeFind($Model, $query) {
|
public function beforeFind($Model, $query) {
|
||||||
$reset = (isset($query['reset']) ? $query['reset'] : true);
|
$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();
|
$contain = array();
|
||||||
if (isset($this->runtime[$Model->alias]['contain'])) {
|
if (isset($this->runtime[$Model->alias]['contain'])) {
|
||||||
$contain = $this->runtime[$Model->alias]['contain'];
|
$contain = $this->runtime[$Model->alias]['contain'];
|
||||||
|
@ -105,7 +108,10 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
if (isset($query['contain'])) {
|
if (isset($query['contain'])) {
|
||||||
$contain = array_merge($contain, (array)$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) {
|
if ($noContain) {
|
||||||
$query['recursive'] = -1;
|
$query['recursive'] = -1;
|
||||||
}
|
}
|
||||||
|
@ -177,6 +183,7 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
$autoFields = ($this->settings[$Model->alias]['autoFields']
|
$autoFields = ($this->settings[$Model->alias]['autoFields']
|
||||||
&& !in_array($Model->findQueryType, array('list', 'count'))
|
&& !in_array($Model->findQueryType, array('list', 'count'))
|
||||||
&& !empty($query['fields']));
|
&& !empty($query['fields']));
|
||||||
|
|
||||||
if (!$autoFields) {
|
if (!$autoFields) {
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +271,7 @@ class ContainableBehavior extends ModelBehavior {
|
||||||
$Model->resetAssociations();
|
$Model->resetAssociations();
|
||||||
if (!empty($Model->__backInnerAssociation)) {
|
if (!empty($Model->__backInnerAssociation)) {
|
||||||
$assocs = $Model->__backInnerAssociation;
|
$assocs = $Model->__backInnerAssociation;
|
||||||
unset($Model->__backInnerAssociation);
|
$Model->__backInnerAssociation = array();
|
||||||
foreach ($assocs as $currentModel) {
|
foreach ($assocs as $currentModel) {
|
||||||
$this->resetBindings($Model->$currentModel);
|
$this->resetBindings($Model->$currentModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,7 +330,13 @@ class Model extends Object {
|
||||||
* @var array
|
* @var array
|
||||||
* @access private
|
* @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.
|
* The ID of the model record that was last inserted.
|
||||||
|
@ -2139,6 +2145,7 @@ class Model extends Object {
|
||||||
array(&$this, $query),
|
array(&$this, $query),
|
||||||
array('break' => true, 'breakOn' => false, 'modParams' => 1)
|
array('break' => true, 'breakOn' => false, 'modParams' => 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = (is_array($return)) ? $return : $query;
|
$query = (is_array($return)) ? $return : $query;
|
||||||
|
|
||||||
if ($return === false) {
|
if ($return === false) {
|
||||||
|
|
|
@ -35,7 +35,8 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $fixtures = array(
|
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'
|
'core.comment', 'core.featured', 'core.tag', 'core.user'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -43,10 +44,11 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
* Method executed before each test
|
* Method executed before each test
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function setUp() {
|
||||||
$this->User =& ClassRegistry::init('User');
|
parent::setUp();
|
||||||
$this->Article =& ClassRegistry::init('Article');
|
$this->User = ClassRegistry::init('User');
|
||||||
$this->Tag =& ClassRegistry::init('Tag');
|
$this->Article = ClassRegistry::init('Article');
|
||||||
|
$this->Tag = ClassRegistry::init('Tag');
|
||||||
|
|
||||||
$this->User->bindModel(array(
|
$this->User->bindModel(array(
|
||||||
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
|
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
|
||||||
|
@ -67,12 +69,11 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
* Method executed after each test
|
* Method executed after each test
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function endTest() {
|
public function tearDown() {
|
||||||
unset($this->Article);
|
unset($this->Article);
|
||||||
unset($this->User);
|
unset($this->User);
|
||||||
unset($this->Tag);
|
unset($this->Tag);
|
||||||
|
parent::tearDown();
|
||||||
ClassRegistry::flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,15 +117,23 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
|
$r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
|
||||||
$this->assertEqual(array_keys($r), array('Comment', 'Article'));
|
$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->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'));
|
$r = $this->__containments($this->Article, array('Comment.User'));
|
||||||
$this->assertEqual(array_keys($r), array('User', 'Comment', 'Article'));
|
$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())));
|
$result = Set::extract('/User/keep', $r);
|
||||||
$this->assertEqual(array_shift(Set::extract('/Article/keep', $r)), array('keep' => array('Comment' => array())));
|
$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(
|
$r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
|
||||||
'Attachment' => array('conditions' => array('Attachment.id >' => 1))
|
'Attachment' => array('conditions' => array('Attachment.id >' => 1))
|
||||||
|
@ -3189,10 +3198,11 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testPaginate() {
|
function testPaginate() {
|
||||||
$Controller = new Controller();
|
App::import('Core', 'Controller');
|
||||||
|
$Controller = new Controller($this->getMock('CakeRequest'));
|
||||||
$Controller->uses = array('Article');
|
$Controller->uses = array('Article');
|
||||||
$Controller->passedArgs[] = '1';
|
$Controller->passedArgs[] = '1';
|
||||||
$Controller->params['url'] = array();
|
$Controller->request->params['url'] = array();
|
||||||
$Controller->constructClasses();
|
$Controller->constructClasses();
|
||||||
|
|
||||||
$Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
|
$Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
|
||||||
|
@ -3396,6 +3406,7 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
'conditions' => array('Article.id' => 1),
|
'conditions' => array('Article.id' => 1),
|
||||||
'contain' => array('ArticlesTag')
|
'contain' => array('ArticlesTag')
|
||||||
));
|
));
|
||||||
|
|
||||||
$expected = array('Article', 'ArticlesTag');
|
$expected = array('Article', 'ArticlesTag');
|
||||||
$this->assertTrue(!empty($result));
|
$this->assertTrue(!empty($result));
|
||||||
$this->assertEqual('First Article', $result['Article']['title']);
|
$this->assertEqual('First Article', $result['Article']['title']);
|
||||||
|
@ -3605,7 +3616,7 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test2');
|
$db = ConnectionManager::getDataSource('test2');
|
||||||
$this->_fixtures[$this->_fixtureClassMap['User']]->create($db);
|
$this->_fixtures[$this->_fixtureClassMap['User']]->create($db);
|
||||||
$this->_fixtures[$this->_fixtureClassMap['User']]->insert($db);
|
$this->_fixtures[$this->_fixtureClassMap['User']]->insert($db);
|
||||||
|
|
||||||
|
@ -3641,7 +3652,7 @@ class ContainableBehaviorTest extends CakeTestCase {
|
||||||
$result = $this->Article->find('all', array(
|
$result = $this->Article->find('all', array(
|
||||||
'conditions' => array('Article.id' => 999999999)
|
'conditions' => array('Article.id' => 999999999)
|
||||||
));
|
));
|
||||||
$this->assertEqual($result, array(), 'Should be empty.');
|
$this->assertEmpty($result, 'Should be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue