Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,23 +2,23 @@
/**
* ContainableBehaviorTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model.Behavior
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Model', 'Model');
App::uses('AppModel', 'Model');
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
/**
@ -43,6 +43,7 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* Method executed before each test
*
* @return void
*/
public function setUp() {
parent::setUp();
@ -60,14 +61,15 @@ class ContainableBehaviorTest extends CakeTestCase {
'hasAndBelongsToMany' => array('Article')
), false);
$this->User->Behaviors->attach('Containable');
$this->Article->Behaviors->attach('Containable');
$this->Tag->Behaviors->attach('Containable');
$this->User->Behaviors->load('Containable');
$this->Article->Behaviors->load('Containable');
$this->Tag->Behaviors->load('Containable');
}
/**
* Method executed after each test
*
* @return void
*/
public function tearDown() {
unset($this->Article);
@ -152,7 +154,7 @@ class ContainableBehaviorTest extends CakeTestCase {
* @return void
*/
public function testInvalidContainments() {
$r = $this->_containments($this->Article, array('Comment', 'InvalidBinding'));
$this->_containments($this->Article, array('Comment', 'InvalidBinding'));
}
/**
@ -161,8 +163,8 @@ class ContainableBehaviorTest extends CakeTestCase {
* @return void
*/
public function testInvalidContainmentsNoNotices() {
$this->Article->Behaviors->attach('Containable', array('notices' => false));
$r = $this->_containments($this->Article, array('Comment', 'InvalidBinding'));
$this->Article->Behaviors->load('Containable', array('notices' => false));
$this->_containments($this->Article, array('Comment', 'InvalidBinding'));
}
/**
@ -243,7 +245,7 @@ class ContainableBehaviorTest extends CakeTestCase {
* @return void
*/
public function testBeforeFindWithNonExistingBinding() {
$r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
$this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
}
/**
@ -261,6 +263,30 @@ class ContainableBehaviorTest extends CakeTestCase {
$this->assertFalse(Set::matches('/Comment/User', $r));
}
/**
* testContainFindList method
*
* @return void
*/
public function testContainFindList() {
$this->Article->contain('Comment.User');
$result = $this->Article->find('list');
$expected = array(
1 => 'First Article',
2 => 'Second Article',
3 => 'Third Article'
);
$this->assertEquals($expected, $result);
$result = $this->Article->find('list', array('fields' => array('Article.id', 'User.id'), 'contain' => array('User')));
$expected = array(
1 => '1',
2 => '3',
3 => '1'
);
$this->assertEquals($expected, $result);
}
/**
* Test that mixing contain() and the contain find option.
*
@ -657,6 +683,65 @@ class ContainableBehaviorTest extends CakeTestCase {
);
$this->assertEquals($expected, $result);
$this->Article->contain(array('User' => array('id', 'ArticleFeatured')));
$result = $this->Article->find('all', array('recursive' => 2));
$expected = array(
array(
'Article' => array(
'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
'User' => array(
'id' => 1,
'ArticleFeatured' => array(
array(
'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
array(
'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
)
)
)
),
array(
'Article' => array(
'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
),
'User' => array(
'id' => 3,
'ArticleFeatured' => array(
array(
'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
)
)
)
),
array(
'Article' => array(
'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
),
'User' => array(
'id' => 1,
'ArticleFeatured' => array(
array(
'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
),
array(
'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
)
)
)
)
);
$this->assertEquals($expected, $result);
$this->Article->contain(array('User' => array('ArticleFeatured', 'Comment')));
$result = $this->Article->find('all', array('recursive' => 2));
$expected = array(
@ -3216,7 +3301,7 @@ class ContainableBehaviorTest extends CakeTestCase {
* @return void
*/
public function testOriginalAssociations() {
$this->Article->Comment->Behaviors->attach('Containable');
$this->Article->Comment->Behaviors->load('Containable');
$options = array(
'conditions' => array(
@ -3228,7 +3313,7 @@ class ContainableBehaviorTest extends CakeTestCase {
$firstResult = $this->Article->Comment->find('all', $options);
$dummyResult = $this->Article->Comment->find('all', array(
$this->Article->Comment->find('all', array(
'conditions' => array(
'User.user' => 'mariano'
),
@ -3305,6 +3390,7 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* testResetAddedAssociation method
*
* @return void
*/
public function testResetAddedAssociation() {
$this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
@ -3331,9 +3417,9 @@ class ContainableBehaviorTest extends CakeTestCase {
$this->JoinB = ClassRegistry::init('JoinB');
$this->JoinC = ClassRegistry::init('JoinC');
$this->JoinA->Behaviors->attach('Containable');
$this->JoinB->Behaviors->attach('Containable');
$this->JoinC->Behaviors->attach('Containable');
$this->JoinA->Behaviors->load('Containable');
$this->JoinB->Behaviors->load('Containable');
$this->JoinC->Behaviors->load('Containable');
$this->JoinA->JoinB->find('all', array('contain' => array('JoinA')));
$this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false);
@ -3346,11 +3432,12 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* testResetAssociation method
*
* @return void
*/
public function testResetAssociation() {
$this->Article->Behaviors->attach('Containable');
$this->Article->Comment->Behaviors->attach('Containable');
$this->Article->User->Behaviors->attach('Containable');
$this->Article->Behaviors->load('Containable');
$this->Article->Comment->Behaviors->load('Containable');
$this->Article->User->Behaviors->load('Containable');
$initialOptions = array(
'conditions' => array(
@ -3377,6 +3464,7 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* testResetDeeperHasOneAssociations method
*
* @return void
*/
public function testResetDeeperHasOneAssociations() {
$this->Article->User->unbindModel(array(
@ -3437,23 +3525,24 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* testResetMultipleHabtmAssociations method
*
* @return void
*/
public function testResetMultipleHabtmAssociations() {
$articleHabtm = array(
'hasAndBelongsToMany' => array(
'Tag' => array(
'className' => 'Tag',
'joinTable' => 'articles_tags',
'foreignKey' => 'article_id',
'className' => 'Tag',
'joinTable' => 'articles_tags',
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id'
),
'ShortTag' => array(
'className' => 'Tag',
'joinTable' => 'articles_tags',
'foreignKey' => 'article_id',
'className' => 'Tag',
'joinTable' => 'articles_tags',
'foreignKey' => 'article_id',
'associationForeignKey' => 'tag_id',
// LENGHT function mysql-only, using LIKE does almost the same
'conditions' => "ShortTag.tag LIKE '???'"
// LENGTH function mysql-only, using LIKE does almost the same
'conditions' => "ShortTag.tag LIKE '???'"
)
)
);
@ -3527,6 +3616,8 @@ class ContainableBehaviorTest extends CakeTestCase {
/**
* test that bindModel and unbindModel work with find() calls in between.
*
* @return void
*/
public function testBindMultipleTimesWithFind() {
$binding = array(
@ -3647,11 +3738,10 @@ class ContainableBehaviorTest extends CakeTestCase {
if (!is_array($Model)) {
$result = $Model->containments($contain);
return $this->_containments($result['models']);
} else {
$result = $Model;
foreach ($result as $i => $containment) {
$result[$i] = array_diff_key($containment, array('instance' => true));
}
}
$result = $Model;
foreach ($result as $i => $containment) {
$result[$i] = array_diff_key($containment, array('instance' => true));
}
return $result;
}
@ -3671,7 +3761,7 @@ class ContainableBehaviorTest extends CakeTestCase {
'hasAndBelongsToMany' => array()
), $expected);
foreach ($expected as $binding => $expect) {
$this->assertEquals(array_keys($Model->$binding), $expect);
$this->assertEquals($expect, array_keys($Model->$binding));
}
}
}