mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-12-17 14:13:58 +01:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* AclNodeTest 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
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DbAcl', 'Controller/Component/Acl');
|
||||
App::uses('AclNode', 'Model');
|
||||
|
||||
|
|
@ -29,14 +29,14 @@ class DbAclNodeTestBase extends AclNode {
|
|||
/**
|
||||
* useDbConfig property
|
||||
*
|
||||
* @var string 'test'
|
||||
* @var string
|
||||
*/
|
||||
public $useDbConfig = 'test';
|
||||
|
||||
/**
|
||||
* cacheSources property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $cacheSources = false;
|
||||
}
|
||||
|
|
@ -48,17 +48,10 @@ class DbAclNodeTestBase extends AclNode {
|
|||
*/
|
||||
class DbAroTest extends DbAclNodeTestBase {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'DbAroTest'
|
||||
*/
|
||||
public $name = 'DbAroTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aros'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'aros';
|
||||
|
||||
|
|
@ -77,17 +70,10 @@ class DbAroTest extends DbAclNodeTestBase {
|
|||
*/
|
||||
class DbAcoTest extends DbAclNodeTestBase {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'DbAcoTest'
|
||||
*/
|
||||
public $name = 'DbAcoTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'acos'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'acos';
|
||||
|
||||
|
|
@ -106,24 +92,17 @@ class DbAcoTest extends DbAclNodeTestBase {
|
|||
*/
|
||||
class DbPermissionTest extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'DbPermissionTest'
|
||||
*/
|
||||
public $name = 'DbPermissionTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aros_acos'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'aros_acos';
|
||||
|
||||
/**
|
||||
* cacheQueries property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $cacheQueries = false;
|
||||
|
||||
|
|
@ -142,17 +121,10 @@ class DbPermissionTest extends CakeTestModel {
|
|||
*/
|
||||
class DbAcoActionTest extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'DbAcoActionTest'
|
||||
*/
|
||||
public $name = 'DbAcoActionTest';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'aco_actions'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'aco_actions';
|
||||
|
||||
|
|
@ -174,14 +146,14 @@ class DbAroUserTest extends CakeTestModel {
|
|||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AuthUser'
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'AuthUser';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'auth_users'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'auth_users';
|
||||
|
||||
|
|
@ -192,9 +164,9 @@ class DbAroUserTest extends CakeTestModel {
|
|||
* @return void
|
||||
*/
|
||||
public function bindNode($ref = null) {
|
||||
if (Configure::read('DbAclbindMode') == 'string') {
|
||||
if (Configure::read('DbAclbindMode') === 'string') {
|
||||
return 'ROOT/admins/Gandalf';
|
||||
} elseif (Configure::read('DbAclbindMode') == 'array') {
|
||||
} elseif (Configure::read('DbAclbindMode') === 'array') {
|
||||
return array('DbAroTest' => array('DbAroTest.model' => 'AuthUser', 'DbAroTest.foreign_key' => 2));
|
||||
}
|
||||
}
|
||||
|
|
@ -209,9 +181,7 @@ class DbAroUserTest extends CakeTestModel {
|
|||
class TestDbAcl extends DbAcl {
|
||||
|
||||
/**
|
||||
* construct method
|
||||
*
|
||||
* @return void
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->Aro = new DbAroTest();
|
||||
|
|
|
|||
|
|
@ -4,19 +4,18 @@
|
|||
*
|
||||
* Test the Acl Behavior
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* 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.
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Test.Case.Model.Behavior
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AclBehavior', 'Model/Behavior');
|
||||
|
|
@ -25,7 +24,6 @@ App::uses('Aro', 'Model');
|
|||
App::uses('AclNode', 'Model');
|
||||
App::uses('DbAcl', 'Model');
|
||||
|
||||
|
||||
/**
|
||||
* Test Person class - self joined model
|
||||
*
|
||||
|
|
@ -33,13 +31,6 @@ App::uses('DbAcl', 'Model');
|
|||
*/
|
||||
class AclPerson extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'AclPerson';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
|
|
@ -94,9 +85,8 @@ class AclPerson extends CakeTestModel {
|
|||
}
|
||||
if (!$motherId) {
|
||||
return null;
|
||||
} else {
|
||||
return array('AclPerson' => array('id' => $motherId));
|
||||
}
|
||||
return array('AclPerson' => array('id' => $motherId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -132,6 +122,7 @@ class AclUser extends CakeTestModel {
|
|||
/**
|
||||
* parentNode
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function parentNode() {
|
||||
return null;
|
||||
|
|
@ -170,6 +161,7 @@ class AclPost extends CakeTestModel {
|
|||
/**
|
||||
* parentNode
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function parentNode() {
|
||||
return null;
|
||||
|
|
@ -234,6 +226,7 @@ class AclBehaviorTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSetup() {
|
||||
parent::setUp();
|
||||
$User = new AclUser();
|
||||
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
|
||||
$this->assertEquals('requester', $User->Behaviors->Acl->settings['User']['type']);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* 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
|
||||
* @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';
|
||||
|
||||
/**
|
||||
|
|
@ -26,7 +28,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
|
@ -68,13 +70,13 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->loadFixtures('TranslateTable', 'Tag', 'TranslatedItem', 'Translate', 'User', 'TranslatedArticle', 'TranslateArticle');
|
||||
$TestModel = new Tag();
|
||||
$TestModel->translateTable = 'another_i18n';
|
||||
$TestModel->Behaviors->attach('Translate', array('title'));
|
||||
$TestModel->Behaviors->load('Translate', array('title'));
|
||||
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||
$this->assertEquals('I18nModel', $translateModel->name);
|
||||
$this->assertEquals('another_i18n', $translateModel->useTable);
|
||||
|
||||
$TestModel = new User();
|
||||
$TestModel->Behaviors->attach('Translate', array('title'));
|
||||
$TestModel->Behaviors->load('Translate', array('title'));
|
||||
$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel);
|
||||
$this->assertEquals('I18nModel', $translateModel->name);
|
||||
$this->assertEquals('i18n', $translateModel->useTable);
|
||||
|
|
@ -230,6 +232,32 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->field('title', array('TranslatedItem.id' => 1));
|
||||
$expected = 'Title #1';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->read('title', 1);
|
||||
$expected = array(
|
||||
'TranslatedItem' => array(
|
||||
'id' => 1,
|
||||
'slug' => 'first_translated',
|
||||
'locale' => 'eng',
|
||||
'title' => 'Title #1',
|
||||
'translated_article_id' => 1,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->read('id, title', 1);
|
||||
$expected = array(
|
||||
'TranslatedItem' => array(
|
||||
'id' => 1,
|
||||
'locale' => 'eng',
|
||||
'title' => 'Title #1',
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -273,6 +301,40 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testLocaleSingleCountWithConditions method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLocaleSingleCountWithConditions() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
$TestModel->locale = 'eng';
|
||||
$result = $TestModel->find('all', array(
|
||||
'conditions' => array('slug' => 'first_translated')
|
||||
));
|
||||
$expected = array(
|
||||
array(
|
||||
'TranslatedItem' => array(
|
||||
'id' => 1,
|
||||
'slug' => 'first_translated',
|
||||
'locale' => 'eng',
|
||||
'title' => 'Title #1',
|
||||
'content' => 'Content #1',
|
||||
'translated_article_id' => 1,
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->find('count', array(
|
||||
'conditions' => array('slug' => 'first_translated')
|
||||
));
|
||||
$expected = 1;
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testLocaleSingleAssociations method
|
||||
*
|
||||
|
|
@ -352,6 +414,33 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test loading fields with 0 as the translated value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchTranslationsWithZero() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$model = new TranslatedItem();
|
||||
$translateModel = $model->translateModel();
|
||||
$translateModel->updateAll(array('content' => "'0'"));
|
||||
$model->locale = 'eng';
|
||||
|
||||
$result = $model->read(null, 1);
|
||||
$expected = array(
|
||||
'TranslatedItem' => array(
|
||||
'id' => 1,
|
||||
'slug' => 'first_translated',
|
||||
'locale' => 'eng',
|
||||
'title' => '0',
|
||||
'content' => '0',
|
||||
'translated_article_id' => 1,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testLocaleMultiple method
|
||||
*
|
||||
|
|
@ -530,6 +619,36 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test saving/deleting with an alias, uses the model name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveDeleteIgnoreAlias() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem(array('alias' => 'SomethingElse'));
|
||||
$TestModel->locale = 'spa';
|
||||
$data = array(
|
||||
'slug' => 'fourth_translated',
|
||||
'title' => 'Leyenda #4',
|
||||
'content' => 'Contenido #4',
|
||||
'translated_article_id' => 1,
|
||||
);
|
||||
$TestModel->create($data);
|
||||
$TestModel->save();
|
||||
$id = $TestModel->id;
|
||||
$result = $TestModel->read();
|
||||
$expected = array($TestModel->alias => array_merge($data, array('id' => $id, 'locale' => 'spa')));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$TestModel->delete($id);
|
||||
$result = $TestModel->translateModel()->find('count', array(
|
||||
'conditions' => array('foreign_key' => $id)
|
||||
));
|
||||
$this->assertEquals(0, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test save multiple locales method
|
||||
*
|
||||
|
|
@ -600,6 +719,54 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertCount(2, $result['Content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveAssociatedAtomic method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveAssociatedAtomic() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
$data = array(
|
||||
'slug' => 'fourth_translated',
|
||||
'title' => array(
|
||||
'eng' => 'Title #4'
|
||||
),
|
||||
'content' => array(
|
||||
'eng' => 'Content #4'
|
||||
),
|
||||
'translated_article_id' => 1,
|
||||
);
|
||||
$Mock = $this->getMockForModel('TranslateTestModel', array('save'));
|
||||
$TestModel->Behaviors->Translate->runtime[$TestModel->alias]['model'] = $Mock;
|
||||
|
||||
$with = array(
|
||||
'TranslateTestModel' => array (
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'content',
|
||||
'locale' => 'eng',
|
||||
'content' => 'Content #4',
|
||||
)
|
||||
);
|
||||
$Mock->expects($this->at(0))->method('save')->with($with, array('atomic' => false));
|
||||
|
||||
$with = array(
|
||||
'TranslateTestModel' => array (
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'title',
|
||||
'locale' => 'eng',
|
||||
'content' => 'Title #4',
|
||||
)
|
||||
);
|
||||
$Mock->expects($this->at(1))->method('save')->with($with, array('atomic' => false));
|
||||
|
||||
$TestModel->create();
|
||||
$TestModel->saveAssociated($data, array('atomic' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that saving only some of the translated fields allows the record to be found again.
|
||||
*
|
||||
|
|
@ -628,6 +795,76 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that all fields are create with partial data + multiple locales.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSavePartialFieldMultipleLocales() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
$TestModel->locale = 'eng';
|
||||
$data = array(
|
||||
'slug' => 'fifth_translated',
|
||||
'title' => array('eng' => 'Title #5', 'spa' => 'Leyenda #5'),
|
||||
);
|
||||
$TestModel->create($data);
|
||||
$TestModel->save();
|
||||
$TestModel->unbindTranslation();
|
||||
|
||||
$translations = array('title' => 'Title', 'content' => 'Content');
|
||||
$TestModel->bindTranslation($translations, false);
|
||||
$result = $TestModel->read(null, $TestModel->id);
|
||||
$expected = array(
|
||||
'TranslatedItem' => array(
|
||||
'id' => '4',
|
||||
'translated_article_id' => null,
|
||||
'slug' => 'fifth_translated',
|
||||
'locale' => 'eng',
|
||||
'title' => 'Title #5',
|
||||
'content' => ''
|
||||
),
|
||||
'Title' => array(
|
||||
0 => array(
|
||||
'id' => '19',
|
||||
'locale' => 'eng',
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'title',
|
||||
'content' => 'Title #5'
|
||||
),
|
||||
1 => array(
|
||||
'id' => '20',
|
||||
'locale' => 'spa',
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'title',
|
||||
'content' => 'Leyenda #5'
|
||||
)
|
||||
),
|
||||
'Content' => array(
|
||||
0 => array(
|
||||
'id' => '21',
|
||||
'locale' => 'eng',
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'content',
|
||||
'content' => ''
|
||||
),
|
||||
1 => array(
|
||||
'id' => '22',
|
||||
'locale' => 'spa',
|
||||
'model' => 'TranslatedItem',
|
||||
'foreign_key' => '4',
|
||||
'field' => 'content',
|
||||
'content' => ''
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveUpdate method
|
||||
*
|
||||
|
|
@ -705,7 +942,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
|
||||
$TestModel = new TranslatedItem();
|
||||
$TestModel->locale = 'eng';
|
||||
$TestModel->validate['title'] = 'notEmpty';
|
||||
$TestModel->validate['title'] = 'notBlank';
|
||||
$data = array('TranslatedItem' => array(
|
||||
'id' => 1,
|
||||
'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'),
|
||||
|
|
@ -841,6 +1078,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testValidation() {
|
||||
Configure::write('Config.language', 'eng');
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
|
|
@ -869,6 +1107,29 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->assertFalse(empty($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* test restoring fields after temporary binds method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFieldsRestoreAfterBind() {
|
||||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
|
||||
$translations = array('title' => 'Title');
|
||||
$TestModel->bindTranslation($translations);
|
||||
|
||||
$result = $TestModel->find('first');
|
||||
$this->assertArrayHasKey('Title', $result);
|
||||
$this->assertArrayHasKey('content', $result['Title'][0]);
|
||||
$this->assertArrayNotHasKey('title', $result);
|
||||
|
||||
$result = $TestModel->find('first');
|
||||
$this->assertArrayNotHasKey('Title', $result);
|
||||
$this->assertEquals('Title #1', $result['TranslatedItem']['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAttachDetach method
|
||||
*
|
||||
|
|
@ -887,7 +1148,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$expected = array('Title', 'Content');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$TestModel->Behaviors->detach('Translate');
|
||||
$TestModel->Behaviors->unload('Translate');
|
||||
$result = array_keys($TestModel->hasMany);
|
||||
$expected = array();
|
||||
$this->assertEquals($expected, $result);
|
||||
|
|
@ -901,7 +1162,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$result = isset($Behavior->runtime[$TestModel->alias]);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content'));
|
||||
$TestModel->Behaviors->load('Translate', array('title' => 'Title', 'content' => 'Content'));
|
||||
$result = array_keys($TestModel->hasMany);
|
||||
$expected = array('Title', 'Content');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
|
@ -1083,9 +1344,9 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||
|
||||
$TestModel = new TranslatedItem();
|
||||
$TestModel->Behaviors->detach('Translate');
|
||||
$TestModel->Behaviors->unload('Translate');
|
||||
$TestModel->actsAs = array();
|
||||
$TestModel->Behaviors->attach('Translate');
|
||||
$TestModel->Behaviors->load('Translate');
|
||||
$TestModel->bindTranslation(array('title', 'content'), true);
|
||||
$result = $TestModel->unbindTranslation();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,25 +2,24 @@
|
|||
/**
|
||||
* TreeBehaviorAfterTest 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.5330
|
||||
* @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';
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
|
||||
|
||||
/**
|
||||
* TreeBehaviorAfterTest class
|
||||
|
|
@ -32,7 +31,7 @@ class TreeBehaviorAfterTest extends CakeTestCase {
|
|||
/**
|
||||
* Whether backup global state for each test method or not
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $backupGlobals = false;
|
||||
|
||||
|
|
@ -62,6 +61,7 @@ class TreeBehaviorAfterTest extends CakeTestCase {
|
|||
*/
|
||||
public function testAftersaveCallback() {
|
||||
$this->Tree = new AfterTree();
|
||||
$this->Tree->order = null;
|
||||
|
||||
$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
|
||||
$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
|
||||
|
|
@ -73,5 +73,3 @@ class TreeBehaviorAfterTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result[7]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,23 +4,23 @@
|
|||
*
|
||||
* This is the basic Tree behavior test
|
||||
*
|
||||
* 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.5330
|
||||
* @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';
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +33,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
/**
|
||||
* Whether backup global state for each test method or not
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $backupGlobals = false;
|
||||
|
||||
|
|
@ -46,7 +46,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
'modelClass' => 'NumberTree',
|
||||
'leftField' => 'lft',
|
||||
'rightField' => 'rght',
|
||||
'parentField' => 'parent_id'
|
||||
'parentField' => 'parent_id',
|
||||
'level' => 'level'
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +71,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals(7, $result);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,15 +89,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$save[$modelClass]['id'] = $result[$modelClass]['id'];
|
||||
$save[$modelClass][$leftField] = 0;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save($save);
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,15 +116,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$save[$modelClass]['id'] = $result[$modelClass]['id'];
|
||||
$save[$modelClass][$rightField] = 0;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save($save);
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -141,13 +144,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->updateAll(array($parentField => null), array('id' => $result[$modelClass]['id']));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,13 +167,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id']));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover('MPTT');
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,24 +186,28 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree = new $modelClass();
|
||||
$this->Tree->Behaviors->disable('Tree');
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
|
||||
$node1 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
|
||||
$node11 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
|
||||
$node12 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
|
||||
|
||||
$this->Tree->Behaviors->enable('Tree');
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
|
@ -234,19 +241,24 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree = new $modelClass();
|
||||
$this->Tree->Behaviors->disable('Tree');
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
|
||||
$node1 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
|
||||
$node11 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
|
||||
$node12 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Lost', $parentField => 9, $leftField => 0, $rightField => 0));
|
||||
|
||||
|
|
@ -262,7 +274,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
))));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$count = $this->Tree->find('count');
|
||||
$this->assertEquals(6, $count);
|
||||
|
|
@ -306,13 +318,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id']));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -328,13 +340,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->updateAll(array($parentField => null));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -350,12 +362,12 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$this->Tree->recover();
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -376,7 +388,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
array($rightField . ' >' => $result[$modelClass][$leftField]));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame($result, true);
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
|
@ -395,13 +407,14 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree = new $modelClass();
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
||||
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
|
||||
$expected = array($modelClass => array('name' => 'testAddOrphan', $parentField => null));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -426,13 +439,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount + 1, $laterCount);
|
||||
|
||||
$children = $this->Tree->children($data[$modelClass]['id'], true, array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||
$expected = array(array($modelClass => array('name' => '1.1.1')),
|
||||
array($modelClass => array('name' => '1.1.2')),
|
||||
array($modelClass => array('name' => 'testAddMiddle')));
|
||||
$this->assertSame($children, $expects);
|
||||
$this->assertSame($expected, $children);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -479,14 +492,15 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$initialCount = $this->Tree->find('count');
|
||||
//$this->expectError('Trying to save a node under a none-existant node in TreeBehavior::beforeSave');
|
||||
|
||||
$this->Tree->create();
|
||||
$saveSuccess = $this->Tree->save(array($modelClass => array('name' => 'testAddInvalid', $parentField => 99999)));
|
||||
$this->assertSame($saveSuccess, false);
|
||||
$this->assertFalse($saveSuccess);
|
||||
|
||||
$laterCount = $this->Tree->find('count');
|
||||
$this->assertSame($initialCount, $laterCount);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -499,13 +513,14 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree = new $modelClass();
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
|
||||
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
|
||||
$expected = array($modelClass => array('name' => 'testAddNotIndexed', $parentField => null));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -526,12 +541,32 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
$this->Tree->saveField($parentField, $parentId);
|
||||
$direct = $this->Tree->children($parentId, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
||||
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetLevel method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLevel() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->initialize(2, 2);
|
||||
$this->Tree->id = null;
|
||||
|
||||
$result = $this->Tree->getLevel(5);
|
||||
$this->assertEquals(1, $result);
|
||||
|
||||
$result = $this->Tree->getLevel(3);
|
||||
$this->assertEquals(2, $result);
|
||||
|
||||
$this->assertFalse($this->Tree->getLevel(999));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -572,11 +607,12 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->whitelist = array('name', $parentField);
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
||||
$result = $this->Tree->findByName('testAddOrphan', array('name', $parentField, $leftField, $rightField));
|
||||
$expected = array('name' => 'testAddOrphan', $parentField => null, $leftField => '15', $rightField => 16);
|
||||
$this->assertEquals($expected, $result[$modelClass]);
|
||||
$this->assertSame($this->Tree->verify(), true);
|
||||
$this->assertTrue($this->Tree->verify());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -598,13 +634,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->saveField($parentField, $parentId);
|
||||
|
||||
$result = $this->Tree->children($parentId, true, array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||
$expected = array(array($modelClass => array('name' => '1.1.1')),
|
||||
array($modelClass => array('name' => '1.1.2')),
|
||||
array($modelClass => array('name' => '1.2')));
|
||||
$this->assertEquals($expects, $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -626,13 +662,13 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->saveField($parentField, $parentId);
|
||||
|
||||
$result = $this->Tree->children($parentId, true, array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1.2.1')),
|
||||
$expected = array(array($modelClass => array('name' => '1.2.1')),
|
||||
array($modelClass => array('name' => '1.2.2')),
|
||||
array($modelClass => array('name' => '1.1')));
|
||||
$this->assertEquals($expects, $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -651,7 +687,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
|
||||
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
|
||||
|
||||
$expects = $this->Tree->find('all');
|
||||
$expected = $this->Tree->find('all');
|
||||
$before = $this->Tree->read(null, $data[$modelClass]['id']);
|
||||
|
||||
$this->Tree->id = $parentId;
|
||||
|
|
@ -660,11 +696,11 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$results = $this->Tree->find('all');
|
||||
$after = $this->Tree->read(null, $data[$modelClass]['id']);
|
||||
|
||||
$this->assertEquals($expects, $results);
|
||||
$this->assertEquals($expected, $results);
|
||||
$this->assertEquals($before, $after);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -688,7 +724,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertSame($initialCount, $laterCount);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -708,12 +744,12 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
$saveSuccess = $this->Tree->saveField($parentField, $this->Tree->id);
|
||||
|
||||
$this->assertSame($saveSuccess, false);
|
||||
$this->assertFalse($saveSuccess);
|
||||
$laterCount = $this->Tree->find('count');
|
||||
$this->assertSame($initialCount, $laterCount);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -732,8 +768,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$parent = $this->Tree->findByName('1. Root', array('id'));
|
||||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.1', )));
|
||||
$expected = array(array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.1')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -754,8 +790,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$parent = $this->Tree->findByName('1. Root', array('id'));
|
||||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )));
|
||||
$expected = array(array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -776,16 +812,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.5', )),
|
||||
array($modelClass => array('name' => '1.3', )),
|
||||
array($modelClass => array('name' => '1.4', )),
|
||||
array($modelClass => array('name' => '1.6', )),
|
||||
array($modelClass => array('name' => '1.7', )),
|
||||
array($modelClass => array('name' => '1.8', )),
|
||||
array($modelClass => array('name' => '1.9', )),
|
||||
array($modelClass => array('name' => '1.10', )));
|
||||
array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.5')),
|
||||
array($modelClass => array('name' => '1.3')),
|
||||
array($modelClass => array('name' => '1.4')),
|
||||
array($modelClass => array('name' => '1.6')),
|
||||
array($modelClass => array('name' => '1.7')),
|
||||
array($modelClass => array('name' => '1.8')),
|
||||
array($modelClass => array('name' => '1.9')),
|
||||
array($modelClass => array('name' => '1.10')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -806,16 +842,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.5', )),
|
||||
array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.3', )),
|
||||
array($modelClass => array('name' => '1.4', )),
|
||||
array($modelClass => array('name' => '1.6', )),
|
||||
array($modelClass => array('name' => '1.7', )),
|
||||
array($modelClass => array('name' => '1.8', )),
|
||||
array($modelClass => array('name' => '1.9', )),
|
||||
array($modelClass => array('name' => '1.10', )));
|
||||
array($modelClass => array('name' => '1.5')),
|
||||
array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.3')),
|
||||
array($modelClass => array('name' => '1.4')),
|
||||
array($modelClass => array('name' => '1.6')),
|
||||
array($modelClass => array('name' => '1.7')),
|
||||
array($modelClass => array('name' => '1.8')),
|
||||
array($modelClass => array('name' => '1.9')),
|
||||
array($modelClass => array('name' => '1.10')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -835,8 +871,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$parent = $this->Tree->findByName('1. Root', array('id'));
|
||||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.1', )));
|
||||
$expected = array(array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.1')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -856,8 +892,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$parent = $this->Tree->findByName('1. Root', array('id'));
|
||||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )));
|
||||
$expected = array(array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -878,16 +914,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.3', )),
|
||||
array($modelClass => array('name' => '1.4', )),
|
||||
array($modelClass => array('name' => '1.6', )),
|
||||
array($modelClass => array('name' => '1.7', )),
|
||||
array($modelClass => array('name' => '1.8', )),
|
||||
array($modelClass => array('name' => '1.9', )),
|
||||
array($modelClass => array('name' => '1.10', )),
|
||||
array($modelClass => array('name' => '1.5', )));
|
||||
array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.3')),
|
||||
array($modelClass => array('name' => '1.4')),
|
||||
array($modelClass => array('name' => '1.6')),
|
||||
array($modelClass => array('name' => '1.7')),
|
||||
array($modelClass => array('name' => '1.8')),
|
||||
array($modelClass => array('name' => '1.9')),
|
||||
array($modelClass => array('name' => '1.10')),
|
||||
array($modelClass => array('name' => '1.5')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -908,16 +944,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.3', )),
|
||||
array($modelClass => array('name' => '1.4', )),
|
||||
array($modelClass => array('name' => '1.6', )),
|
||||
array($modelClass => array('name' => '1.7', )),
|
||||
array($modelClass => array('name' => '1.5', )),
|
||||
array($modelClass => array('name' => '1.8', )),
|
||||
array($modelClass => array('name' => '1.9', )),
|
||||
array($modelClass => array('name' => '1.10', )));
|
||||
array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.3')),
|
||||
array($modelClass => array('name' => '1.4')),
|
||||
array($modelClass => array('name' => '1.6')),
|
||||
array($modelClass => array('name' => '1.7')),
|
||||
array($modelClass => array('name' => '1.5')),
|
||||
array($modelClass => array('name' => '1.8')),
|
||||
array($modelClass => array('name' => '1.9')),
|
||||
array($modelClass => array('name' => '1.10')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -938,16 +974,16 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $parent[$modelClass]['id'];
|
||||
$result = $this->Tree->children(null, true, array('name'));
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1', )),
|
||||
array($modelClass => array('name' => '1.2', )),
|
||||
array($modelClass => array('name' => '1.3', )),
|
||||
array($modelClass => array('name' => '1.4', )),
|
||||
array($modelClass => array('name' => 'renamed', )),
|
||||
array($modelClass => array('name' => '1.6', )),
|
||||
array($modelClass => array('name' => '1.7', )),
|
||||
array($modelClass => array('name' => '1.8', )),
|
||||
array($modelClass => array('name' => '1.9', )),
|
||||
array($modelClass => array('name' => '1.10', )));
|
||||
array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.3')),
|
||||
array($modelClass => array('name' => '1.4')),
|
||||
array($modelClass => array('name' => 'renamed')),
|
||||
array($modelClass => array('name' => '1.6')),
|
||||
array($modelClass => array('name' => '1.7')),
|
||||
array($modelClass => array('name' => '1.8')),
|
||||
array($modelClass => array('name' => '1.9')),
|
||||
array($modelClass => array('name' => '1.10')));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
|
|
@ -965,7 +1001,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->save(array($parentField => null));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->Tree->moveUp();
|
||||
|
||||
|
|
@ -995,7 +1031,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount - 1, $laterCount);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
|
||||
$initialCount = $this->Tree->find('count');
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
|
|
@ -1007,7 +1043,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount - 2, $laterCount);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1040,18 +1076,18 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount, $laterCount);
|
||||
|
||||
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||
$expected = array(array($modelClass => array('name' => '1.1.1')),
|
||||
array($modelClass => array('name' => '1.1.2')),
|
||||
array($modelClass => array('name' => '1.2')));
|
||||
$this->assertEquals($children, $expects);
|
||||
$this->assertEquals($expected, $children);
|
||||
|
||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1. Root')),
|
||||
$topNodes = $this->Tree->children(false, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1. Root')),
|
||||
array($modelClass => array('name' => '1.1')));
|
||||
$this->assertEquals($topNodes, $expects);
|
||||
$this->assertEquals($expected, $topNodes);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1076,15 +1112,15 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount, $laterCount);
|
||||
$this->assertEquals($initialTopNodes, $laterTopNodes);
|
||||
|
||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1.1')),
|
||||
$topNodes = $this->Tree->children(false, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1.1')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1. Root')));
|
||||
|
||||
$this->assertEquals($topNodes, $expects);
|
||||
$this->assertEquals($expected, $topNodes);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1105,7 +1141,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount, $laterCount);
|
||||
|
||||
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
1 => '1. Root',
|
||||
2 => '1.1',
|
||||
4 => '1.1.2',
|
||||
|
|
@ -1115,10 +1151,10 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
3 => '1.1.1',
|
||||
);
|
||||
|
||||
$this->assertEquals($nodes, $expects);
|
||||
$this->assertEquals($expected, $nodes);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1140,19 +1176,19 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount - 1, $laterCount);
|
||||
|
||||
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'), $leftField . ' asc');
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1.1')),
|
||||
array($modelClass => array('name' => '1.1.2')),
|
||||
array($modelClass => array('name' => '1.2'))
|
||||
);
|
||||
$this->assertEquals($children, $expects);
|
||||
$this->assertEquals($expected, $children);
|
||||
|
||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1. Root')));
|
||||
$this->assertEquals($topNodes, $expects);
|
||||
$topNodes = $this->Tree->children(false, true, array('name'));
|
||||
$expected = array(array($modelClass => array('name' => '1. Root')));
|
||||
$this->assertEquals($expected, $topNodes);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1173,7 +1209,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount - 1, $laterCount);
|
||||
|
||||
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
1 => '1. Root',
|
||||
2 => '1.1',
|
||||
4 => '1.1.2',
|
||||
|
|
@ -1181,10 +1217,10 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
6 => '1.2.1',
|
||||
7 => '1.2.2',
|
||||
);
|
||||
$this->assertEquals($nodes, $expects);
|
||||
$this->assertEquals($expected, $nodes);
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1201,18 +1237,18 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
|
||||
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
||||
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)),
|
||||
array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
||||
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12)));
|
||||
$this->assertEquals($total, $expects);
|
||||
$this->assertEquals($expected, $total);
|
||||
|
||||
$this->assertEquals(array(), $this->Tree->children(10000));
|
||||
}
|
||||
|
|
@ -1256,8 +1292,8 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$result = $this->Tree->getParentNode(null, array('name'));
|
||||
$expects = array($modelClass => array('name' => '1.2'));
|
||||
$this->assertSame($expects, $result);
|
||||
$expected = array($modelClass => array('name' => '1.2'));
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1274,10 +1310,10 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$result = $this->Tree->getPath(null, array('name'));
|
||||
$expects = array(array($modelClass => array('name' => '1. Root')),
|
||||
$expected = array(array($modelClass => array('name' => '1. Root')),
|
||||
array($modelClass => array('name' => '1.2')),
|
||||
array($modelClass => array('name' => '1.2.2')));
|
||||
$this->assertSame($expects, $result);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1296,12 +1332,12 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
|
||||
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
||||
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
||||
|
|
@ -1309,7 +1345,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
||||
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12))
|
||||
);
|
||||
$this->assertEquals($total, $expects);
|
||||
$this->assertEquals($expected, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1397,6 +1433,29 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
$this->assertEquals('__3 - 1.1.1', $result[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the formatting options of formatTreeList()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFormatTreeList() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$options = array('order' => array('lft' => 'asc'));
|
||||
$records = $this->Tree->find('all', $options);
|
||||
|
||||
$options = array(
|
||||
'keyPath' => "{n}.$modelClass.id",
|
||||
'valuePath' => array('%s - %s', "{n}.$modelClass.id", "{n}.$modelClass.name"),
|
||||
'spacer' => '--');
|
||||
$result = $this->Tree->formatTreeList($records, $options);
|
||||
$this->assertEquals('1 - 1. Root', $result[1]);
|
||||
$this->assertEquals('--2 - 1.1', $result[2]);
|
||||
$this->assertEquals('----3 - 1.1.1', $result[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* testArraySyntax method
|
||||
*
|
||||
|
|
@ -1419,7 +1478,7 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
public function testFindThreaded() {
|
||||
$Model = new Person();
|
||||
$Model->recursive = -1;
|
||||
$Model->Behaviors->attach('Tree', array('parent' => 'mother_id'));
|
||||
$Model->Behaviors->load('Tree', array('parent' => 'mother_id'));
|
||||
|
||||
$result = $Model->find('threaded');
|
||||
$expected = array(
|
||||
|
|
@ -1492,4 +1551,61 @@ class TreeBehaviorNumberTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testLevel() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->Behaviors->attach('Tree', array('level' => 'level'));
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$result = $this->Tree->findByName('1. Root');
|
||||
$this->assertEquals(0, $result[$modelClass][$level]);
|
||||
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
$this->assertEquals(1, $result[$modelClass][$level]);
|
||||
|
||||
$result = $this->Tree->findByName('1.2.2');
|
||||
$this->assertEquals(2, $result[$modelClass][$level]);
|
||||
|
||||
$result = $this->Tree->findByName('1.2.1');
|
||||
$this->assertEquals(2, $result[$modelClass][$level]);
|
||||
|
||||
// Save with parent_id not set
|
||||
$this->Tree->save(array('id' => $result[$modelClass]['id'], 'name' => 'foo'));
|
||||
$result = $this->Tree->findByName('foo');
|
||||
$this->assertEquals(2, $result[$modelClass][$level]);
|
||||
|
||||
// Save with parent_id not changed
|
||||
$this->Tree->save(array(
|
||||
'id' => $result[$modelClass]['id'],
|
||||
'parent_id' => $result[$modelClass]['parent_id'],
|
||||
'name' => 'foo2'
|
||||
));
|
||||
$result = $this->Tree->findByName('foo2');
|
||||
$this->assertEquals(2, $result[$modelClass][$level]);
|
||||
|
||||
// Save with parent_id changed
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
$this->Tree->save(array(
|
||||
'id' => $result[$modelClass]['id'],
|
||||
'parent_id' => ''
|
||||
));
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
$this->assertEquals(0, $result[$modelClass][$level]);
|
||||
|
||||
$result = $this->Tree->findByName('1.1.2');
|
||||
$this->assertEquals(1, $result[$modelClass][$level]);
|
||||
|
||||
$parent = $this->Tree->findByName('1.1.2');
|
||||
$result = $this->Tree->findByName('1.2');
|
||||
$this->Tree->save(array(
|
||||
'id' => $result[$modelClass]['id'],
|
||||
'parent_id' => $parent[$modelClass]['id']
|
||||
));
|
||||
$result = $this->Tree->findByName('1.2');
|
||||
$this->assertEquals(2, $result[$modelClass][$level]);
|
||||
|
||||
$result = $this->Tree->findByName('1.2.2');
|
||||
$this->assertEquals(3, $result[$modelClass][$level]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,23 @@
|
|||
*
|
||||
* A tree test using scope
|
||||
*
|
||||
* 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.5330
|
||||
* @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';
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +33,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
/**
|
||||
* Whether backup global state for each test method or not
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $backupGlobals = false;
|
||||
|
||||
|
|
@ -63,6 +63,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
*/
|
||||
public function testStringScope() {
|
||||
$this->Tree = new FlagTree();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 3);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
|
|
@ -78,11 +79,11 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
$this->assertEquals(array(), $this->Tree->children());
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
|
||||
$result = $this->Tree->children();
|
||||
$expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1')));
|
||||
|
|
@ -99,6 +100,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
*/
|
||||
public function testArrayScope() {
|
||||
$this->Tree = new FlagTree();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 3);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
|
|
@ -114,11 +116,11 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
$this->assertEquals(array(), $this->Tree->children());
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$result = $this->Tree->children();
|
||||
$expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1')));
|
||||
|
|
@ -128,6 +130,29 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
$this->assertEquals(11, $this->Tree->find('count'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveWithParentAndInvalidScope method
|
||||
*
|
||||
* Attempting to save an invalid data should not trigger an `Undefined offset`
|
||||
* error
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveWithParentAndInvalidScope() {
|
||||
$this->Tree = new FlagTree();
|
||||
$this->Tree->order = null;
|
||||
$data = $this->Tree->create(array(
|
||||
'name' => 'Flag',
|
||||
));
|
||||
$tree = $this->Tree->save($data);
|
||||
$this->Tree->Behaviors->load('Tree', array(
|
||||
'scope' => array('FlagTree.flag' => 100)
|
||||
));
|
||||
$tree['FlagTree']['parent_id'] = 1;
|
||||
$result = $this->Tree->save($tree);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMoveUpWithScope method
|
||||
*
|
||||
|
|
@ -135,7 +160,8 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
*/
|
||||
public function testMoveUpWithScope() {
|
||||
$this->Ad = new Ad();
|
||||
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
|
||||
$this->Ad->order = null;
|
||||
$this->Ad->Behaviors->load('Tree', array('scope' => 'Campaign'));
|
||||
$this->Ad->moveUp(6);
|
||||
|
||||
$this->Ad->id = 4;
|
||||
|
|
@ -151,7 +177,8 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
*/
|
||||
public function testMoveDownWithScope() {
|
||||
$this->Ad = new Ad();
|
||||
$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign'));
|
||||
$this->Ad->order = null;
|
||||
$this->Ad->Behaviors->load('Tree', array('scope' => 'Campaign'));
|
||||
$this->Ad->moveDown(6);
|
||||
|
||||
$this->Ad->id = 4;
|
||||
|
|
@ -168,10 +195,12 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
*/
|
||||
public function testTranslatingTree() {
|
||||
$this->Tree = new FlagTree();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->cacheQueries = false;
|
||||
$this->Tree->Behaviors->attach('Translate', array('title'));
|
||||
$this->Tree->Behaviors->load('Translate', array('title'));
|
||||
|
||||
//Save
|
||||
$this->Tree->create();
|
||||
$this->Tree->locale = 'eng';
|
||||
$data = array('FlagTree' => array(
|
||||
'title' => 'name #1',
|
||||
|
|
@ -285,9 +314,11 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
public function testAliasesWithScopeInTwoTreeAssociations() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->TreeTwo = new NumberTreeTwo();
|
||||
$this->TreeTwo->order = null;
|
||||
|
||||
$record = $this->Tree->find('first');
|
||||
|
||||
|
|
@ -307,7 +338,7 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
));
|
||||
$this->TreeTwo->Behaviors->attach('Tree', array(
|
||||
$this->TreeTwo->Behaviors->load('Tree', array(
|
||||
'scope' => 'FirstTree'
|
||||
));
|
||||
|
||||
|
|
@ -332,4 +363,229 @@ class TreeBehaviorScopedTest extends CakeTestCase {
|
|||
));
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testGenerateTreeListWithScope method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateTreeListWithScope() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 3);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
$this->Tree->id = 2;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$result = $this->Tree->generateTreeList();
|
||||
$expected = array(
|
||||
1 => '1. Root',
|
||||
2 => '_1.1'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
// As string.
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
|
||||
$result = $this->Tree->generateTreeList();
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
// Merging conditions.
|
||||
$result = $this->Tree->generateTreeList(array('FlagTree.id >' => 1));
|
||||
$expected = array(
|
||||
2 => '1.1'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRecoverUsingParentMode method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRecoverUsingParentMode() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 3);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1'));
|
||||
$this->Tree->Behaviors->disable('Tree');
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0, 'flag' => 1));
|
||||
$node1 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1));
|
||||
$node11 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1));
|
||||
$node12 = $this->Tree->id;
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0, 'flag' => 1));
|
||||
|
||||
$this->Tree->create();
|
||||
$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0, 'flag' => 1));
|
||||
|
||||
$this->Tree->Behaviors->enable('Tree');
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->find('first', array(
|
||||
'fields' => array('name', $parentField, $leftField, $rightField, 'flag'),
|
||||
'conditions' => array('name' => 'Main'),
|
||||
'recursive' => -1
|
||||
));
|
||||
$expected = array(
|
||||
$modelClass => array(
|
||||
'name' => 'Main',
|
||||
$parentField => null,
|
||||
$leftField => 1,
|
||||
$rightField => 10,
|
||||
'flag' => 1
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRecoverFromMissingParent method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRecoverFromMissingParent() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
$this->Tree->id = 2;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id']));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDetectInvalidParents method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDetectInvalidParents() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
$this->Tree->id = 2;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$this->Tree->updateAll(array($parentField => null));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDetectInvalidLftsRghts method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDetectInvalidLftsRghts() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
$this->Tree->id = 2;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$this->Tree->recover();
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reproduces a situation where a single node has lft= rght, and all other lft and rght fields follow sequentially
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDetectEqualLftsRghts() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(1, 3);
|
||||
|
||||
$this->Tree->id = 1;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
$this->Tree->id = 2;
|
||||
$this->Tree->saveField('flag', 1);
|
||||
|
||||
$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1)));
|
||||
|
||||
$result = $this->Tree->findByName('1.1');
|
||||
$this->Tree->updateAll(array($rightField => $result[$modelClass][$leftField]), array('id' => $result[$modelClass]['id']));
|
||||
$this->Tree->updateAll(array($leftField => $this->Tree->escapeField($leftField) . ' -1'),
|
||||
array($leftField . ' >' => $result[$modelClass][$leftField]));
|
||||
$this->Tree->updateAll(array($rightField => $this->Tree->escapeField($rightField) . ' -1'),
|
||||
array($rightField . ' >' => $result[$modelClass][$leftField]));
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertNotSame(true, $result);
|
||||
|
||||
$result = $this->Tree->recover();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Tree->verify();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Tree Behavior test file - runs all the tree behavior tests
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Behavior
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,24 +4,24 @@
|
|||
*
|
||||
* Tree test using UUIDs
|
||||
*
|
||||
* 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.5330
|
||||
* @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');
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('CakeText', 'Utility');
|
||||
|
||||
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
|
||||
|
||||
/**
|
||||
|
|
@ -34,7 +34,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
/**
|
||||
* Whether backup global state for each test method or not
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $backupGlobals = false;
|
||||
|
||||
|
|
@ -65,6 +65,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testAddWithPreSpecifiedId() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$data = $this->Tree->find('first', array(
|
||||
|
|
@ -72,7 +73,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
'conditions' => array($modelClass . '.name' => '1.1')
|
||||
));
|
||||
|
||||
$id = String::uuid();
|
||||
$id = CakeText::uuid();
|
||||
$this->Tree->create();
|
||||
$result = $this->Tree->save(array($modelClass => array(
|
||||
'id' => $id,
|
||||
|
|
@ -96,6 +97,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testMovePromote() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
$this->Tree->id = null;
|
||||
|
||||
|
|
@ -106,12 +108,12 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
$this->Tree->saveField($parentField, $parentId);
|
||||
$direct = $this->Tree->children($parentId, true, array('name', $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)),
|
||||
$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)),
|
||||
array($modelClass => array('name' => '1.2', $leftField => 6, $rightField => 11)),
|
||||
array($modelClass => array('name' => '1.1.1', $leftField => 12, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,6 +124,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testMoveWithWhitelist() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
$this->Tree->id = null;
|
||||
|
||||
|
|
@ -149,6 +152,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testRemoveNoChildren() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
$initialCount = $this->Tree->find('count');
|
||||
|
||||
|
|
@ -159,7 +163,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount, $laterCount);
|
||||
|
||||
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
'1. Root',
|
||||
'1.1',
|
||||
'1.1.2',
|
||||
|
|
@ -169,10 +173,10 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
'1.1.1',
|
||||
);
|
||||
|
||||
$this->assertEquals(array_values($nodes), $expects);
|
||||
$this->assertEquals($expected, array_values($nodes));
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,6 +187,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testRemoveAndDeleteNoChildren() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
$initialCount = $this->Tree->find('count');
|
||||
|
||||
|
|
@ -193,7 +198,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
$this->assertEquals($initialCount - 1, $laterCount);
|
||||
|
||||
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
'1. Root',
|
||||
'1.1',
|
||||
'1.1.2',
|
||||
|
|
@ -201,10 +206,10 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
'1.2.1',
|
||||
'1.2.2',
|
||||
);
|
||||
$this->assertEquals(array_values($nodes), $expects);
|
||||
$this->assertEquals($expected, array_values($nodes));
|
||||
|
||||
$validTree = $this->Tree->verify();
|
||||
$this->assertSame($validTree, true);
|
||||
$this->assertTrue($validTree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -215,24 +220,25 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testChildren() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
||||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
|
||||
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)),
|
||||
array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)),
|
||||
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)),
|
||||
array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)),
|
||||
array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12)));
|
||||
$this->assertEquals($total, $expects);
|
||||
$this->assertEquals($expected, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,6 +249,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testNoAmbiguousColumn() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||
|
|
@ -255,12 +262,12 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
$this->Tree->id = $data[$modelClass]['id'];
|
||||
|
||||
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
|
||||
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)));
|
||||
$this->assertEquals($direct, $expects);
|
||||
$this->assertEquals($expected, $direct);
|
||||
|
||||
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField));
|
||||
$expects = array(
|
||||
$expected = array(
|
||||
array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||
array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)),
|
||||
array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)),
|
||||
|
|
@ -268,7 +275,7 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)),
|
||||
array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12))
|
||||
);
|
||||
$this->assertEquals($total, $expects);
|
||||
$this->assertEquals($expected, $total);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -279,12 +286,13 @@ class TreeBehaviorUuidTest extends CakeTestCase {
|
|||
public function testGenerateTreeListWithSelfJoin() {
|
||||
extract($this->settings);
|
||||
$this->Tree = new $modelClass();
|
||||
$this->Tree->order = null;
|
||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||
$this->Tree->initialize(2, 2);
|
||||
|
||||
$result = $this->Tree->generateTreeList();
|
||||
$expected = array('1. Root', '_1.1', '__1.1.1', '__1.1.2', '_1.2', '__1.2.1', '__1.2.2');
|
||||
$this->assertSame(array_values($result), $expected);
|
||||
$this->assertSame($expected, array_values($result));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,22 @@
|
|||
*
|
||||
* Long description for behavior.test.php
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* 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 CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model
|
||||
* @since 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppModel', 'Model');
|
||||
|
||||
require_once dirname(__FILE__) . DS . 'models.php';
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +60,7 @@ class TestBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function beforeFind(Model $model, $query) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['beforeFind']) || $settings['beforeFind'] == 'off') {
|
||||
if (!isset($settings['beforeFind']) || $settings['beforeFind'] === 'off') {
|
||||
return parent::beforeFind($model, $query);
|
||||
}
|
||||
switch ($settings['beforeFind']) {
|
||||
|
|
@ -80,12 +80,12 @@ class TestBehavior extends ModelBehavior {
|
|||
*
|
||||
* @param Model $model
|
||||
* @param array $results
|
||||
* @param boolean $primary
|
||||
* @param bool $primary
|
||||
* @return void
|
||||
*/
|
||||
public function afterFind(Model $model, $results, $primary) {
|
||||
public function afterFind(Model $model, $results, $primary = false) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['afterFind']) || $settings['afterFind'] == 'off') {
|
||||
if (!isset($settings['afterFind']) || $settings['afterFind'] === 'off') {
|
||||
return parent::afterFind($model, $results, $primary);
|
||||
}
|
||||
switch ($settings['afterFind']) {
|
||||
|
|
@ -103,13 +103,15 @@ class TestBehavior extends ModelBehavior {
|
|||
/**
|
||||
* beforeSave method
|
||||
*
|
||||
* @param Model $model
|
||||
* @return void
|
||||
* @param Model $model Model using this behavior
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return mixed False if the operation should abort. Any other result will continue.
|
||||
* @see Model::save()
|
||||
*/
|
||||
public function beforeSave(Model $model) {
|
||||
public function beforeSave(Model $model, $options = array()) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['beforeSave']) || $settings['beforeSave'] == 'off') {
|
||||
return parent::beforeSave($model);
|
||||
if (!isset($settings['beforeSave']) || $settings['beforeSave'] === 'off') {
|
||||
return parent::beforeSave($model, $options);
|
||||
}
|
||||
switch ($settings['beforeSave']) {
|
||||
case 'on':
|
||||
|
|
@ -126,13 +128,14 @@ class TestBehavior extends ModelBehavior {
|
|||
* afterSave method
|
||||
*
|
||||
* @param Model $model
|
||||
* @param boolean $created
|
||||
* @param bool $created
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return void
|
||||
*/
|
||||
public function afterSave(Model $model, $created) {
|
||||
public function afterSave(Model $model, $created, $options = array()) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['afterSave']) || $settings['afterSave'] == 'off') {
|
||||
return parent::afterSave($model, $created);
|
||||
if (!isset($settings['afterSave']) || $settings['afterSave'] === 'off') {
|
||||
return parent::afterSave($model, $created, $options);
|
||||
}
|
||||
$string = 'modified after';
|
||||
if ($created) {
|
||||
|
|
@ -141,28 +144,30 @@ class TestBehavior extends ModelBehavior {
|
|||
switch ($settings['afterSave']) {
|
||||
case 'on':
|
||||
$model->data[$model->alias]['aftersave'] = $string;
|
||||
break;
|
||||
break;
|
||||
case 'test':
|
||||
unset($model->data[$model->alias]['name']);
|
||||
break;
|
||||
break;
|
||||
case 'test2':
|
||||
return false;
|
||||
case 'modify':
|
||||
$model->data[$model->alias]['name'] .= ' ' . $string;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* beforeValidate method
|
||||
* beforeValidate Callback
|
||||
*
|
||||
* @param Model $model
|
||||
* @return void
|
||||
* @param Model $Model Model invalidFields was called on.
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return bool
|
||||
* @see Model::save()
|
||||
*/
|
||||
public function beforeValidate(Model $model) {
|
||||
public function beforeValidate(Model $model, $options = array()) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['validate']) || $settings['validate'] == 'off') {
|
||||
return parent::beforeValidate($model);
|
||||
if (!isset($settings['validate']) || $settings['validate'] === 'off') {
|
||||
return parent::beforeValidate($model, $options);
|
||||
}
|
||||
switch ($settings['validate']) {
|
||||
case 'on':
|
||||
|
|
@ -188,7 +193,7 @@ class TestBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function afterValidate(Model $model) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['afterValidate']) || $settings['afterValidate'] == 'off') {
|
||||
if (!isset($settings['afterValidate']) || $settings['afterValidate'] === 'off') {
|
||||
return parent::afterValidate($model);
|
||||
}
|
||||
switch ($settings['afterValidate']) {
|
||||
|
|
@ -209,7 +214,7 @@ class TestBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function beforeDelete(Model $model, $cascade = true) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') {
|
||||
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] === 'off') {
|
||||
return parent::beforeDelete($model, $cascade);
|
||||
}
|
||||
switch ($settings['beforeDelete']) {
|
||||
|
|
@ -234,13 +239,13 @@ class TestBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function afterDelete(Model $model) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') {
|
||||
if (!isset($settings['afterDelete']) || $settings['afterDelete'] === 'off') {
|
||||
return parent::afterDelete($model);
|
||||
}
|
||||
switch ($settings['afterDelete']) {
|
||||
case 'on':
|
||||
echo 'afterDelete success';
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +257,7 @@ class TestBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function onError(Model $model, $error) {
|
||||
$settings = $this->settings[$model->alias];
|
||||
if (!isset($settings['onError']) || $settings['onError'] == 'off') {
|
||||
if (!isset($settings['onError']) || $settings['onError'] === 'off') {
|
||||
return parent::onError($model, $error);
|
||||
}
|
||||
echo "onError trigger success";
|
||||
|
|
@ -348,7 +353,7 @@ class Test2Behavior extends TestBehavior {
|
|||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Test3Behavior extends TestBehavior{
|
||||
class Test3Behavior extends TestBehavior {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -356,7 +361,7 @@ class Test3Behavior extends TestBehavior{
|
|||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Test4Behavior extends ModelBehavior{
|
||||
class Test4Behavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $model, $config = null) {
|
||||
$model->bindModel(
|
||||
|
|
@ -371,7 +376,7 @@ class Test4Behavior extends ModelBehavior{
|
|||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Test5Behavior extends ModelBehavior{
|
||||
class Test5Behavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $model, $config = null) {
|
||||
$model->bindModel(
|
||||
|
|
@ -386,7 +391,7 @@ class Test5Behavior extends ModelBehavior{
|
|||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Test6Behavior extends ModelBehavior{
|
||||
class Test6Behavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $model, $config = null) {
|
||||
$model->bindModel(
|
||||
|
|
@ -401,7 +406,7 @@ class Test6Behavior extends ModelBehavior{
|
|||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Test7Behavior extends ModelBehavior{
|
||||
class Test7Behavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $model, $config = null) {
|
||||
$model->bindModel(
|
||||
|
|
@ -417,6 +422,39 @@ class Test7Behavior extends ModelBehavior{
|
|||
class TestAliasBehavior extends TestBehavior {
|
||||
}
|
||||
|
||||
/**
|
||||
* FirstBehavior
|
||||
*/
|
||||
class FirstBehavior extends ModelBehavior {
|
||||
|
||||
public function beforeFind(Model $model, $query = array()) {
|
||||
$model->called[] = get_class($this);
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SecondBehavior
|
||||
*/
|
||||
class SecondBehavior extends FirstBehavior {
|
||||
}
|
||||
|
||||
/**
|
||||
* ThirdBehavior
|
||||
*/
|
||||
class ThirdBehavior extends FirstBehavior {
|
||||
}
|
||||
|
||||
/**
|
||||
* Orangutan Model
|
||||
*/
|
||||
class Orangutan extends Monkey {
|
||||
|
||||
public $called = array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* BehaviorCollection class
|
||||
*
|
||||
|
|
@ -431,31 +469,35 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public $fixtures = array(
|
||||
'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment',
|
||||
'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate'
|
||||
'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate',
|
||||
'core.device'
|
||||
);
|
||||
|
||||
/**
|
||||
* Test load() with enabled => false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadDisabled() {
|
||||
$Apple = new Apple();
|
||||
$this->assertSame(array(), $Apple->Behaviors->attached());
|
||||
$this->assertSame(array(), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->load('Translate', array('enabled' => false));
|
||||
$this->assertTrue($Apple->Behaviors->attached('Translate'));
|
||||
$this->assertTrue($Apple->Behaviors->loaded('Translate'));
|
||||
$this->assertFalse($Apple->Behaviors->enabled('Translate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests loading aliased behaviors
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAlias() {
|
||||
$Apple = new Apple();
|
||||
$this->assertSame(array(), $Apple->Behaviors->attached());
|
||||
$this->assertSame(array(), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->load('Test', array('className' => 'TestAlias', 'somesetting' => true));
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->attached());
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->loaded());
|
||||
$this->assertInstanceOf('TestAliasBehavior', $Apple->Behaviors->Test);
|
||||
$this->assertTrue($Apple->Behaviors->Test->settings['Apple']['somesetting']);
|
||||
|
||||
|
|
@ -468,8 +510,8 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$this->assertTrue($Apple->Behaviors->load('SomeOther', array('className' => 'TestPlugin.TestPluginPersisterOne')));
|
||||
$this->assertInstanceOf('TestPluginPersisterOneBehavior', $Apple->Behaviors->SomeOther);
|
||||
|
||||
$result = $Apple->Behaviors->attached();
|
||||
$this->assertEquals(array('Test', 'SomeOther'), $result, 'attached() results are wrong.');
|
||||
$result = $Apple->Behaviors->loaded();
|
||||
$this->assertEquals(array('Test', 'SomeOther'), $result, 'loaded() results are wrong.');
|
||||
App::build();
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
|
@ -481,44 +523,44 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBehaviorBinding() {
|
||||
$Apple = new Apple();
|
||||
$this->assertSame(array(), $Apple->Behaviors->attached());
|
||||
$this->assertSame(array(), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('key' => 'value'));
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->attached());
|
||||
$Apple->Behaviors->load('Test', array('key' => 'value'));
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->loaded());
|
||||
$this->assertEquals('testbehavior', strtolower(get_class($Apple->Behaviors->Test)));
|
||||
$expected = array('beforeFind' => 'on', 'afterFind' => 'off', 'key' => 'value');
|
||||
$this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']);
|
||||
$this->assertEquals(array('Apple'), array_keys($Apple->Behaviors->Test->settings));
|
||||
$this->assertEquals(array('priority', 'Apple'), array_keys($Apple->Behaviors->Test->settings));
|
||||
|
||||
$this->assertSame($Apple->Sample->Behaviors->attached(), array());
|
||||
$Apple->Sample->Behaviors->attach('Test', array('key2' => 'value2'));
|
||||
$this->assertSame($Apple->Sample->Behaviors->attached(), array('Test'));
|
||||
$this->assertSame($Apple->Sample->Behaviors->loaded(), array());
|
||||
$Apple->Sample->Behaviors->load('Test', array('key2' => 'value2'));
|
||||
$this->assertSame($Apple->Sample->Behaviors->loaded(), array('Test'));
|
||||
$this->assertEquals(array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'), $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->assertEquals(array('Apple', 'Sample'), array_keys($Apple->Behaviors->Test->settings));
|
||||
$this->assertEquals(array('priority', 'Apple', 'Sample'), array_keys($Apple->Behaviors->Test->settings));
|
||||
$this->assertSame(
|
||||
$Apple->Sample->Behaviors->Test->settings,
|
||||
$Apple->Behaviors->Test->settings
|
||||
);
|
||||
$this->assertNotSame($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$Apple->Sample->Behaviors->attach('Test', array('key' => 'value', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$Apple->Behaviors->load('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('key' => 'value', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$this->assertEquals(array('beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'value', 'key2' => 'value2', 'key3' => 'value3'), $Apple->Behaviors->Test->settings['Apple']);
|
||||
$this->assertEquals($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->assertFalse(isset($Apple->Child->Behaviors->Test));
|
||||
$Apple->Child->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$Apple->Child->Behaviors->load('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$this->assertEquals($Apple->Child->Behaviors->Test->settings['Child'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->assertFalse(isset($Apple->Parent->Behaviors->Test));
|
||||
$Apple->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||
$this->assertEquals($Apple->Parent->Behaviors->Test->settings['Parent'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'beforeFind' => 'off'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'beforeFind' => 'off'));
|
||||
$this->assertNotEquals($Apple->Parent->Behaviors->Test->settings['Parent'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value'));
|
||||
$Apple->Behaviors->load('Plugin.Test', array('key' => 'new value'));
|
||||
$expected = array(
|
||||
'beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value',
|
||||
'key2' => 'value2', 'key3' => 'value3'
|
||||
|
|
@ -527,14 +569,14 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
|
||||
$current = $Apple->Behaviors->Test->settings['Apple'];
|
||||
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
||||
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
||||
$Apple->Behaviors->load('Test', array('mangle' => 'trigger'));
|
||||
$this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']);
|
||||
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$Apple->Behaviors->load('Test');
|
||||
$expected = array_merge($current, array('mangle' => 'trigger mangled mangled'));
|
||||
|
||||
$this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']);
|
||||
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
||||
$Apple->Behaviors->load('Test', array('mangle' => 'trigger'));
|
||||
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
||||
$this->assertEquals($expected, $Apple->Behaviors->Test->settings['Apple']);
|
||||
}
|
||||
|
|
@ -546,19 +588,19 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testDetachWithPluginNames() {
|
||||
$Apple = new Apple();
|
||||
$Apple->Behaviors->attach('Plugin.Test');
|
||||
$Apple->Behaviors->load('Plugin.Test');
|
||||
$this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
|
||||
$this->assertEquals(array('Test'), $Apple->Behaviors->attached());
|
||||
$this->assertEquals(array('Test'), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->detach('Plugin.Test');
|
||||
$this->assertEquals(array(), $Apple->Behaviors->attached());
|
||||
$Apple->Behaviors->unload('Plugin.Test');
|
||||
$this->assertEquals(array(), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->attach('Plugin.Test');
|
||||
$Apple->Behaviors->load('Plugin.Test');
|
||||
$this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
|
||||
$this->assertEquals(array('Test'), $Apple->Behaviors->attached());
|
||||
$this->assertEquals(array('Test'), $Apple->Behaviors->loaded());
|
||||
|
||||
$Apple->Behaviors->detach('Test');
|
||||
$this->assertEquals(array(), $Apple->Behaviors->attached());
|
||||
$Apple->Behaviors->unload('Test');
|
||||
$this->assertEquals(array(), $Apple->Behaviors->loaded());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -569,7 +611,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testInvalidBehaviorCausingCakeError() {
|
||||
$Apple = new Apple();
|
||||
$Apple->Behaviors->attach('NoSuchBehavior');
|
||||
$Apple->Behaviors->load('NoSuchBehavior');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -579,31 +621,30 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBehaviorToggling() {
|
||||
$Apple = new Apple();
|
||||
$expected = $Apple->find('all');
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
|
||||
$Apple->Behaviors->init('Apple', array('Test' => array('key' => 'value')));
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array('Test'));
|
||||
|
||||
$Apple->Behaviors->disable('Test');
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->attached());
|
||||
$this->assertSame(array('Test'), $Apple->Behaviors->loaded());
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test');
|
||||
$this->assertSame($Apple->Sample->Behaviors->enabled('Test'), true);
|
||||
$Apple->Sample->Behaviors->load('Test');
|
||||
$this->assertTrue($Apple->Sample->Behaviors->enabled('Test'));
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
|
||||
$Apple->Behaviors->enable('Test');
|
||||
$this->assertSame($Apple->Behaviors->attached('Test'), true);
|
||||
$this->assertTrue($Apple->Behaviors->loaded('Test'));
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array('Test'));
|
||||
|
||||
$Apple->Behaviors->disable('Test');
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
$Apple->Behaviors->attach('Test', array('enabled' => true));
|
||||
$Apple->Behaviors->load('Test', array('enabled' => true));
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array('Test'));
|
||||
$Apple->Behaviors->attach('Test', array('enabled' => false));
|
||||
$Apple->Behaviors->load('Test', array('enabled' => false));
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
$Apple->Behaviors->detach('Test');
|
||||
$Apple->Behaviors->unload('Test');
|
||||
$this->assertSame($Apple->Behaviors->enabled(), array());
|
||||
}
|
||||
|
||||
|
|
@ -618,16 +659,16 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$Apple = new Apple();
|
||||
$expected = $Apple->find('all');
|
||||
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$this->assertSame($Apple->find('all'), null);
|
||||
$Apple->Behaviors->load('Test');
|
||||
$this->assertNull($Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off'));
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'off'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'test'));
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'test'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'modify'));
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'modify'));
|
||||
$expected2 = array(
|
||||
array('Apple' => array('id' => '1', 'name' => 'Red Apple 1', 'mytime' => '22:57:17')),
|
||||
array('Apple' => array('id' => '2', 'name' => 'Bright Red Apple', 'mytime' => '22:57:17')),
|
||||
|
|
@ -640,19 +681,19 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Apple->find('all');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'on'));
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'off', 'afterFind' => 'on'));
|
||||
$this->assertSame($Apple->find('all'), array());
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterFind' => 'off'));
|
||||
$Apple->Behaviors->load('Test', array('afterFind' => 'off'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterFind' => 'test'));
|
||||
$Apple->Behaviors->load('Test', array('afterFind' => 'test'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterFind' => 'test2'));
|
||||
$Apple->Behaviors->load('Test', array('afterFind' => 'test2'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterFind' => 'modify'));
|
||||
$Apple->Behaviors->load('Test', array('afterFind' => 'modify'));
|
||||
$expected = array(
|
||||
array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
|
||||
array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'),
|
||||
|
|
@ -677,48 +718,32 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
|
||||
$Apple->unbindModel(array('hasMany' => array('Child')));
|
||||
$wellBehaved = $Apple->find('all');
|
||||
$Apple->Child->Behaviors->attach('Test', array('afterFind' => 'modify'));
|
||||
$Apple->Child->Behaviors->load('Test', array('afterFind' => 'modify'));
|
||||
$Apple->unbindModel(array('hasMany' => array('Child')));
|
||||
$this->assertSame($Apple->find('all'), $wellBehaved);
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('before' => 'off'));
|
||||
$Apple->Child->Behaviors->load('Test', array('before' => 'off'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('before' => 'test'));
|
||||
$Apple->Child->Behaviors->load('Test', array('before' => 'test'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$expected2 = array(
|
||||
array(
|
||||
'Apple' => array('id' => 1),
|
||||
'Child' => array(
|
||||
array('id' => 2, 'name' => 'Bright Red Apple', 'mytime' => '22:57:17'))),
|
||||
array(
|
||||
'Apple' => array('id' => 2),
|
||||
'Child' => array(
|
||||
array('id' => 1, 'name' => 'Red Apple 1', 'mytime' => '22:57:17'),
|
||||
array('id' => 3, 'name' => 'green blue', 'mytime' => '22:57:17'),
|
||||
array('id' => 4, 'name' => 'Test Name', 'mytime' => '22:57:17'))),
|
||||
array(
|
||||
'Apple' => array('id' => 3),
|
||||
'Child' => array())
|
||||
);
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('before' => 'modify'));
|
||||
$Apple->Child->Behaviors->load('Test', array('before' => 'modify'));
|
||||
$result = $Apple->find('all', array('fields' => array('Apple.id'), 'conditions' => array('Apple.id <' => '4')));
|
||||
|
||||
$Apple->Child->Behaviors->disable('Test');
|
||||
$result = $Apple->find('all');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('before' => 'off', 'after' => 'on'));
|
||||
$Apple->Child->Behaviors->load('Test', array('before' => 'off', 'after' => 'on'));
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('after' => 'off'));
|
||||
$Apple->Child->Behaviors->load('Test', array('after' => 'off'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('after' => 'test'));
|
||||
$Apple->Child->Behaviors->load('Test', array('after' => 'test'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Child->Behaviors->attach('Test', array('after' => 'test2'));
|
||||
$Apple->Child->Behaviors->load('Test', array('after' => 'test2'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
}
|
||||
|
||||
|
|
@ -734,27 +759,27 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
|
||||
$Apple->unbindModel(array('hasOne' => array('Sample')));
|
||||
$wellBehaved = $Apple->find('all');
|
||||
$Apple->Sample->Behaviors->attach('Test');
|
||||
$Apple->Sample->Behaviors->load('Test');
|
||||
$Apple->unbindModel(array('hasOne' => array('Sample')));
|
||||
$this->assertSame($Apple->find('all'), $wellBehaved);
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test', array('before' => 'off'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('before' => 'off'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test', array('before' => 'test'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('before' => 'test'));
|
||||
$this->assertSame($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Sample->Behaviors->disable('Test');
|
||||
$result = $Apple->find('all');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test', array('after' => 'off'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('after' => 'off'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test', array('after' => 'test'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('after' => 'test'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
|
||||
$Apple->Sample->Behaviors->attach('Test', array('after' => 'test2'));
|
||||
$Apple->Sample->Behaviors->load('Test', array('after' => 'test2'));
|
||||
$this->assertEquals($expected, $Apple->find('all'));
|
||||
}
|
||||
|
||||
|
|
@ -773,17 +798,17 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
|
||||
$Apple->unbindModel(array('belongsTo' => array('Parent')));
|
||||
$wellBehaved = $Apple->find('all', $conditions);
|
||||
$Apple->Parent->Behaviors->attach('Test');
|
||||
$Apple->Parent->Behaviors->load('Test');
|
||||
$Apple->unbindModel(array('belongsTo' => array('Parent')));
|
||||
$this->assertSame($Apple->find('all', $conditions), $wellBehaved);
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('before' => 'off'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('before' => 'off'));
|
||||
$this->assertSame($expected, $Apple->find('all', $conditions));
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('before' => 'test'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('before' => 'test'));
|
||||
$this->assertSame($expected, $Apple->find('all', $conditions));
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('before' => 'modify'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('before' => 'modify'));
|
||||
$expected2 = array(
|
||||
array(
|
||||
'Apple' => array('id' => 1),
|
||||
|
|
@ -806,13 +831,13 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Apple->find('all', $conditions);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('after' => 'off'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('after' => 'off'));
|
||||
$this->assertEquals($expected, $Apple->find('all', $conditions));
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('after' => 'test'));
|
||||
$this->assertEquals($expected, $Apple->find('all', $conditions));
|
||||
|
||||
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test2'));
|
||||
$Apple->Parent->Behaviors->load('Test', array('after' => 'test2'));
|
||||
$this->assertEquals($expected, $Apple->find('all', $conditions));
|
||||
}
|
||||
|
||||
|
|
@ -825,25 +850,25 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$Sample = new Sample();
|
||||
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'on'));
|
||||
$Sample->create();
|
||||
$this->assertSame(false, $Sample->save($record));
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'off'));
|
||||
$Sample->create();
|
||||
$result = $Sample->save($record);
|
||||
$expected = $record;
|
||||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'test'));
|
||||
$Sample->create();
|
||||
$result = $Sample->save($record);
|
||||
$expected = $record;
|
||||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'modify'));
|
||||
$expected = Hash::insert($record, 'Sample.name', 'sample99 modified before');
|
||||
$Sample->create();
|
||||
$result = $Sample->save($record);
|
||||
|
|
@ -853,21 +878,21 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$Sample->Behaviors->disable('Test');
|
||||
$this->assertSame($record, $Sample->save($record));
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
|
||||
$expected = Hash::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
|
||||
$Sample->create();
|
||||
$result = $Sample->save($record);
|
||||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
|
||||
$expected = Hash::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
|
||||
$Sample->create();
|
||||
$result = $Sample->save($record);
|
||||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
|
||||
$Sample->Behaviors->load('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
|
||||
$Sample->create();
|
||||
$expected = $record;
|
||||
unset($expected['Sample']['name']);
|
||||
|
|
@ -875,23 +900,23 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
|
||||
$Sample->Behaviors->load('Test', array('afterSave' => 'test2'));
|
||||
$Sample->create();
|
||||
$expected = $record;
|
||||
$result = $Sample->save($record);
|
||||
$expected['Sample']['id'] = $Sample->id;
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
|
||||
$Sample->Behaviors->load('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
|
||||
$Sample->recursive = -1;
|
||||
$record2 = $Sample->read(null, 1);
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
|
||||
$Sample->Behaviors->load('Test', array('afterSave' => 'on'));
|
||||
$expected = Hash::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
|
||||
$Sample->create();
|
||||
$this->assertSame($expected, $Sample->save($record2));
|
||||
|
||||
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
|
||||
$Sample->Behaviors->load('Test', array('afterSave' => 'modify'));
|
||||
$expected = Hash::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
|
||||
$Sample->create();
|
||||
$this->assertSame($expected, $Sample->save($record2));
|
||||
|
|
@ -905,29 +930,29 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
public function testBehaviorDeleteCallbacks() {
|
||||
$Apple = new Apple();
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'beforeDelete' => 'off'));
|
||||
$this->assertSame($Apple->delete(6), true);
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'off', 'beforeDelete' => 'off'));
|
||||
$this->assertTrue($Apple->delete(6));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'on'));
|
||||
$this->assertSame($Apple->delete(4), false);
|
||||
$Apple->Behaviors->load('Test', array('beforeDelete' => 'on'));
|
||||
$this->assertFalse($Apple->delete(4));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'test2'));
|
||||
$Apple->Behaviors->load('Test', array('beforeDelete' => 'test2'));
|
||||
|
||||
ob_start();
|
||||
$results = $Apple->delete(4);
|
||||
$this->assertSame(trim(ob_get_clean()), 'beforeDelete success (cascading)');
|
||||
$this->assertSame($results, true);
|
||||
$this->assertTrue($results);
|
||||
|
||||
ob_start();
|
||||
$results = $Apple->delete(3, false);
|
||||
$this->assertSame(trim(ob_get_clean()), 'beforeDelete success');
|
||||
$this->assertSame($results, true);
|
||||
$this->assertTrue($results);
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'off', 'afterDelete' => 'on'));
|
||||
$Apple->Behaviors->load('Test', array('beforeDelete' => 'off', 'afterDelete' => 'on'));
|
||||
ob_start();
|
||||
$results = $Apple->delete(2, false);
|
||||
$this->assertSame(trim(ob_get_clean()), 'afterDelete success');
|
||||
$this->assertSame($results, true);
|
||||
$this->assertTrue($results);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -938,7 +963,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
public function testBehaviorOnErrorCallback() {
|
||||
$Apple = new Apple();
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'onError' => 'on'));
|
||||
$Apple->Behaviors->load('Test', array('beforeFind' => 'off', 'onError' => 'on'));
|
||||
ob_start();
|
||||
$Apple->Behaviors->Test->onError($Apple, '');
|
||||
$this->assertSame(trim(ob_get_clean()), 'onError trigger success');
|
||||
|
|
@ -952,18 +977,18 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
public function testBehaviorValidateCallback() {
|
||||
$Apple = new Apple();
|
||||
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$this->assertSame($Apple->validates(), true);
|
||||
$Apple->Behaviors->load('Test');
|
||||
$this->assertTrue($Apple->validates());
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('validate' => 'on'));
|
||||
$this->assertSame($Apple->validates(), false);
|
||||
$Apple->Behaviors->load('Test', array('validate' => 'on'));
|
||||
$this->assertFalse($Apple->validates());
|
||||
$this->assertSame($Apple->validationErrors, array('name' => array(true)));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('validate' => 'stop'));
|
||||
$this->assertSame($Apple->validates(), false);
|
||||
$Apple->Behaviors->load('Test', array('validate' => 'stop'));
|
||||
$this->assertFalse($Apple->validates());
|
||||
$this->assertSame($Apple->validationErrors, array('name' => array(true, true)));
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('validate' => 'whitelist'));
|
||||
$Apple->Behaviors->load('Test', array('validate' => 'whitelist'));
|
||||
$Apple->validates();
|
||||
$this->assertSame($Apple->whitelist, array());
|
||||
|
||||
|
|
@ -980,14 +1005,14 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
public function testBehaviorValidateAfterCallback() {
|
||||
$Apple = new Apple();
|
||||
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$this->assertSame($Apple->validates(), true);
|
||||
$Apple->Behaviors->load('Test');
|
||||
$this->assertTrue($Apple->validates());
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterValidate' => 'on'));
|
||||
$this->assertSame($Apple->validates(), true);
|
||||
$Apple->Behaviors->load('Test', array('afterValidate' => 'on'));
|
||||
$this->assertTrue($Apple->validates());
|
||||
$this->assertSame($Apple->validationErrors, array());
|
||||
|
||||
$Apple->Behaviors->attach('Test', array('afterValidate' => 'test'));
|
||||
$Apple->Behaviors->load('Test', array('afterValidate' => 'test'));
|
||||
$Apple->data = array('bar');
|
||||
$Apple->validates();
|
||||
$this->assertEquals(array('foo'), $Apple->data);
|
||||
|
|
@ -1000,7 +1025,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBehaviorValidateMethods() {
|
||||
$Apple = new Apple();
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$Apple->Behaviors->load('Test');
|
||||
$Apple->validate['color'] = 'validateField';
|
||||
|
||||
$result = $Apple->save(array('name' => 'Genetically Modified Apple', 'color' => 'Orange'));
|
||||
|
|
@ -1018,7 +1043,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBehaviorMethodDispatching() {
|
||||
$Apple = new Apple();
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$Apple->Behaviors->load('Test');
|
||||
|
||||
$expected = 'working';
|
||||
$this->assertEquals($expected, $Apple->testMethod());
|
||||
|
|
@ -1043,7 +1068,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testBehaviorMethodDispatchingWithData() {
|
||||
$Apple = new Apple();
|
||||
$Apple->Behaviors->attach('Test');
|
||||
$Apple->Behaviors->load('Test');
|
||||
|
||||
$Apple->set('field', 'value');
|
||||
$this->assertTrue($Apple->testData());
|
||||
|
|
@ -1064,7 +1089,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('Comment', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test4');
|
||||
$Article->Behaviors->load('Test4');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('Comment', $result));
|
||||
|
||||
|
|
@ -1073,7 +1098,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('User', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test5');
|
||||
$Article->Behaviors->load('Test5');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('User', $result));
|
||||
|
||||
|
|
@ -1082,7 +1107,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('Tag', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test6');
|
||||
$Article->Behaviors->load('Test6');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('Comment', $result));
|
||||
|
||||
|
|
@ -1092,7 +1117,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$result = $Comment->find('first');
|
||||
$this->assertFalse(array_key_exists('Attachment', $result));
|
||||
|
||||
$Comment->Behaviors->attach('Test7');
|
||||
$Comment->Behaviors->load('Test7');
|
||||
$result = $Comment->find('first');
|
||||
$this->assertTrue(array_key_exists('Attachment', $result));
|
||||
}
|
||||
|
|
@ -1106,8 +1131,8 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$Sample = new Sample();
|
||||
$Sample->actsAs = array('Test3' => array('bar'), 'Test2' => array('foo', 'bar'));
|
||||
$Sample->Behaviors->init($Sample->alias, $Sample->actsAs);
|
||||
$Sample->Behaviors->attach('Test2');
|
||||
$Sample->Behaviors->detach('Test3');
|
||||
$Sample->Behaviors->load('Test2');
|
||||
$Sample->Behaviors->unload('Test3');
|
||||
|
||||
$Sample->Behaviors->trigger('beforeTest', array(&$Sample));
|
||||
}
|
||||
|
|
@ -1118,7 +1143,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testHasMethodBasic() {
|
||||
$Sample = new Sample();
|
||||
new Sample();
|
||||
$Collection = new BehaviorCollection();
|
||||
$Collection->init('Sample', array('Test', 'Test2'));
|
||||
|
||||
|
|
@ -1134,7 +1159,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testHasMethodMappedMethods() {
|
||||
$Sample = new Sample();
|
||||
new Sample();
|
||||
$Collection = new BehaviorCollection();
|
||||
$Collection->init('Sample', array('Test', 'Test2'));
|
||||
|
||||
|
|
@ -1148,7 +1173,7 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testHasMethodAsCallback() {
|
||||
$Sample = new Sample();
|
||||
new Sample();
|
||||
$Collection = new BehaviorCollection();
|
||||
$Collection->init('Sample', array('Test', 'Test2'));
|
||||
|
||||
|
|
@ -1165,4 +1190,79 @@ class BehaviorCollectionTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that behavior priority
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBehaviorOrderCallbacks() {
|
||||
$model = ClassRegistry::init('Orangutan');
|
||||
$model->Behaviors->init('Orangutan', array(
|
||||
'Second' => array('priority' => 9),
|
||||
'Third',
|
||||
'First' => array('priority' => 8),
|
||||
));
|
||||
|
||||
$this->assertEmpty($model->called);
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'FirstBehavior',
|
||||
'SecondBehavior',
|
||||
'ThirdBehavior',
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
|
||||
$model->called = array();
|
||||
$model->Behaviors->load('Third', array('priority' => 1));
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'ThirdBehavior',
|
||||
'FirstBehavior',
|
||||
'SecondBehavior'
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
|
||||
$model->called = array();
|
||||
$model->Behaviors->load('First');
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'ThirdBehavior',
|
||||
'SecondBehavior',
|
||||
'FirstBehavior'
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
|
||||
$model->called = array();
|
||||
$model->Behaviors->unload('Third');
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'SecondBehavior',
|
||||
'FirstBehavior'
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
|
||||
$model->called = array();
|
||||
$model->Behaviors->disable('Second');
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'FirstBehavior'
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
|
||||
$model->called = array();
|
||||
$model->Behaviors->enable('Second');
|
||||
|
||||
$model->find('first');
|
||||
$expected = array(
|
||||
'SecondBehavior',
|
||||
'FirstBehavior'
|
||||
);
|
||||
$this->assertEquals($expected, $model->called);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,18 @@
|
|||
/**
|
||||
* Test for Schema database management
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* @since CakePHP(tm) v 1.2.0.5550
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeSchema', 'Model');
|
||||
|
|
@ -28,17 +26,10 @@ App::uses('CakeTestFixture', 'TestSuite/Fixture');
|
|||
*/
|
||||
class MyAppSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'MyApp'
|
||||
*/
|
||||
public $name = 'MyApp';
|
||||
|
||||
/**
|
||||
* connection property
|
||||
*
|
||||
* @var string 'test'
|
||||
* @var string
|
||||
*/
|
||||
public $connection = 'test';
|
||||
|
||||
|
|
@ -83,24 +74,6 @@ class MyAppSchema extends CakeSchema {
|
|||
*/
|
||||
protected $_foo = array('bar');
|
||||
|
||||
/**
|
||||
* setup method
|
||||
*
|
||||
* @param mixed $version
|
||||
* @return void
|
||||
*/
|
||||
public function setup($version) {
|
||||
}
|
||||
|
||||
/**
|
||||
* teardown method
|
||||
*
|
||||
* @param mixed $version
|
||||
* @return void
|
||||
*/
|
||||
public function teardown($version) {
|
||||
}
|
||||
|
||||
/**
|
||||
* getVar method
|
||||
*
|
||||
|
|
@ -126,7 +99,7 @@ class TestAppSchema extends CakeSchema {
|
|||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'MyApp'
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'MyApp';
|
||||
|
||||
|
|
@ -136,7 +109,7 @@ class TestAppSchema extends CakeSchema {
|
|||
* @var array
|
||||
*/
|
||||
public $comments = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0,'key' => 'primary'),
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'article_id' => array('type' => 'integer', 'null' => false),
|
||||
'user_id' => array('type' => 'integer', 'null' => false),
|
||||
'comment' => array('type' => 'text', 'null' => true, 'default' => null),
|
||||
|
|
@ -198,6 +171,8 @@ class TestAppSchema extends CakeSchema {
|
|||
public $datatypes = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
|
||||
'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'),
|
||||
'huge_int' => array('type' => 'biginteger'),
|
||||
'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
|
||||
'tableParameters' => array()
|
||||
|
|
@ -230,17 +205,10 @@ class TestAppSchema extends CakeSchema {
|
|||
*/
|
||||
class SchemaPost extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SchemaPost'
|
||||
*/
|
||||
public $name = 'SchemaPost';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'posts';
|
||||
|
||||
|
|
@ -266,17 +234,10 @@ class SchemaPost extends CakeTestModel {
|
|||
*/
|
||||
class SchemaComment extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SchemaComment'
|
||||
*/
|
||||
public $name = 'SchemaComment';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'comments'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'comments';
|
||||
|
||||
|
|
@ -295,17 +256,10 @@ class SchemaComment extends CakeTestModel {
|
|||
*/
|
||||
class SchemaTag extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SchemaTag'
|
||||
*/
|
||||
public $name = 'SchemaTag';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'tags'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'tags';
|
||||
|
||||
|
|
@ -324,17 +278,10 @@ class SchemaTag extends CakeTestModel {
|
|||
*/
|
||||
class SchemaDatatype extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SchemaDatatype'
|
||||
*/
|
||||
public $name = 'SchemaDatatype';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'datatypes'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'datatypes';
|
||||
}
|
||||
|
|
@ -347,17 +294,9 @@ class SchemaDatatype extends CakeTestModel {
|
|||
* its source cache populated - I.e. if the test is run within a group
|
||||
*
|
||||
* @uses CakeTestModel
|
||||
* @package
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class Testdescribe extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Testdescribe'
|
||||
*/
|
||||
public $name = 'Testdescribe';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -367,24 +306,17 @@ class Testdescribe extends CakeTestModel {
|
|||
*/
|
||||
class SchemaCrossDatabase extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SchemaCrossDatabase'
|
||||
*/
|
||||
public $name = 'SchemaCrossDatabase';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'cross_database';
|
||||
|
||||
/**
|
||||
* useDbConfig property
|
||||
*
|
||||
* @var string 'test2'
|
||||
* @var string
|
||||
*/
|
||||
public $useDbConfig = 'test2';
|
||||
}
|
||||
|
|
@ -399,13 +331,14 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
|
|||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'CrossDatabase'
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'CrossDatabase';
|
||||
|
||||
/**
|
||||
* table property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $table = 'cross_database';
|
||||
|
||||
|
|
@ -437,13 +370,6 @@ class SchemaCrossDatabaseFixture extends CakeTestFixture {
|
|||
*/
|
||||
class SchemaPrefixAuthUser extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'SchemaPrefixAuthUser';
|
||||
|
||||
/**
|
||||
* table prefix
|
||||
*
|
||||
|
|
@ -510,25 +436,7 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
*/
|
||||
public function testSchemaName() {
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some.name.with.dots');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithDots', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some-name-with-dashes');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithDashes', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some name with spaces');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithSpaces', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some,name;with&weird=characters');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithWeirdCharacters', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'app');
|
||||
$this->assertEquals('App', $Schema->name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -587,7 +495,6 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
/**
|
||||
* testSchemaReadWithAppModel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function testSchemaReadWithAppModel() {
|
||||
|
|
@ -595,7 +502,7 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
ConnectionManager::drop('default');
|
||||
ConnectionManager::create('default', $connections['test']);
|
||||
try {
|
||||
$read = $this->Schema->read(array(
|
||||
$this->Schema->read(array(
|
||||
'connection' => 'default',
|
||||
'name' => 'TestApp',
|
||||
'models' => array('AppModel')
|
||||
|
|
@ -637,8 +544,6 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
$config = ConnectionManager::getDataSource('test')->config;
|
||||
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
|
||||
|
||||
$model = new SchemaPrefixAuthUser();
|
||||
|
||||
$Schema = new CakeSchema();
|
||||
$read = $Schema->read(array(
|
||||
'connection' => 'test',
|
||||
|
|
@ -762,6 +667,39 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
);
|
||||
$result = $this->Schema->generateTable('posts', $posts);
|
||||
$this->assertRegExp('/public \$posts/', $result);
|
||||
|
||||
$posts = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
|
||||
'author_id' => array('type' => 'integer', 'null' => false),
|
||||
'title' => array('type' => 'string', 'null' => false),
|
||||
'body' => array('type' => 'text', 'null' => true, 'default' => null),
|
||||
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
|
||||
'indexes' => array(
|
||||
'PRIMARY' => array('column' => 'id', 'unique' => true),
|
||||
'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext')
|
||||
)
|
||||
);
|
||||
$result = $this->Schema->generateTable('fields', $posts);
|
||||
$this->assertRegExp('/public \$fields/', $result);
|
||||
$this->assertRegExp('/\'type\' \=\> \'fulltext\'/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that tables with unsupported name are not getting through
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateInvalidTable() {
|
||||
$invalidTableName = 'invalid name !@#$%^&*()';
|
||||
$expectedException = "Invalid table name '{$invalidTableName}'";
|
||||
try{
|
||||
$this->Schema->generateTable($invalidTableName, array());
|
||||
$this->fail("Expected exception \"{$expectedException}\" not thrown");
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals($expectedException, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -848,13 +786,13 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
$compare = $New->compare($this->Schema, $tables);
|
||||
$expected = array(
|
||||
'ratings' => array(
|
||||
'add' => array(
|
||||
'create' => array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'),
|
||||
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null, 'after' => 'id'),
|
||||
'model' => array('type' => 'varchar', 'null' => false, 'default' => null, 'after' => 'foreign_key'),
|
||||
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null, 'after' => 'model'),
|
||||
'created' => array('type' => 'datetime', 'null' => false, 'default' => null, 'after' => 'value'),
|
||||
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null, 'after' => 'created'),
|
||||
'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => null),
|
||||
'model' => array('type' => 'varchar', 'null' => false, 'default' => null),
|
||||
'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => null),
|
||||
'created' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
||||
'modified' => array('type' => 'datetime', 'null' => false, 'default' => null),
|
||||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
|
||||
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM')
|
||||
)
|
||||
|
|
@ -1031,6 +969,63 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $compare, 'Invalid SQL, datetime does not have length');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comparing with field length/limit changed from some non-default value to the default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareLimitToDefault() {
|
||||
$old = array(
|
||||
'posts' => array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => 1, 'key' => 'primary'),
|
||||
'author_id' => array('type' => 'integer', 'null' => false, 'limit' => 5),
|
||||
'title' => array('type' => 'string', 'null' => true, 'length' => 45),
|
||||
'indexes' => array(
|
||||
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
||||
),
|
||||
'tableParameters' => array(
|
||||
'charset' => 'latin1',
|
||||
'collate' => 'latin1_general_ci'
|
||||
)
|
||||
),
|
||||
);
|
||||
$new = array(
|
||||
'posts' => array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
|
||||
'author_id' => array('type' => 'integer', 'null' => false),
|
||||
'title' => array('type' => 'varchar', 'null' => true),
|
||||
'indexes' => array(
|
||||
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
||||
),
|
||||
'tableParameters' => array(
|
||||
'charset' => 'latin1',
|
||||
'collate' => 'latin1_general_ci'
|
||||
)
|
||||
),
|
||||
);
|
||||
$compare = $this->Schema->compare($old, $new);
|
||||
$expected = array(
|
||||
'posts' => array(
|
||||
'change' => array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
'key' => 'primary'
|
||||
),
|
||||
'author_id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'null' => true,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $compare, 'Invalid SQL, field length change not detected');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSchemaLoading method
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@
|
|||
/**
|
||||
* Connection Manager tests
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* 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
|
||||
* @since CakePHP(tm) v 1.2.0.5550
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ConnectionManager', 'Model');
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +62,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
|||
$name = 'test_get_datasource';
|
||||
$config = array('datasource' => 'Test2Source');
|
||||
|
||||
$connection = ConnectionManager::create($name, $config);
|
||||
ConnectionManager::create($name, $config);
|
||||
$connections = ConnectionManager::enumConnectionObjects();
|
||||
$this->assertTrue((bool)(count(array_keys($connections) >= 1)));
|
||||
|
||||
|
|
@ -190,7 +190,6 @@ class ConnectionManagerTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetSourceName() {
|
||||
$connections = ConnectionManager::enumConnectionObjects();
|
||||
$source = ConnectionManager::getDataSource('test');
|
||||
$result = ConnectionManager::getSourceName($source);
|
||||
|
||||
|
|
@ -228,7 +227,7 @@ class ConnectionManagerTest extends CakeTestCase {
|
|||
*/
|
||||
public function testLoadDataSourceException() {
|
||||
$connection = array('classname' => 'NonExistentDataSource', 'filename' => 'non_existent');
|
||||
$loaded = ConnectionManager::loadDataSource($connection);
|
||||
ConnectionManager::loadDataSource($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,37 +2,46 @@
|
|||
/**
|
||||
* SessionTest 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.Datasource
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeSession', 'Model/Datasource');
|
||||
App::uses('DatabaseSession', 'Model/Datasource/Session');
|
||||
App::uses('CacheSession', 'Model/Datasource/Session');
|
||||
|
||||
/**
|
||||
* TestCakeSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestCakeSession extends CakeSession {
|
||||
|
||||
public static function setUserAgent($value) {
|
||||
self::$_userAgent = $value;
|
||||
static::$_userAgent = $value;
|
||||
}
|
||||
|
||||
public static function setHost($host) {
|
||||
self::_setHost($host);
|
||||
static::_setHost($host);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TestCacheSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestCacheSession extends CacheSession {
|
||||
|
||||
protected function _writeSession() {
|
||||
|
|
@ -41,6 +50,11 @@ class TestCacheSession extends CacheSession {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* TestDatabaseSession
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource
|
||||
*/
|
||||
class TestDatabaseSession extends DatabaseSession {
|
||||
|
||||
protected function _writeSession() {
|
||||
|
|
@ -72,7 +86,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public static function setupBeforeClass() {
|
||||
// Make sure garbage colector will be called
|
||||
self::$_gcDivisor = ini_get('session.gc_divisor');
|
||||
static::$_gcDivisor = ini_get('session.gc_divisor');
|
||||
ini_set('session.gc_divisor', '1');
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +97,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public static function teardownAfterClass() {
|
||||
// Revert to the default setting
|
||||
ini_set('session.gc_divisor', self::$_gcDivisor);
|
||||
ini_set('session.gc_divisor', static::$_gcDivisor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +114,6 @@ class CakeSessionTest extends CakeTestCase {
|
|||
'cookieTimeout' => 120,
|
||||
'ini' => array(),
|
||||
));
|
||||
TestCakeSession::init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,12 +121,12 @@ class CakeSessionTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function teardown() {
|
||||
public function tearDown() {
|
||||
if (TestCakeSession::started()) {
|
||||
session_write_close();
|
||||
}
|
||||
unset($_SESSION);
|
||||
parent::teardown();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -231,7 +244,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
TestCakeSession::write('SessionTestCase', 'value');
|
||||
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
||||
|
||||
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false);
|
||||
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,7 +257,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$result = TestCakeSession::read('testing');
|
||||
$this->assertEquals('1,2,3', $result);
|
||||
|
||||
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two','3' => 'three'));
|
||||
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two', '3' => 'three'));
|
||||
$result = TestCakeSession::read('testing.1');
|
||||
$this->assertEquals('one', $result);
|
||||
|
||||
|
|
@ -267,7 +280,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testReadyEmpty() {
|
||||
$this->assertFalse(TestCakeSession::read(''));
|
||||
$this->assertNull(TestCakeSession::read(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -294,9 +307,9 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testWriteEmptyKey() {
|
||||
$this->assertFalse(TestCakeSession::write('', 'graham'));
|
||||
$this->assertFalse(TestCakeSession::write('', ''));
|
||||
$this->assertFalse(TestCakeSession::write(''));
|
||||
$this->assertTrue(TestCakeSession::write('', 'graham'));
|
||||
$this->assertTrue(TestCakeSession::write('', ''));
|
||||
$this->assertTrue(TestCakeSession::write(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -315,6 +328,28 @@ class CakeSessionTest extends CakeTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test consuming session data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConsume() {
|
||||
TestCakeSession::write('Some.string', 'value');
|
||||
TestCakeSession::write('Some.array', array('key1' => 'value1', 'key2' => 'value2'));
|
||||
$this->assertEquals('value', TestCakeSession::read('Some.string'));
|
||||
$value = TestCakeSession::consume('Some.string');
|
||||
$this->assertEquals('value', $value);
|
||||
$this->assertFalse(TestCakeSession::check('Some.string'));
|
||||
$value = TestCakeSession::consume('');
|
||||
$this->assertNull($value);
|
||||
$value = TestCakeSession::consume(null);
|
||||
$this->assertNull($value);
|
||||
$value = TestCakeSession::consume('Some.array');
|
||||
$expected = array('key1' => 'value1', 'key2' => 'value2');
|
||||
$this->assertEquals($expected, $value);
|
||||
$this->assertFalse(TestCakeSession::check('Some.array'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testId method
|
||||
*
|
||||
|
|
@ -346,21 +381,6 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertTrue(TestCakeSession::started());
|
||||
}
|
||||
|
||||
/**
|
||||
* testError method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testError() {
|
||||
TestCakeSession::read('Does.not.exist');
|
||||
$result = TestCakeSession::error();
|
||||
$this->assertEquals("Does.not.exist doesn't exist", $result);
|
||||
|
||||
TestCakeSession::delete('Failing.delete');
|
||||
$result = TestCakeSession::error();
|
||||
$this->assertEquals("Failing.delete doesn't exist", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDel method
|
||||
*
|
||||
|
|
@ -373,11 +393,47 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertTrue(TestCakeSession::check('Delete'));
|
||||
|
||||
$this->assertTrue(TestCakeSession::write('Clearing.sale', 'everything must go'));
|
||||
$this->assertFalse(TestCakeSession::delete(''));
|
||||
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
|
||||
$this->assertFalse(TestCakeSession::delete(null));
|
||||
$this->assertTrue(TestCakeSession::check('Clearing.sale'));
|
||||
|
||||
$this->assertTrue(TestCakeSession::delete('Clearing'));
|
||||
$this->assertFalse(TestCakeSession::check('Clearing.sale'));
|
||||
$this->assertFalse(TestCakeSession::check('Clearing'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteEmptyString() {
|
||||
TestCakeSession::write('', 'empty string');
|
||||
$this->assertTrue(TestCakeSession::delete(''));
|
||||
$this->assertFalse(TestCakeSession::check(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* testClear method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
$this->assertTrue(TestCakeSession::write('Delete.me', 'Clearing out'));
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertFalse(TestCakeSession::check('Delete.me'));
|
||||
$this->assertFalse(TestCakeSession::check('Delete'));
|
||||
|
||||
TestCakeSession::write('Some.string', 'value');
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertNull(TestCakeSession::read('Some'));
|
||||
|
||||
TestCakeSession::write('Some.string.array', array('values'));
|
||||
TestCakeSession::clear(false);
|
||||
$this->assertFalse(TestCakeSession::read());
|
||||
}
|
||||
|
||||
/**
|
||||
* testDestroy method
|
||||
*
|
||||
|
|
@ -431,7 +487,8 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testCheckEmpty() {
|
||||
$this->assertFalse(TestCakeSession::check());
|
||||
$this->assertFalse(TestCakeSession::check(''));
|
||||
$this->assertFalse(TestCakeSession::check(null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -442,10 +499,10 @@ class CakeSessionTest extends CakeTestCase {
|
|||
public function testKeyExploit() {
|
||||
$key = "a'] = 1; phpinfo(); \$_SESSION['a";
|
||||
$result = TestCakeSession::write($key, 'haxored');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = TestCakeSession::read($key);
|
||||
$this->assertEquals('haxored', $result);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -454,6 +511,10 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testReadingSavedEmpty() {
|
||||
TestCakeSession::write('', 'empty string');
|
||||
$this->assertTrue(TestCakeSession::check(''));
|
||||
$this->assertEquals('empty string', TestCakeSession::read(''));
|
||||
|
||||
TestCakeSession::write('SessionTestCase', 0);
|
||||
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
||||
|
||||
|
|
@ -465,7 +526,23 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
||||
|
||||
TestCakeSession::write('SessionTestCase', null);
|
||||
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
||||
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test te cacheLimiter settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheLimiter() {
|
||||
Configure::write('Session.cacheLimiter', 'public');
|
||||
TestCakeSession::start();
|
||||
$this->assertSame('public', session_cache_limiter());
|
||||
|
||||
Configure::write('Session.cacheLimiter', 'private');
|
||||
TestCakeSession::destroy();
|
||||
TestCakeSession::start();
|
||||
$this->assertSame('private', session_cache_limiter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -547,9 +624,13 @@ class CakeSessionTest extends CakeTestCase {
|
|||
'engine' => 'TestAppLibSession'
|
||||
)
|
||||
));
|
||||
TestCakeSession::destroy();
|
||||
|
||||
TestCakeSession::start();
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
||||
TestCakeSession::destroy();
|
||||
$this->assertFalse(TestCakeSession::started());
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
|
|
@ -571,9 +652,12 @@ class CakeSessionTest extends CakeTestCase {
|
|||
)
|
||||
));
|
||||
|
||||
TestCakeSession::destroy();
|
||||
TestCakeSession::start();
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
||||
TestCakeSession::destroy();
|
||||
$this->assertFalse(TestCakeSession::started());
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
|
|
@ -658,7 +742,7 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, TestCakeSession::id());
|
||||
|
||||
TestCakeSession::renew();
|
||||
$this->assertFalse($expected == TestCakeSession::id());
|
||||
$this->assertFalse($expected === TestCakeSession::id());
|
||||
|
||||
$expected = session_id();
|
||||
$this->assertEquals($expected, TestCakeSession::id());
|
||||
|
|
@ -751,4 +835,31 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->assertEquals(400, Configure::read('Session.timeout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves that invalid sessions will be destroyed and re-created
|
||||
* if invalid
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidSessionRenew() {
|
||||
TestCakeSession::start();
|
||||
$this->assertNotEmpty($_SESSION['Config']);
|
||||
$data = $_SESSION;
|
||||
|
||||
session_write_close();
|
||||
$_SESSION = null;
|
||||
|
||||
TestCakeSession::start();
|
||||
$this->assertEquals($data, $_SESSION);
|
||||
TestCakeSession::write('Foo', 'Bar');
|
||||
|
||||
session_write_close();
|
||||
$_SESSION = null;
|
||||
|
||||
TestCakeSession::userAgent('bogus!');
|
||||
TestCakeSession::start();
|
||||
$this->assertNotEquals($data, $_SESSION);
|
||||
$this->assertEquals('bogus!', $_SESSION['Config']['userAgent']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* DataSourceTest 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 Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
* 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.Datasource
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @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');
|
||||
|
|
@ -58,7 +57,7 @@ class TestSource extends DataSource {
|
|||
/**
|
||||
* listSources
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function listSources() {
|
||||
return null;
|
||||
|
|
@ -67,7 +66,7 @@ class TestSource extends DataSource {
|
|||
/**
|
||||
* Returns the schema for the datasource to enable create/update
|
||||
*
|
||||
* @param object $Model
|
||||
* @param Model $Model
|
||||
* @return array
|
||||
*/
|
||||
public function describe(Model $Model) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,19 +2,17 @@
|
|||
/**
|
||||
* DboPostgresTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @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');
|
||||
|
|
@ -66,17 +64,10 @@ class DboPostgresTestDb extends Postgres {
|
|||
*/
|
||||
class PostgresTestModel extends Model {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PostgresTestModel'
|
||||
*/
|
||||
public $name = 'PostgresTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
|
@ -141,7 +132,8 @@ class PostgresTestModel extends Model {
|
|||
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
|
||||
'some_uuid' => array('type' => 'uuid', 'null' => '1', 'default' => null),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -154,17 +146,10 @@ class PostgresTestModel extends Model {
|
|||
*/
|
||||
class PostgresClientTestModel extends Model {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PostgresClientTestModel'
|
||||
*/
|
||||
public $name = 'PostgresClientTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
|
@ -178,8 +163,8 @@ class PostgresClientTestModel extends Model {
|
|||
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +181,7 @@ class PostgresTest extends CakeTestCase {
|
|||
* Do not automatically load fixtures for each test, they will be loaded manually
|
||||
* using CakeTestCase::loadFixtures
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
|
@ -227,8 +212,10 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Cache.disable', true);
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
$this->skipIf(!($this->Dbo instanceof Postgres));
|
||||
|
|
@ -239,8 +226,10 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('Cache.disable', false);
|
||||
unset($this->Dbo2);
|
||||
}
|
||||
|
|
@ -248,6 +237,7 @@ class PostgresTest extends CakeTestCase {
|
|||
/**
|
||||
* Test field quoting method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFieldQuoting() {
|
||||
$fields = array(
|
||||
|
|
@ -268,7 +258,8 @@ class PostgresTest extends CakeTestCase {
|
|||
'"PostgresTestModel"."comments" AS "PostgresTestModel__comments"',
|
||||
'"PostgresTestModel"."last_login" AS "PostgresTestModel__last_login"',
|
||||
'"PostgresTestModel"."created" AS "PostgresTestModel__created"',
|
||||
'"PostgresTestModel"."updated" AS "PostgresTestModel__updated"'
|
||||
'"PostgresTestModel"."updated" AS "PostgresTestModel__updated"',
|
||||
'"PostgresTestModel"."some_uuid" AS "PostgresTestModel__some_uuid"'
|
||||
);
|
||||
|
||||
$result = $this->Dbo->fields($this->model);
|
||||
|
|
@ -307,6 +298,15 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals('string', $this->Dbo2->column('character varying'));
|
||||
$this->assertEquals('time', $this->Dbo2->column('time without time zone'));
|
||||
$this->assertEquals('datetime', $this->Dbo2->column('timestamp without time zone'));
|
||||
$this->assertEquals('decimal', $this->Dbo2->column('decimal'));
|
||||
$this->assertEquals('decimal', $this->Dbo2->column('numeric'));
|
||||
$this->assertEquals('float', $this->Dbo2->column('float'));
|
||||
$this->assertEquals('float', $this->Dbo2->column('double precision'));
|
||||
$this->assertEquals('uuid', $this->Dbo2->column('uuid'));
|
||||
|
||||
$result = $this->Dbo2->column('bigint');
|
||||
$expected = 'biginteger';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -321,8 +321,8 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals("0", $this->Dbo->value('0', 'integer'));
|
||||
$this->assertEquals('NULL', $this->Dbo->value('', 'integer'));
|
||||
$this->assertEquals('NULL', $this->Dbo->value('', 'float'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value('', 'integer', false));
|
||||
$this->assertEquals("NULL", $this->Dbo->value('', 'float', false));
|
||||
$this->assertEquals('""', $this->Dbo->value('', 'integer', false));
|
||||
$this->assertEquals('""', $this->Dbo->value('', 'float', false));
|
||||
$this->assertEquals("'0.0'", $this->Dbo->value('0.0', 'float'));
|
||||
|
||||
$this->assertEquals("'TRUE'", $this->Dbo->value('t', 'boolean'));
|
||||
|
|
@ -339,6 +339,8 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals("'TRUE'", $this->Dbo->value('1', 'boolean'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(null, 'boolean'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(array()));
|
||||
$this->assertEquals("'550e8400-e29b-41d4-a716-446655440000'", $this->Dbo->value('550e8400-e29b-41d4-a716-446655440000', 'uuid'));
|
||||
$this->assertEquals("NULL", $this->Dbo->value(null, 'uuid'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -348,7 +350,8 @@ class PostgresTest extends CakeTestCase {
|
|||
*/
|
||||
public function testLocalizedFloats() {
|
||||
$restore = setlocale(LC_NUMERIC, 0);
|
||||
setlocale(LC_NUMERIC, 'de_DE');
|
||||
|
||||
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
|
||||
|
||||
$result = $this->db->value(3.141593, 'float');
|
||||
$this->assertEquals("3.141593", $result);
|
||||
|
|
@ -482,6 +485,22 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertEquals($data, $result['BinaryTest']['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests passing PostgreSQL regular expression operators when building queries
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRegexpOperatorConditionsParsing() {
|
||||
$this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
|
||||
$this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
|
||||
$this->assertSame(
|
||||
' WHERE EXTRACT( \'YEAR\' FROM "User"."birthday" ) = 2015',
|
||||
$this->Dbo->conditions(array('EXTRACT( \'YEAR\' FROM User.birthday )' => 2015))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the syntax of generated schema indexes
|
||||
*
|
||||
|
|
@ -530,23 +549,27 @@ class PostgresTest extends CakeTestCase {
|
|||
id serial NOT NULL,
|
||||
"varchar" character varying(40) NOT NULL,
|
||||
"full_length" character varying NOT NULL,
|
||||
"huge_int" bigint NOT NULL,
|
||||
"timestamp" timestamp without time zone,
|
||||
"date" date,
|
||||
CONSTRAINT test_data_types_pkey PRIMARY KEY (id)
|
||||
)');
|
||||
|
||||
$model = new Model(array('name' => 'DatatypeTest', 'ds' => 'test'));
|
||||
$schema = new CakeSchema(array('connection' => 'test'));
|
||||
$result = $schema->read(array(
|
||||
'connection' => 'test',
|
||||
'models' => array('DatatypeTest')
|
||||
));
|
||||
$schema->tables = array('datatype_tests' => $result['tables']['missing']['datatype_tests']);
|
||||
|
||||
$schema->tables = array(
|
||||
'datatype_tests' => $result['tables']['missing']['datatype_tests']
|
||||
);
|
||||
$result = $db1->createSchema($schema, 'datatype_tests');
|
||||
|
||||
$this->assertNotRegExp('/timestamp DEFAULT/', $result);
|
||||
$this->assertRegExp('/\"full_length\"\s*text\s.*,/', $result);
|
||||
$this->assertRegExp('/timestamp\s*,/', $result);
|
||||
$this->assertContains('timestamp ,', $result);
|
||||
$this->assertContains('"huge_int" bigint NOT NULL,', $result);
|
||||
|
||||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
|
||||
|
||||
|
|
@ -562,6 +585,38 @@ class PostgresTest extends CakeTestCase {
|
|||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testCakeSchemaBegserial method
|
||||
*
|
||||
* Test that schema generated postgresql queries are valid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCakeSchemaBigserial() {
|
||||
$db1 = ConnectionManager::getDataSource('test');
|
||||
$db1->cacheSources = false;
|
||||
|
||||
$db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('bigserial_tests') . ' (
|
||||
"id" bigserial NOT NULL,
|
||||
"varchar" character varying(40) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
)');
|
||||
|
||||
$schema = new CakeSchema(array('connection' => 'test'));
|
||||
$result = $schema->read(array(
|
||||
'connection' => 'test',
|
||||
'models' => array('BigserialTest')
|
||||
));
|
||||
$schema->tables = array(
|
||||
'bigserial_tests' => $result['tables']['missing']['bigserial_tests']
|
||||
);
|
||||
$result = $db1->createSchema($schema, 'bigserial_tests');
|
||||
|
||||
$this->assertContains('"id" bigserial NOT NULL,', $result);
|
||||
|
||||
$db1->query('DROP TABLE ' . $db1->fullTableName('bigserial_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index generation from table info.
|
||||
*
|
||||
|
|
@ -657,6 +712,70 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertNotRegExp('/varchar\(36\) NOT NULL/i', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema changing boolean to integer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaBooleanToIntegerField() {
|
||||
$default = array(
|
||||
'connection' => 'test',
|
||||
'name' => 'BoolField',
|
||||
'bool_fields' => array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 50),
|
||||
'active' => array('type' => 'boolean', 'null' => false),
|
||||
)
|
||||
);
|
||||
$Old = new CakeSchema($default);
|
||||
$result = $this->Dbo->query($this->Dbo->createSchema($Old));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$modified = $default;
|
||||
$modified['bool_fields']['active'] = array('type' => 'integer', 'null' => true);
|
||||
|
||||
$New = new CakeSchema($modified);
|
||||
$query = $this->Dbo->alterSchema($New->compare($Old));
|
||||
$result = $this->Dbo->query($query);
|
||||
$this->Dbo->query($this->Dbo->dropSchema($Old));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema changing text to integer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaTextToIntegerField() {
|
||||
$default = array(
|
||||
'connection' => 'test',
|
||||
'name' => 'TextField',
|
||||
'text_fields' => array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'length' => 50),
|
||||
'active' => array('type' => 'text', 'null' => false),
|
||||
)
|
||||
);
|
||||
$Old = new CakeSchema($default);
|
||||
$result = $this->Dbo->query($this->Dbo->createSchema($Old));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$modified = $default;
|
||||
$modified['text_fields']['active'] = array('type' => 'integer', 'null' => true);
|
||||
|
||||
$New = new CakeSchema($modified);
|
||||
$this->Dbo->query($this->Dbo->alterSchema($New->compare($Old)));
|
||||
$result = $this->Dbo->describe('text_fields');
|
||||
|
||||
$this->Dbo->query($this->Dbo->dropSchema($Old));
|
||||
$expected = array(
|
||||
'type' => 'integer',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null,
|
||||
);
|
||||
$this->assertEquals($expected, $result['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alter index capabilities of postgres
|
||||
*
|
||||
|
|
@ -732,6 +851,25 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->Dbo->query($this->Dbo->dropSchema($schema1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the alterSchema RENAME statements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAlterSchemaRenameTo() {
|
||||
$query = $this->Dbo->alterSchema(array(
|
||||
'posts' => array(
|
||||
'change' => array(
|
||||
'title' => array('name' => 'subject', 'type' => 'string', 'null' => false)
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->assertContains('RENAME "title" TO "subject";', $query);
|
||||
$this->assertContains('ALTER COLUMN "subject" TYPE', $query);
|
||||
$this->assertNotContains(";\n\tALTER COLUMN \"subject\" TYPE", $query);
|
||||
$this->assertNotContains('ALTER COLUMN "title" TYPE "subject"', $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it is possible to use virtual field with postgresql
|
||||
*
|
||||
|
|
@ -915,6 +1053,7 @@ class PostgresTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testNestedTransaction() {
|
||||
$this->Dbo->useNestedTransactions = true;
|
||||
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
|
||||
|
||||
$this->loadFixtures('Article');
|
||||
|
|
@ -942,4 +1081,141 @@ class PostgresTest extends CakeTestCase {
|
|||
$this->assertNotEmpty($model->read(null, 1));
|
||||
}
|
||||
|
||||
public function testResetSequence() {
|
||||
$model = new Article();
|
||||
|
||||
$table = $this->Dbo->fullTableName($model, false);
|
||||
$fields = array(
|
||||
'id', 'user_id', 'title', 'body', 'published',
|
||||
);
|
||||
$values = array(
|
||||
array(1, 1, 'test', 'first post', false),
|
||||
array(2, 1, 'test 2', 'second post post', false),
|
||||
);
|
||||
$this->Dbo->insertMulti($table, $fields, $values);
|
||||
$sequence = $this->Dbo->getSequence($table);
|
||||
$result = $this->Dbo->rawQuery("SELECT nextval('$sequence')");
|
||||
$original = $result->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$this->assertTrue($this->Dbo->resetSequence($table, 'id'));
|
||||
$result = $this->Dbo->rawQuery("SELECT currval('$sequence')");
|
||||
$new = $result->fetch(PDO::FETCH_ASSOC);
|
||||
$this->assertTrue($new['currval'] > $original['nextval'], 'Sequence did not update');
|
||||
}
|
||||
|
||||
public function testSettings() {
|
||||
Configure::write('Cache.disable', true);
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
$this->skipIf(!($this->Dbo instanceof Postgres));
|
||||
|
||||
$config2 = $this->Dbo->config;
|
||||
$config2['settings']['datestyle'] = 'sql, dmy';
|
||||
ConnectionManager::create('test2', $config2);
|
||||
$dbo2 = new Postgres($config2, true);
|
||||
$expected = array(array('r' => date('d/m/Y')));
|
||||
$r = $dbo2->fetchRow('SELECT now()::date AS "r"');
|
||||
$this->assertEquals($expected, $r);
|
||||
$dbo2->execute('SET DATESTYLE TO ISO');
|
||||
$dbo2->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the limit function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLimit() {
|
||||
$db = $this->Dbo;
|
||||
|
||||
$result = $db->limit('0');
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $db->limit('10');
|
||||
$this->assertEquals(' LIMIT 10', $result);
|
||||
|
||||
$result = $db->limit('FARTS', 'BOOGERS');
|
||||
$this->assertEquals(' LIMIT 0 OFFSET 0', $result);
|
||||
|
||||
$result = $db->limit(20, 10);
|
||||
$this->assertEquals(' LIMIT 20 OFFSET 10', $result);
|
||||
|
||||
$result = $db->limit(10, 300000000000000000000000000000);
|
||||
$scientificNotation = sprintf('%.1E', 300000000000000000000000000000);
|
||||
$this->assertNotContains($scientificNotation, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that postgres describes UUID columns correctly.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeUuid() {
|
||||
$db = $this->Dbo;
|
||||
$db->execute('CREATE TABLE test_uuid_describe (id UUID PRIMARY KEY, name VARCHAR(255))');
|
||||
$data = $db->describe('test_uuid_describe');
|
||||
|
||||
$expected = array(
|
||||
'type' => 'uuid',
|
||||
'null' => false,
|
||||
'default' => null,
|
||||
'length' => 36,
|
||||
);
|
||||
$this->assertSame($expected, $data['id']);
|
||||
$db->execute('DROP TABLE test_uuid_describe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test describe() behavior for timestamp columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeTimestamp() {
|
||||
$this->loadFixtures('User');
|
||||
$model = ClassRegistry::init('User');
|
||||
$result = $this->Dbo->describe($model);
|
||||
$expected = array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
'default' => null,
|
||||
'length' => 11,
|
||||
'key' => 'primary'
|
||||
),
|
||||
'user' => array(
|
||||
'type' => 'string',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 255
|
||||
),
|
||||
'password' => array(
|
||||
'type' => 'string',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 255
|
||||
),
|
||||
'created' => array(
|
||||
'type' => 'datetime',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null
|
||||
),
|
||||
'updated' => array(
|
||||
'type' => 'datetime',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build column working for new uuid types
|
||||
*/
|
||||
public function testBuildColumnUuid() {
|
||||
$column = array('name' => 'col1', 'type' => 'uuid');
|
||||
$result = $this->Dbo2->buildColumn($column);
|
||||
|
||||
$this->assertEquals('"col1" uuid', $result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* DboSqliteTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @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');
|
||||
App::uses('Sqlite', 'Model/Datasource/Database');
|
||||
|
|
@ -68,7 +68,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Do not automatically load fixtures for each test, they will be loaded manually using CakeTestCase::loadFixtures
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ class SqliteTest extends CakeTestCase {
|
|||
*
|
||||
* @var object
|
||||
*/
|
||||
public $fixtures = array('core.user', 'core.uuid');
|
||||
public $fixtures = array('core.user', 'core.uuid', 'core.datatype');
|
||||
|
||||
/**
|
||||
* Actual DB connection used in testing
|
||||
|
|
@ -89,6 +89,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
|
@ -102,6 +103,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
|
|
@ -111,6 +113,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Tests that SELECT queries from DboSqlite::listSources() are not cached
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTableListCacheDisabling() {
|
||||
$this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
|
||||
|
|
@ -157,6 +160,7 @@ class SqliteTest extends CakeTestCase {
|
|||
/**
|
||||
* Tests that cached table descriptions are saved under the sanitized key name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheKeyName() {
|
||||
Configure::write('Cache.disable', false);
|
||||
|
|
@ -164,8 +168,13 @@ class SqliteTest extends CakeTestCase {
|
|||
$dbName = 'db' . rand() . '$(*%&).db';
|
||||
$this->assertFalse(file_exists(TMP . $dbName));
|
||||
|
||||
$config = $this->Dbo->config;
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
try {
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
} catch (MissingConnectionException $e) {
|
||||
// This might be caused by NTFS file systems, where '*' is a forbidden character. Repeat without this character.
|
||||
$dbName = str_replace('*', '', $dbName);
|
||||
$db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
|
||||
}
|
||||
$this->assertTrue(file_exists(TMP . $dbName));
|
||||
|
||||
$db->execute("CREATE TABLE test_list (id VARCHAR(255));");
|
||||
|
|
@ -253,6 +262,27 @@ class SqliteTest extends CakeTestCase {
|
|||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$data = array(
|
||||
'name' => 'huge',
|
||||
'type' => 'biginteger',
|
||||
'length' => 20,
|
||||
'null' => false,
|
||||
);
|
||||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"huge" bigint(20) NOT NULL';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$data = array(
|
||||
'name' => 'id',
|
||||
'type' => 'biginteger',
|
||||
'length' => 20,
|
||||
'null' => false,
|
||||
'key' => 'primary',
|
||||
);
|
||||
$result = $this->Dbo->buildColumn($data);
|
||||
$expected = '"id" bigint(20) NOT NULL PRIMARY KEY';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -262,7 +292,11 @@ class SqliteTest extends CakeTestCase {
|
|||
*/
|
||||
public function testDescribe() {
|
||||
$this->loadFixtures('User');
|
||||
$Model = new Model(array('name' => 'User', 'ds' => 'test', 'table' => 'users'));
|
||||
$Model = new Model(array(
|
||||
'name' => 'User',
|
||||
'ds' => 'test',
|
||||
'table' => 'users'
|
||||
));
|
||||
|
||||
$this->Dbo->cacheSources = true;
|
||||
Configure::write('Cache.disable', false);
|
||||
|
|
@ -310,6 +344,55 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that datatypes are reflected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDatatypes() {
|
||||
$this->loadFixtures('Datatype');
|
||||
$Model = new Model(array(
|
||||
'name' => 'Datatype',
|
||||
'ds' => 'test',
|
||||
'table' => 'datatypes'
|
||||
));
|
||||
$result = $this->Dbo->describe($Model);
|
||||
$expected = array(
|
||||
'id' => array(
|
||||
'type' => 'integer',
|
||||
'null' => false,
|
||||
'default' => '',
|
||||
'length' => 11,
|
||||
'key' => 'primary',
|
||||
),
|
||||
'float_field' => array(
|
||||
'type' => 'float',
|
||||
'null' => false,
|
||||
'default' => '',
|
||||
'length' => '5,2',
|
||||
),
|
||||
'decimal_field' => array(
|
||||
'type' => 'decimal',
|
||||
'null' => true,
|
||||
'default' => '0.000',
|
||||
'length' => '6,3',
|
||||
),
|
||||
'huge_int' => array(
|
||||
'type' => 'biginteger',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 20,
|
||||
),
|
||||
'bool' => array(
|
||||
'type' => 'boolean',
|
||||
'null' => false,
|
||||
'default' => '0',
|
||||
'length' => null
|
||||
),
|
||||
);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that describe does not corrupt UUID primary keys
|
||||
*
|
||||
|
|
@ -345,6 +428,40 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->Dbo->query('DROP TABLE ' . $tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that describe ignores `default current_timestamp` in timestamp columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDescribeHandleCurrentTimestamp() {
|
||||
$name = $this->Dbo->fullTableName('timestamp_default_values');
|
||||
$sql = <<<SQL
|
||||
CREATE TABLE $name (
|
||||
id INT NOT NULL,
|
||||
phone VARCHAR(10),
|
||||
limit_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
SQL;
|
||||
$this->Dbo->execute($sql);
|
||||
$model = new Model(array(
|
||||
'table' => 'timestamp_default_values',
|
||||
'ds' => 'test',
|
||||
'alias' => 'TimestampDefaultValue'
|
||||
));
|
||||
$result = $this->Dbo->describe($model);
|
||||
$this->Dbo->execute('DROP TABLE ' . $name);
|
||||
|
||||
$this->assertNull($result['limit_date']['default']);
|
||||
|
||||
$schema = new CakeSchema(array(
|
||||
'connection' => 'test',
|
||||
'testdescribes' => $result
|
||||
));
|
||||
$result = $this->Dbo->createSchema($schema);
|
||||
$this->assertContains('"limit_date" timestamp NOT NULL', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test virtualFields with functions.
|
||||
*
|
||||
|
|
@ -362,7 +479,7 @@ class SqliteTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that records can be inserted with uuid primary keys, and
|
||||
* Test that records can be inserted with UUID primary keys, and
|
||||
* that the primary key is not blank
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -372,7 +489,7 @@ class SqliteTest extends CakeTestCase {
|
|||
$Model = ClassRegistry::init('Uuid');
|
||||
|
||||
$data = array(
|
||||
'title' => 'A uuid should work',
|
||||
'title' => 'A UUID should work',
|
||||
'count' => 10
|
||||
);
|
||||
$Model->create($data);
|
||||
|
|
@ -380,7 +497,7 @@ class SqliteTest extends CakeTestCase {
|
|||
$result = $Model->read();
|
||||
|
||||
$this->assertEquals($data['title'], $result['Uuid']['title']);
|
||||
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid');
|
||||
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a UUID');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -389,6 +506,7 @@ class SqliteTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testNestedTransaction() {
|
||||
$this->Dbo->useNestedTransactions = true;
|
||||
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Sqlite version do not support nested transaction');
|
||||
|
||||
$this->loadFixtures('User');
|
||||
|
|
@ -416,4 +534,96 @@ class SqliteTest extends CakeTestCase {
|
|||
$this->assertNotEmpty($model->read(null, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the limit function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLimit() {
|
||||
$db = $this->Dbo;
|
||||
|
||||
$result = $db->limit('0');
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $db->limit('10');
|
||||
$this->assertEquals(' LIMIT 10', $result);
|
||||
|
||||
$result = $db->limit('FARTS', 'BOOGERS');
|
||||
$this->assertEquals(' LIMIT 0 OFFSET 0', $result);
|
||||
|
||||
$result = $db->limit(20, 10);
|
||||
$this->assertEquals(' LIMIT 20 OFFSET 10', $result);
|
||||
|
||||
$result = $db->limit(10, 300000000000000000000000000000);
|
||||
$scientificNotation = sprintf('%.1E', 300000000000000000000000000000);
|
||||
$this->assertNotContains($scientificNotation, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that fields are parsed out in a reasonable fashion.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchRowColumnParsing() {
|
||||
$this->loadFixtures('User');
|
||||
$sql = 'SELECT "User"."id", "User"."user", "User"."password", "User"."created", (1 + 1) AS "two" ' .
|
||||
'FROM "users" AS "User" WHERE ' .
|
||||
'"User"."id" IN (SELECT MAX("id") FROM "users") ' .
|
||||
'OR "User.id" IN (5, 6, 7, 8)';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'User' => array(
|
||||
'id' => 4,
|
||||
'user' => 'garrett',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:22:23'
|
||||
),
|
||||
0 => array(
|
||||
'two' => 2
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$sql = 'SELECT "User"."id", "User"."user" ' .
|
||||
'FROM "users" AS "User" WHERE "User"."id" = 4 ' .
|
||||
'UNION ' .
|
||||
'SELECT "User"."id", "User"."user" ' .
|
||||
'FROM "users" AS "User" WHERE "User"."id" = 3';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'User' => array(
|
||||
'id' => 3,
|
||||
'user' => 'larry',
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing more complex field names.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFetchColumnRowParsingMoreComplex() {
|
||||
$this->loadFixtures('User');
|
||||
$sql = 'SELECT
|
||||
COUNT(*) AS User__count,
|
||||
COUNT(CASE id WHEN 2 THEN 1 ELSE NULL END) as User__case,
|
||||
AVG(CAST("User"."id" AS BIGINT)) AS User__bigint
|
||||
FROM "users" AS "User"
|
||||
WHERE "User"."id" > 0';
|
||||
$result = $this->Dbo->fetchRow($sql);
|
||||
|
||||
$expected = array(
|
||||
'0' => array(
|
||||
'User__count' => '4',
|
||||
'User__case' => '1',
|
||||
'User__bigint' => '2.5',
|
||||
),
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* SqlserverTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Database
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @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');
|
||||
|
|
@ -98,7 +97,7 @@ class SqlserverTestDb extends Sqlserver {
|
|||
/**
|
||||
* describe method
|
||||
*
|
||||
* @param object $model
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function describe($model) {
|
||||
|
|
@ -114,17 +113,10 @@ class SqlserverTestDb extends Sqlserver {
|
|||
*/
|
||||
class SqlserverTestModel extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SqlserverTestModel'
|
||||
*/
|
||||
public $name = 'SqlserverTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
|
@ -187,17 +179,10 @@ class SqlserverTestModel extends CakeTestModel {
|
|||
*/
|
||||
class SqlserverClientTestModel extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'SqlserverAssociatedTestModel'
|
||||
*/
|
||||
public $name = 'SqlserverClientTestModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $useTable = false;
|
||||
|
||||
|
|
@ -263,7 +248,7 @@ class SqlserverTest extends CakeTestCase {
|
|||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
|
@ -277,8 +262,10 @@ class SqlserverTest extends CakeTestCase {
|
|||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Dbo = ConnectionManager::getDataSource('test');
|
||||
if (!($this->Dbo instanceof Sqlserver)) {
|
||||
$this->markTestSkipped('Please configure the test datasource to use SQL Server.');
|
||||
|
|
@ -293,6 +280,7 @@ class SqlserverTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->Dbo);
|
||||
unset($this->model);
|
||||
}
|
||||
|
|
@ -322,6 +310,10 @@ class SqlserverTest extends CakeTestCase {
|
|||
$expected = "''";
|
||||
$result = $this->db->value('', 'binary');
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$expected = 'NULL';
|
||||
$result = $this->db->value(null, 'string');
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -447,7 +439,25 @@ class SqlserverTest extends CakeTestCase {
|
|||
'Length' => 72,
|
||||
'Null' => 'NO',
|
||||
'Size' => ''
|
||||
)
|
||||
),
|
||||
(object)array(
|
||||
'Default' => null,
|
||||
'Field' => 'parent_id',
|
||||
'Key' => '0',
|
||||
'Type' => 'bigint',
|
||||
'Length' => 8,
|
||||
'Null' => 'YES',
|
||||
'Size' => '0',
|
||||
),
|
||||
(object)array(
|
||||
'Default' => null,
|
||||
'Field' => 'description',
|
||||
'Key' => '0',
|
||||
'Type' => 'text',
|
||||
'Length' => 16,
|
||||
'Null' => 'YES',
|
||||
'Size' => '0',
|
||||
),
|
||||
));
|
||||
$this->db->executeResultsStack = array($SqlserverTableDescription);
|
||||
$dummyModel = $this->model;
|
||||
|
|
@ -477,9 +487,22 @@ class SqlserverTest extends CakeTestCase {
|
|||
'default' => '',
|
||||
'length' => 36,
|
||||
'key' => 'primary'
|
||||
),
|
||||
'parent_id' => array(
|
||||
'type' => 'biginteger',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => 8,
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'text',
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'length' => null,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertSame($expected['parent_id'], $result['parent_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -553,6 +576,14 @@ class SqlserverTest extends CakeTestCase {
|
|||
$result = $this->db->buildColumn($column);
|
||||
$expected = "[checked] bit DEFAULT '1'";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$column = array(
|
||||
'name' => 'huge',
|
||||
'type' => 'biginteger',
|
||||
);
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = "[huge] bigint";
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,25 +2,29 @@
|
|||
/**
|
||||
* CacheSessionTest
|
||||
*
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeSession', 'Model/Datasource');
|
||||
App::uses('CacheSession', 'Model/Datasource/Session');
|
||||
class_exists('CakeSession');
|
||||
|
||||
/**
|
||||
* CacheSessionTest
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
*/
|
||||
class CacheSessionTest extends CakeTestCase {
|
||||
|
||||
protected static $_sessionBackup;
|
||||
|
|
@ -35,7 +39,7 @@ class CacheSessionTest extends CakeTestCase {
|
|||
'engine' => 'File',
|
||||
'prefix' => 'session_test_'
|
||||
));
|
||||
self::$_sessionBackup = Configure::read('Session');
|
||||
static::$_sessionBackup = Configure::read('Session');
|
||||
|
||||
Configure::write('Session.handler.config', 'session_test');
|
||||
}
|
||||
|
|
@ -49,7 +53,7 @@ class CacheSessionTest extends CakeTestCase {
|
|||
Cache::clear(false, 'session_test');
|
||||
Cache::drop('session_test');
|
||||
|
||||
Configure::write('Session', self::$_sessionBackup);
|
||||
Configure::write('Session', static::$_sessionBackup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,6 +104,8 @@ class CacheSessionTest extends CakeTestCase {
|
|||
public function testRead() {
|
||||
$this->storage->write('test_one', 'Some other value');
|
||||
$this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
|
||||
$this->storage->write('test_two', 0);
|
||||
$this->assertEquals(0, $this->storage->read('test_two'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,4 +120,4 @@ class CacheSessionTest extends CakeTestCase {
|
|||
$this->assertFalse(Cache::read('test_one', 'session_test'), 'Value stuck around.');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* DatabaseSessionTest 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @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');
|
||||
|
|
@ -22,10 +21,13 @@ App::uses('CakeSession', 'Model/Datasource');
|
|||
App::uses('DatabaseSession', 'Model/Datasource/Session');
|
||||
class_exists('CakeSession');
|
||||
|
||||
/**
|
||||
* SessionTestModel
|
||||
*
|
||||
* @package Cake.Test.Case.Model.Datasource.Session
|
||||
*/
|
||||
class SessionTestModel extends Model {
|
||||
|
||||
public $name = 'SessionTestModel';
|
||||
|
||||
public $useTable = 'sessions';
|
||||
|
||||
}
|
||||
|
|
@ -52,7 +54,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public static function setupBeforeClass() {
|
||||
self::$_sessionBackup = Configure::read('Session');
|
||||
static::$_sessionBackup = Configure::read('Session');
|
||||
Configure::write('Session.handler', array(
|
||||
'model' => 'SessionTestModel',
|
||||
));
|
||||
|
|
@ -65,7 +67,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public static function teardownAfterClass() {
|
||||
Configure::write('Session', self::$_sessionBackup);
|
||||
Configure::write('Session', static::$_sessionBackup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -96,7 +98,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testConstructionSettings() {
|
||||
ClassRegistry::flush();
|
||||
$storage = new DatabaseSession();
|
||||
new DatabaseSession();
|
||||
|
||||
$session = ClassRegistry::getObject('session');
|
||||
$this->assertInstanceOf('SessionTestModel', $session);
|
||||
|
|
@ -120,19 +122,8 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testWrite() {
|
||||
$result = $this->storage->write('foo', 'Some value');
|
||||
$expected = array(
|
||||
'Session' => array(
|
||||
'id' => 'foo',
|
||||
'data' => 'Some value',
|
||||
)
|
||||
);
|
||||
$expires = $result['Session']['expires'];
|
||||
unset($result['Session']['expires']);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = time() + (Configure::read('Session.timeout') * 60);
|
||||
$this->assertWithinMargin($expires, $expected, 1);
|
||||
$this->storage->write('foo', 'Some value');
|
||||
$this->assertEquals($this->storage->read('foo'), 'Some value');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -152,13 +143,10 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
*/
|
||||
public function testRead() {
|
||||
$this->storage->write('foo', 'Some value');
|
||||
|
||||
$result = $this->storage->read('foo');
|
||||
$expected = 'Some value';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->storage->read('made up value');
|
||||
$this->assertFalse($result);
|
||||
$this->assertEquals($this->storage->read('foo'), 'Some value');
|
||||
$this->storage->write('bar', 0);
|
||||
$this->assertEquals(0, $this->storage->read('bar'));
|
||||
$this->assertSame('', $this->storage->read('made up value'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -170,7 +158,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
$this->storage->write('foo', 'Some value');
|
||||
|
||||
$this->assertTrue($this->storage->destroy('foo'), 'Destroy failed');
|
||||
$this->assertFalse($this->storage->read('foo'), 'Value still present.');
|
||||
$this->assertSame($this->storage->read('foo'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -187,6 +175,58 @@ class DatabaseSessionTest extends CakeTestCase {
|
|||
|
||||
sleep(1);
|
||||
$storage->gc();
|
||||
$this->assertFalse($storage->read('foo'));
|
||||
$this->assertSame($storage->read('foo'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* testConcurrentInsert
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConcurrentInsert() {
|
||||
$this->skipIf(
|
||||
$this->db instanceof Sqlite,
|
||||
'Sqlite does not throw exceptions when attempting to insert a duplicate primary key'
|
||||
);
|
||||
|
||||
ClassRegistry::removeObject('Session');
|
||||
|
||||
$mockedModel = $this->getMockForModel(
|
||||
'SessionTestModel',
|
||||
array('exists'),
|
||||
array('alias' => 'MockedSessionTestModel', 'table' => 'sessions')
|
||||
);
|
||||
Configure::write('Session.handler.model', 'MockedSessionTestModel');
|
||||
|
||||
$counter = 0;
|
||||
// First save
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
// Second save
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
// Second save retry
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// Datasource exists check
|
||||
$mockedModel->expects($this->at($counter++))
|
||||
->method('exists')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->storage = new DatabaseSession();
|
||||
|
||||
$this->storage->write('foo', 'Some value');
|
||||
$return = $this->storage->read('foo');
|
||||
$this->assertSame('Some value', $return);
|
||||
|
||||
$this->storage->write('foo', 'Some other value');
|
||||
$return = $this->storage->read('foo');
|
||||
$this->assertSame('Some other value', $return);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,27 @@
|
|||
* NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
|
||||
* or one connection will step on the other.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* 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.
|
||||
* @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
|
||||
* @since CakePHP(tm) v 2.1
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
||||
|
||||
/**
|
||||
* ModelCrossSchemaHabtmTest
|
||||
*
|
||||
* @package Cake.Test.Case.Model
|
||||
*/
|
||||
class ModelCrossSchemaHabtmTest extends BaseModelTest {
|
||||
|
||||
/**
|
||||
|
|
@ -35,14 +40,14 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest {
|
|||
/**
|
||||
* Don't drop tables if they exist
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $dropTables = false;
|
||||
|
||||
/**
|
||||
* Don't auto load fixtures
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
|
|
@ -140,7 +145,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest {
|
|||
));
|
||||
|
||||
$results = $Player->saveAll($player, array('validate' => 'first'));
|
||||
$this->assertNotEqual(false, $results);
|
||||
$this->assertNotSame(false, $results);
|
||||
$count = $Player->find('count');
|
||||
$this->assertEquals(5, $count);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* ModelDeleteTest 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
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
||||
|
||||
/**
|
||||
|
|
@ -149,7 +149,7 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
* @return void
|
||||
*/
|
||||
public function testDeleteDependentWithConditions() {
|
||||
$this->loadFixtures('Cd','Book','OverallFavorite');
|
||||
$this->loadFixtures('Cd', 'Book', 'OverallFavorite');
|
||||
|
||||
$Cd = new Cd();
|
||||
$Book = new Book();
|
||||
|
|
@ -421,6 +421,20 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAll diamond operator method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteAllDiamondOperator() {
|
||||
$this->loadFixtures('Article');
|
||||
$article = new Article();
|
||||
|
||||
$result = $article->deleteAll(array('Article.id <>' => 1));
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse($article->exists(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAllUnknownColumn method
|
||||
*
|
||||
|
|
@ -434,6 +448,88 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAllFailedFind method
|
||||
*
|
||||
* Eg: Behavior callback stops the event, find returns null
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteAllFailedFind() {
|
||||
$this->loadFixtures('Article');
|
||||
$TestModel = $this->getMock('Article', array('find'));
|
||||
$TestModel->expects($this->once())
|
||||
->method('find')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAllMultipleRowsPerId method
|
||||
*
|
||||
* Ensure find done in deleteAll only returns distinct ids. A wacky combination
|
||||
* of association and conditions can sometimes generate multiple rows per id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteAllMultipleRowsPerId() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
|
||||
$TestModel = new Article();
|
||||
$TestModel->unbindModel(array(
|
||||
'belongsTo' => array('User'),
|
||||
'hasMany' => array('Comment'),
|
||||
'hasAndBelongsToMany' => array('Tag')
|
||||
), false);
|
||||
$TestModel->bindModel(array(
|
||||
'belongsTo' => array(
|
||||
'User' => array(
|
||||
'foreignKey' => false,
|
||||
'conditions' => array(
|
||||
'Article.user_id = 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
), false);
|
||||
|
||||
$result = $TestModel->deleteAll(
|
||||
array('Article.user_id' => array(1, 3)),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDeleteAllWithOrderProperty
|
||||
*
|
||||
* Ensure find done in deleteAll works with models that has $order property set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteAllWithOrderProperty() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
|
||||
$TestModel = new Article();
|
||||
$TestModel->order = 'Article.published desc';
|
||||
$TestModel->unbindModel(array(
|
||||
'belongsTo' => array('User'),
|
||||
'hasMany' => array('Comment'),
|
||||
'hasAndBelongsToMany' => array('Tag')
|
||||
), false);
|
||||
|
||||
$result = $TestModel->deleteAll(
|
||||
array('Article.user_id' => array(1, 3)),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRecursiveDel method
|
||||
*
|
||||
|
|
@ -548,6 +644,7 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
'Tag' => array('with' => 'TestPlugin.ArticlesTag')
|
||||
)), false);
|
||||
|
||||
$Article->ArticlesTag->order = null;
|
||||
$this->assertTrue($Article->delete(1));
|
||||
}
|
||||
|
||||
|
|
@ -638,7 +735,7 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
$this->assertEquals(4, $result);
|
||||
|
||||
$result = $Article->delete(1, true);
|
||||
$this->assertSame($result, true);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $Article->Comment->find('count', array(
|
||||
'conditions' => array('Comment.article_id' => 1)
|
||||
|
|
|
|||
|
|
@ -2,23 +2,24 @@
|
|||
/**
|
||||
* ModelIntegrationTest 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
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
||||
|
||||
App::uses('DboSource', 'Model/Datasource');
|
||||
App::uses('DboMock', 'Model/Datasource');
|
||||
|
||||
/**
|
||||
* DboMock class
|
||||
|
|
@ -28,6 +29,8 @@ class DboMock extends DboSource {
|
|||
|
||||
/**
|
||||
* Returns the $field without modifications
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name($field) {
|
||||
return $field;
|
||||
|
|
@ -35,6 +38,8 @@ class DboMock extends DboSource {
|
|||
|
||||
/**
|
||||
* Returns true to fake a database connection
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
public function connect() {
|
||||
return true;
|
||||
|
|
@ -155,17 +160,17 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that $cacheSources can only be disabled in the db using model settings, not enabled
|
||||
* Tests that $cacheSources is restored despite the settings on the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCacheSourcesDisabling() {
|
||||
public function testCacheSourcesRestored() {
|
||||
$this->loadFixtures('JoinA', 'JoinB', 'JoinAB', 'JoinC', 'JoinAC');
|
||||
$this->db->cacheSources = true;
|
||||
$TestModel = new JoinA();
|
||||
$TestModel->cacheSources = false;
|
||||
$TestModel->setSource('join_as');
|
||||
$this->assertFalse($this->db->cacheSources);
|
||||
$this->assertTrue($this->db->cacheSources);
|
||||
|
||||
$this->db->cacheSources = false;
|
||||
$TestModel = new JoinA();
|
||||
|
|
@ -208,11 +213,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
public function testDynamicBehaviorAttachment() {
|
||||
$this->loadFixtures('Apple', 'Sample', 'Author');
|
||||
$TestModel = new Apple();
|
||||
$this->assertEquals(array(), $TestModel->Behaviors->attached());
|
||||
$this->assertEquals(array(), $TestModel->Behaviors->loaded());
|
||||
|
||||
$TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field'));
|
||||
$TestModel->Behaviors->load('Tree', array('left' => 'left_field', 'right' => 'right_field'));
|
||||
$this->assertTrue(is_object($TestModel->Behaviors->Tree));
|
||||
$this->assertEquals(array('Tree'), $TestModel->Behaviors->attached());
|
||||
$this->assertEquals(array('Tree'), $TestModel->Behaviors->loaded());
|
||||
|
||||
$expected = array(
|
||||
'parent' => 'parent_id',
|
||||
|
|
@ -221,23 +226,49 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'scope' => '1 = 1',
|
||||
'type' => 'nested',
|
||||
'__parentChange' => false,
|
||||
'recursive' => -1
|
||||
'recursive' => -1,
|
||||
'level' => null
|
||||
);
|
||||
$this->assertEquals($expected, $TestModel->Behaviors->Tree->settings['Apple']);
|
||||
|
||||
$TestModel->Behaviors->attach('Tree', array('enabled' => false));
|
||||
$TestModel->Behaviors->load('Tree', array('enabled' => false));
|
||||
$this->assertEquals($expected, $TestModel->Behaviors->Tree->settings['Apple']);
|
||||
$this->assertEquals(array('Tree'), $TestModel->Behaviors->attached());
|
||||
$this->assertEquals(array('Tree'), $TestModel->Behaviors->loaded());
|
||||
|
||||
$TestModel->Behaviors->detach('Tree');
|
||||
$this->assertEquals(array(), $TestModel->Behaviors->attached());
|
||||
$TestModel->Behaviors->unload('Tree');
|
||||
$this->assertEquals(array(), $TestModel->Behaviors->loaded());
|
||||
$this->assertFalse(isset($TestModel->Behaviors->Tree));
|
||||
}
|
||||
|
||||
/**
|
||||
* testTreeWithContainable method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTreeWithContainable() {
|
||||
$this->loadFixtures('Ad', 'Campaign');
|
||||
$TestModel = new Ad();
|
||||
$TestModel->Behaviors->load('Tree');
|
||||
$TestModel->Behaviors->load('Containable');
|
||||
|
||||
$node = $TestModel->findById(2);
|
||||
$node['Ad']['parent_id'] = 1;
|
||||
$TestModel->save($node);
|
||||
|
||||
$result = $TestModel->getParentNode(array('id' => 2, 'contain' => 'Campaign'));
|
||||
$this->assertTrue(array_key_exists('Campaign', $result));
|
||||
|
||||
$result = $TestModel->children(array('id' => 1, 'contain' => 'Campaign'));
|
||||
$this->assertTrue(array_key_exists('Campaign', $result[0]));
|
||||
|
||||
$result = $TestModel->getPath(array('id' => 2, 'contain' => 'Campaign'));
|
||||
$this->assertTrue(array_key_exists('Campaign', $result[0]));
|
||||
$this->assertTrue(array_key_exists('Campaign', $result[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* testFindWithJoinsOption method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function testFindWithJoinsOption() {
|
||||
|
|
@ -274,9 +305,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG
|
||||
* Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG
|
||||
* NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
|
||||
* or one connection will step on the other.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCrossDatabaseJoins() {
|
||||
$config = ConnectionManager::enumConnectionObjects();
|
||||
|
|
@ -284,7 +317,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$skip = (!isset($config['test']) || !isset($config['test2']));
|
||||
if ($skip) {
|
||||
$this->markTestSkipped('Primary and secondary test databases not configured, skipping cross-database
|
||||
join tests. To run theses tests defined $test and $test2 in your database configuration.'
|
||||
join tests. To run theses tests defined $test and $test2 in your database configuration.'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -815,7 +848,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
|
||||
$this->skipIf(
|
||||
!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']),
|
||||
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
|
||||
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
|
||||
);
|
||||
|
||||
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer');
|
||||
|
|
@ -835,16 +868,16 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->assertEquals('test_database_three', $Player->ArmorsPlayer->useDbConfig);
|
||||
|
||||
$players = $Player->find('all');
|
||||
$this->assertEquals(4 , count($players));
|
||||
$this->assertEquals(4, count($players));
|
||||
$playersGuilds = Hash::extract($players, '{n}.Guild.{n}.GuildsPlayer');
|
||||
$this->assertEquals(3 , count($playersGuilds));
|
||||
$this->assertEquals(3, count($playersGuilds));
|
||||
$playersArmors = Hash::extract($players, '{n}.Armor.{n}.ArmorsPlayer');
|
||||
$this->assertEquals(3 , count($playersArmors));
|
||||
$this->assertEquals(3, count($playersArmors));
|
||||
unset($players);
|
||||
|
||||
$larry = $Player->findByName('larry');
|
||||
$larrysArmor = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer');
|
||||
$this->assertEquals(1 , count($larrysArmor));
|
||||
$this->assertEquals(1, count($larrysArmor));
|
||||
|
||||
$larry['Guild']['Guild'] = array(1, 3); // larry joins another guild
|
||||
$larry['Armor']['Armor'] = array(2, 3); // purchases chainmail
|
||||
|
|
@ -853,11 +886,9 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
|
||||
$larry = $Player->findByName('larry');
|
||||
$larrysGuild = Hash::extract($larry, 'Guild.{n}.GuildsPlayer');
|
||||
$this->assertEquals(2 , count($larrysGuild));
|
||||
$this->assertEquals(2, count($larrysGuild));
|
||||
$larrysArmor = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer');
|
||||
$this->assertEquals(2 , count($larrysArmor));
|
||||
|
||||
$larrysArmorsPlayersIds = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer.id');
|
||||
$this->assertEquals(2, count($larrysArmor));
|
||||
|
||||
$Player->ArmorsPlayer->id = 3;
|
||||
$Player->ArmorsPlayer->saveField('broken', true); // larry's cloak broke
|
||||
|
|
@ -1303,7 +1334,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$Article->useTable = false;
|
||||
$Article->id = 1;
|
||||
$result = $Article->exists();
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1441,7 +1472,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
|
||||
$assocTypes = array('hasMany', 'hasOne', 'belongsTo', 'hasAndBelongsToMany');
|
||||
foreach ($assocTypes as $type) {
|
||||
$this->assertEquals($Article->getAssociated($type), array_keys($Article->{$type}));
|
||||
$this->assertEquals($Article->getAssociated($type), array_keys($Article->{$type}));
|
||||
}
|
||||
|
||||
$Article->bindModel(array('hasMany' => array('Category')));
|
||||
|
|
@ -1492,7 +1523,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'dynamicWith' => true,
|
||||
'associationForeignKey' => 'join_b_id',
|
||||
'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '',
|
||||
'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => ''
|
||||
'finderQuery' => ''
|
||||
));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
|
@ -1509,8 +1540,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''
|
||||
)
|
||||
);
|
||||
$this->assertSame($TestModel->belongsTo, $expected);
|
||||
$this->assertSame($TestFakeModel->belongsTo, $expected);
|
||||
$this->assertSame($expected, $TestModel->belongsTo);
|
||||
$this->assertSame($expected, $TestFakeModel->belongsTo);
|
||||
|
||||
$this->assertEquals('User', $TestModel->User->name);
|
||||
$this->assertEquals('User', $TestFakeModel->User->name);
|
||||
|
|
@ -1527,8 +1558,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'dependent' => ''
|
||||
));
|
||||
|
||||
$this->assertSame($TestModel->hasOne, $expected);
|
||||
$this->assertSame($TestFakeModel->hasOne, $expected);
|
||||
$this->assertSame($expected, $TestModel->hasOne);
|
||||
$this->assertSame($expected, $TestFakeModel->hasOne);
|
||||
|
||||
$this->assertEquals('Featured', $TestModel->Featured->name);
|
||||
$this->assertEquals('Featured', $TestFakeModel->Featured->name);
|
||||
|
|
@ -1548,8 +1579,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'counterQuery' => ''
|
||||
));
|
||||
|
||||
$this->assertSame($TestModel->hasMany, $expected);
|
||||
$this->assertSame($TestFakeModel->hasMany, $expected);
|
||||
$this->assertSame($expected, $TestModel->hasMany);
|
||||
$this->assertSame($expected, $TestFakeModel->hasMany);
|
||||
|
||||
$this->assertEquals('Comment', $TestModel->Comment->name);
|
||||
$this->assertEquals('Comment', $TestFakeModel->Comment->name);
|
||||
|
|
@ -1569,12 +1600,10 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'offset' => '',
|
||||
'unique' => true,
|
||||
'finderQuery' => '',
|
||||
'deleteQuery' => '',
|
||||
'insertQuery' => ''
|
||||
));
|
||||
|
||||
$this->assertSame($TestModel->hasAndBelongsToMany, $expected);
|
||||
$this->assertSame($TestFakeModel->hasAndBelongsToMany, $expected);
|
||||
$this->assertSame($expected, $TestModel->hasAndBelongsToMany);
|
||||
$this->assertSame($expected, $TestFakeModel->hasAndBelongsToMany);
|
||||
|
||||
$this->assertEquals('Tag', $TestModel->Tag->name);
|
||||
$this->assertEquals('Tag', $TestFakeModel->Tag->name);
|
||||
|
|
@ -1588,10 +1617,12 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
public function testAutoConstructPluginAssociations() {
|
||||
$Comment = ClassRegistry::init('TestPluginComment');
|
||||
|
||||
$this->assertEquals(2, count($Comment->belongsTo), 'Too many associations');
|
||||
$this->assertEquals(3, count($Comment->belongsTo), 'Too many associations');
|
||||
$this->assertFalse(isset($Comment->belongsTo['TestPlugin.User']));
|
||||
$this->assertFalse(isset($Comment->belongsTo['TestPlugin.Source']));
|
||||
$this->assertTrue(isset($Comment->belongsTo['User']), 'Missing association');
|
||||
$this->assertTrue(isset($Comment->belongsTo['TestPluginArticle']), 'Missing association');
|
||||
$this->assertTrue(isset($Comment->belongsTo['Source']), 'Missing association');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1681,6 +1712,14 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$result = $TestModel->alias;
|
||||
$expected = 'AnotherTest';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$TestModel = ClassRegistry::init('Test');
|
||||
$expected = null;
|
||||
$this->assertEquals($expected, $TestModel->plugin);
|
||||
|
||||
$TestModel = ClassRegistry::init('TestPlugin.TestPluginComment');
|
||||
$expected = 'TestPlugin';
|
||||
$this->assertEquals($expected, $TestModel->plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1701,7 +1740,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'First Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
|
@ -1717,7 +1757,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '1',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31'
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
)))),
|
||||
array(
|
||||
'SomethingElse' => array(
|
||||
|
|
@ -1726,7 +1767,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'Second Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31'
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
|
@ -1742,7 +1784,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '2',
|
||||
'doomed' => true,
|
||||
'created' => '2007-03-18 10:39:23',
|
||||
'updated' => '2007-03-18 10:41:31'
|
||||
'updated' => '2007-03-18 10:41:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
)))),
|
||||
array(
|
||||
'SomethingElse' => array(
|
||||
|
|
@ -1751,7 +1794,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'body' => 'Third Post Body',
|
||||
'published' => 'Y',
|
||||
'created' => '2007-03-18 10:43:23',
|
||||
'updated' => '2007-03-18 10:45:31'
|
||||
'updated' => '2007-03-18 10:45:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'Something' => array(
|
||||
array(
|
||||
|
|
@ -1767,7 +1811,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'something_else_id' => '3',
|
||||
'doomed' => false,
|
||||
'created' => '2007-03-18 10:41:23',
|
||||
'updated' => '2007-03-18 10:43:31'
|
||||
'updated' => '2007-03-18 10:43:31',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
)))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
|
@ -1793,8 +1838,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
)))),
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
))),
|
||||
array(
|
||||
'Something' => array(
|
||||
'id' => '2',
|
||||
|
|
@ -1815,8 +1863,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => false,
|
||||
'something_id' => '2',
|
||||
'something_else_id' => '3'
|
||||
)))),
|
||||
'something_else_id' => '3',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
))),
|
||||
array(
|
||||
'Something' => array(
|
||||
'id' => '3',
|
||||
|
|
@ -1837,8 +1888,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '3',
|
||||
'something_else_id' => '1'
|
||||
)))));
|
||||
'something_else_id' => '1',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
))));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $TestModel->findById(1);
|
||||
|
|
@ -1862,8 +1916,11 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
))));
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
)));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$expected = $TestModel->findById(1);
|
||||
|
|
@ -1903,8 +1960,10 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '1'
|
||||
)
|
||||
'something_else_id' => '1',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
array(
|
||||
'id' => '2',
|
||||
|
|
@ -1916,8 +1975,10 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => true,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '2'
|
||||
)
|
||||
'something_else_id' => '2',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
array(
|
||||
'id' => '3',
|
||||
|
|
@ -1929,11 +1990,13 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
'JoinThing' => array(
|
||||
'doomed' => false,
|
||||
'something_id' => '1',
|
||||
'something_else_id' => '3')
|
||||
)
|
||||
'something_else_id' => '3',
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
),
|
||||
'afterFind' => 'Successfully added by AfterFind'
|
||||
)
|
||||
);
|
||||
$this->assertEquals(self::date(), $result['Something']['updated']);
|
||||
));
|
||||
$this->assertEquals(static::date(), $result['Something']['updated']);
|
||||
unset($result['Something']['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
|
@ -2175,7 +2238,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
} else {
|
||||
$intLength = 11;
|
||||
}
|
||||
foreach (array('collate', 'charset', 'comment') as $type) {
|
||||
foreach (array('collate', 'charset', 'comment', 'unsigned') as $type) {
|
||||
foreach ($result as $i => $r) {
|
||||
unset($result[$i][$type]);
|
||||
}
|
||||
|
|
@ -2359,7 +2422,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$config = ConnectionManager::enumConnectionObjects();
|
||||
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
|
||||
$this->skipIf(!isset($config['test']) || !isset($config['test2']),
|
||||
'Primary and secondary test databases not configured, skipping cross-database join tests. To run these tests define $test and $test2 in your database configuration.'
|
||||
'Primary and secondary test databases not configured, skipping cross-database join tests. To run these tests define $test and $test2 in your database configuration.'
|
||||
);
|
||||
|
||||
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');
|
||||
|
|
@ -2389,7 +2452,7 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
$this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.');
|
||||
$this->skipIf(
|
||||
!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']),
|
||||
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
|
||||
'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.'
|
||||
);
|
||||
|
||||
$this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer');
|
||||
|
|
@ -2430,11 +2493,24 @@ class ModelIntegrationTest extends BaseModelTest {
|
|||
* does not trigger any calls on any datasource
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
public function testSchemaNoDB() {
|
||||
$model = $this->getMock('Article', array('getDataSource'));
|
||||
$model->useTable = false;
|
||||
$model->expects($this->never())->method('getDataSource');
|
||||
$this->assertEmpty($model->schema());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that calling getColumnType() on a model that is not supposed to use a table
|
||||
* does not trigger any calls on any datasource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetColumnTypeNoDB() {
|
||||
$model = $this->getMock('Example', array('getDataSource'));
|
||||
$model->expects($this->never())->method('getDataSource');
|
||||
$result = $model->getColumnType('filefield');
|
||||
$this->assertEquals('string', $result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* ModelTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* 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://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,23 +2,23 @@
|
|||
/**
|
||||
* ModelTest 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
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @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(__FILE__) . DS . 'models.php';
|
||||
|
||||
/**
|
||||
|
|
@ -31,14 +31,14 @@ abstract class BaseModelTest extends CakeTestCase {
|
|||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $autoFixtures = false;
|
||||
|
||||
/**
|
||||
* Whether backup global state for each test method or not
|
||||
*
|
||||
* @var bool false
|
||||
* @var bool
|
||||
*/
|
||||
public $backupGlobals = false;
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ abstract class BaseModelTest extends CakeTestCase {
|
|||
'core.feature_set', 'core.exterior_type_category', 'core.document', 'core.device',
|
||||
'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
||||
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c',
|
||||
'core.join_a_b', 'core.join_a_c', 'core.uuid', 'core.data_test', 'core.posts_tag',
|
||||
'core.join_a_b', 'core.join_a_c', 'core.uuid', 'core.uuid_native', 'core.data_test', 'core.posts_tag',
|
||||
'core.the_paper_monkies', 'core.person', 'core.underscore_field', 'core.node',
|
||||
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
|
||||
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
|
||||
|
|
@ -71,6 +71,8 @@ abstract class BaseModelTest extends CakeTestCase {
|
|||
'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all',
|
||||
'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player',
|
||||
'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site',
|
||||
'core.uuidnativeitem', 'core.uuidnativeportfolio', 'core.uuidnativeitems_uuidnativeportfolio',
|
||||
'core.uuidnativeitems_uuidnativeportfolio_numericid',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* ModelValidationTest 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
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
||||
|
||||
/**
|
||||
|
|
@ -25,6 +25,16 @@ require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
|
|||
*/
|
||||
class ModelValidationTest extends BaseModelTest {
|
||||
|
||||
/**
|
||||
* override locale to the default (eng).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Config.language', 'eng');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests validation parameter order in custom validation methods
|
||||
*
|
||||
|
|
@ -167,7 +177,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that invalidFields() integrates well with save(). And that fieldList can be an empty type.
|
||||
* Test that invalidFields() integrates well with save(). And that fieldList can be an empty type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -200,8 +210,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$TestModel->validate = array(
|
||||
'user_id' => 'numeric',
|
||||
'title' => array('allowEmpty' => false, 'rule' => 'notEmpty'),
|
||||
'body' => 'notEmpty'
|
||||
'title' => array('allowEmpty' => false, 'rule' => 'notBlank'),
|
||||
'body' => 'notBlank'
|
||||
);
|
||||
|
||||
$data = array('TestValidate' => array(
|
||||
|
|
@ -370,7 +380,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
),
|
||||
'title' => array(
|
||||
'allowEmpty' => false,
|
||||
'rule' => 'notEmpty'
|
||||
'rule' => 'notBlank'
|
||||
));
|
||||
|
||||
$data = array('TestValidate' => array(
|
||||
|
|
@ -417,7 +427,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
),
|
||||
'title' => array(
|
||||
'allowEmpty' => false,
|
||||
'rule' => 'notEmpty'
|
||||
'rule' => 'notBlank'
|
||||
));
|
||||
|
||||
$data = array('TestValidate' => array(
|
||||
|
|
@ -544,6 +554,44 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that validates() still performs correctly when useTable = false on the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatesWithNoTable() {
|
||||
$TestModel = new TheVoid();
|
||||
$TestModel->validate = array(
|
||||
'title' => array(
|
||||
'notEmpty' => array(
|
||||
'rule' => array('notBlank'),
|
||||
'required' => true,
|
||||
),
|
||||
'tooShort' => array(
|
||||
'rule' => array('minLength', 10),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data = array(
|
||||
'TheVoid' => array(
|
||||
'title' => 'too short',
|
||||
),
|
||||
);
|
||||
$TestModel->create($data);
|
||||
$result = $TestModel->validates();
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = array(
|
||||
'TheVoid' => array(
|
||||
'id' => '1',
|
||||
'title' => 'A good title',
|
||||
),
|
||||
);
|
||||
$TestModel->create($data);
|
||||
$result = $TestModel->validates();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that validates() checks all the 'with' associations as well for validation
|
||||
* as this can cause partial/wrong data insertion.
|
||||
|
|
@ -567,7 +615,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$Something = new Something();
|
||||
$JoinThing = $Something->JoinThing;
|
||||
|
||||
$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));
|
||||
$JoinThing->validate = array('doomed' => array('rule' => 'notBlank'));
|
||||
|
||||
$expectedError = array('doomed' => array('This field cannot be left blank'));
|
||||
|
||||
|
|
@ -576,7 +624,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertFalse($result, 'Save occurred even when with models failed. %s');
|
||||
$this->assertEquals($expectedError, $JoinThing->validationErrors);
|
||||
$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));
|
||||
$this->assertSame($count, 0);
|
||||
$this->assertSame(0, $count);
|
||||
|
||||
$data = array(
|
||||
'Something' => array(
|
||||
|
|
@ -600,6 +648,34 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertEquals(0, $joinRecords, 'Records were saved on the join table. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that if a behavior modifies the model's whitelist validation gets triggered
|
||||
* properly for those fields.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateWithFieldListAndBehavior() {
|
||||
$TestModel = new ValidationTest1();
|
||||
$TestModel->validate = array(
|
||||
'title' => array(
|
||||
'rule' => 'notBlank',
|
||||
),
|
||||
'name' => array(
|
||||
'rule' => 'notBlank',
|
||||
));
|
||||
$TestModel->Behaviors->attach('ValidationRule', array('fields' => array('name')));
|
||||
|
||||
$data = array(
|
||||
'title' => '',
|
||||
'name' => '',
|
||||
);
|
||||
$result = $TestModel->save($data, array('fieldList' => array('title')));
|
||||
$this->assertFalse($result);
|
||||
|
||||
$expected = array('title' => array('This field cannot be left blank'), 'name' => array('This field cannot be left blank'));
|
||||
$this->assertEquals($expected, $TestModel->validationErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that saveAll and with models with validation interact well
|
||||
*
|
||||
|
|
@ -621,7 +697,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$Something = new Something();
|
||||
$JoinThing = $Something->JoinThing;
|
||||
|
||||
$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));
|
||||
$JoinThing->validate = array('doomed' => array('rule' => 'notBlank'));
|
||||
$expectedError = array('doomed' => array('This field cannot be left blank'));
|
||||
|
||||
$Something->create();
|
||||
|
|
@ -639,7 +715,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertEquals($expectedError, $JoinThing->validationErrors);
|
||||
|
||||
$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));
|
||||
$this->assertSame($count, 0);
|
||||
$this->assertSame(0, $count);
|
||||
|
||||
$joinRecords = $JoinThing->find('count', array(
|
||||
'conditions' => array('JoinThing.something_id' => $data['Something']['id'])
|
||||
|
|
@ -680,11 +756,11 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$Author->create();
|
||||
$result = $Author->saveAll($data, array('validate' => 'first'));
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(is_null($Author->id));
|
||||
$this->assertNotNull($Author->id);
|
||||
|
||||
$id = $Author->id;
|
||||
$count = $Author->find('count', array('conditions' => array('Author.id' => $id)));
|
||||
$this->assertSame($count, 1);
|
||||
$this->assertSame(1, $count);
|
||||
|
||||
$count = $Post->find('count', array(
|
||||
'conditions' => array('Post.author_id' => $id)
|
||||
|
|
@ -713,25 +789,6 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$TestModel->invalidFields(array('fieldList' => array('title')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing validation methods does not trigger errors in production mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMissingValidationErrorNoTriggering() {
|
||||
Configure::write('debug', 0);
|
||||
$TestModel = new ValidationTest1();
|
||||
$TestModel->create(array('title' => 'foo'));
|
||||
$TestModel->validate = array(
|
||||
'title' => array(
|
||||
'rule' => array('thisOneBringsThePain'),
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
$TestModel->invalidFields(array('fieldList' => array('title')));
|
||||
$this->assertEquals(array(), $TestModel->validationErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test placeholder replacement when validation message is an array
|
||||
*
|
||||
|
|
@ -748,7 +805,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
'last' => false
|
||||
),
|
||||
'between' => array(
|
||||
'rule' => array('between', 5, 15),
|
||||
'rule' => array('lengthBetween', 5, 15),
|
||||
'message' => array('You may enter up to %s chars (minimum is %s chars)', 14, 6)
|
||||
)
|
||||
)
|
||||
|
|
@ -831,8 +888,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'on' => 'create'
|
||||
)
|
||||
)
|
||||
|
|
@ -849,8 +906,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
unset($data['Article']['id']);
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'on' => 'update'
|
||||
)
|
||||
)
|
||||
|
|
@ -884,8 +941,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'create'
|
||||
)
|
||||
)
|
||||
|
|
@ -902,8 +959,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
unset($data['Article']['id']);
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'update'
|
||||
)
|
||||
)
|
||||
|
|
@ -937,8 +994,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'create',
|
||||
'on' => 'create'
|
||||
)
|
||||
|
|
@ -950,8 +1007,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'update',
|
||||
'on' => 'create'
|
||||
)
|
||||
|
|
@ -963,8 +1020,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'create',
|
||||
'on' => 'update'
|
||||
)
|
||||
|
|
@ -976,8 +1033,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'update',
|
||||
'on' => 'update'
|
||||
)
|
||||
|
|
@ -989,8 +1046,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'create',
|
||||
'on' => 'create'
|
||||
)
|
||||
|
|
@ -1004,8 +1061,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'update',
|
||||
'on' => 'create'
|
||||
)
|
||||
|
|
@ -1017,8 +1074,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'create',
|
||||
'on' => 'update'
|
||||
)
|
||||
|
|
@ -1030,8 +1087,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => 'update',
|
||||
'on' => 'update'
|
||||
)
|
||||
|
|
@ -1053,8 +1110,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$TestModel = new Article();
|
||||
$TestModel->hasMany['Comment']['order'] = array('Comment.created' => 'ASC');
|
||||
$TestModel->hasAndBelongsToMany = array();
|
||||
$TestModel->Comment->Attachment->validate['attachment'] = 'notEmpty';
|
||||
$TestModel->Comment->validate['comment'] = 'notEmpty';
|
||||
$TestModel->Comment->Attachment->validate['attachment'] = 'notBlank';
|
||||
$TestModel->Comment->validate['comment'] = 'notBlank';
|
||||
|
||||
$data = array(
|
||||
'Article' => array('id' => 2),
|
||||
|
|
@ -1381,8 +1438,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$TestModel = new Article();
|
||||
$TestModel->hasMany['Comment']['order'] = array('Comment.created' => 'ASC');
|
||||
$TestModel->hasAndBelongsToMany = array();
|
||||
$TestModel->Comment->Attachment->validate['attachment'] = 'notEmpty';
|
||||
$TestModel->Comment->validate['comment'] = 'notEmpty';
|
||||
$TestModel->Comment->Attachment->validate['attachment'] = 'notBlank';
|
||||
$TestModel->Comment->validate['comment'] = 'notBlank';
|
||||
|
||||
$data = array(
|
||||
'Article' => array('id' => 2, 'body' => ''),
|
||||
|
|
@ -1529,9 +1586,9 @@ class ModelValidationTest extends BaseModelTest {
|
|||
* @return void
|
||||
*/
|
||||
public function testValidateAssociated() {
|
||||
$this->loadFixtures('Comment', 'Attachment');
|
||||
$this->loadFixtures('Comment', 'Attachment', 'Article', 'User');
|
||||
$TestModel = new Comment();
|
||||
$TestModel->Attachment->validate = array('attachment' => 'notEmpty');
|
||||
$TestModel->Attachment->validate = array('attachment' => 'notBlank');
|
||||
|
||||
$data = array(
|
||||
'Comment' => array(
|
||||
|
|
@ -1546,7 +1603,19 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$result = $TestModel->validateAssociated($data);
|
||||
$this->assertFalse($result);
|
||||
|
||||
$TestModel->validate = array('comment' => 'notEmpty');
|
||||
$fieldList = array(
|
||||
'Attachment' => array('comment_id')
|
||||
);
|
||||
$result = $TestModel->saveAll($data, array(
|
||||
'fieldList' => $fieldList, 'validate' => 'only'
|
||||
));
|
||||
$this->assertTrue($result);
|
||||
$this->assertEmpty($TestModel->validationErrors);
|
||||
$result = $TestModel->validateAssociated($data, array('fieldList' => $fieldList));
|
||||
$this->assertTrue($result);
|
||||
$this->assertEmpty($TestModel->validationErrors);
|
||||
|
||||
$TestModel->validate = array('comment' => 'notBlank');
|
||||
$record = array(
|
||||
'Comment' => array(
|
||||
'user_id' => 1,
|
||||
|
|
@ -1577,7 +1646,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$TestModel = new Article();
|
||||
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
|
||||
$TestModel->Comment->validate = array('comment' => 'notEmpty');
|
||||
$TestModel->Comment->validate = array('comment' => 'notBlank');
|
||||
$data = array(
|
||||
'Article' => array('id' => 2),
|
||||
'Comment' => array(
|
||||
|
|
@ -1622,8 +1691,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$model = new Comment();
|
||||
$model->deleteAll(true);
|
||||
$model->validate = array('comment' => 'notEmpty');
|
||||
$model->Attachment->validate = array('attachment' => 'notEmpty');
|
||||
$model->validate = array('comment' => 'notBlank');
|
||||
$model->Attachment->validate = array('attachment' => 'notBlank');
|
||||
$model->Attachment->bindModel(array('belongsTo' => array('Comment')));
|
||||
$expected = array(
|
||||
'comment' => array('This field cannot be left blank'),
|
||||
|
|
@ -1651,7 +1720,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
*/
|
||||
public function testValidateMany() {
|
||||
$TestModel = new Article();
|
||||
$TestModel->validate = array('title' => 'notEmpty');
|
||||
$TestModel->validate = array('title' => 'notBlank');
|
||||
$data = array(
|
||||
0 => array('title' => ''),
|
||||
1 => array('title' => 'title 1'),
|
||||
|
|
@ -1715,7 +1784,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$expected = array_map('strtolower', get_class_methods('Article'));
|
||||
$this->assertEquals($expected, array_keys($result));
|
||||
|
||||
$TestModel->Behaviors->attach('Containable');
|
||||
$TestModel->Behaviors->load('Containable');
|
||||
$newList = array(
|
||||
'contain',
|
||||
'resetbindings',
|
||||
|
|
@ -1725,7 +1794,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
);
|
||||
$this->assertEquals(array_merge($expected, $newList), array_keys($Validator->getMethods()));
|
||||
|
||||
$TestModel->Behaviors->detach('Containable');
|
||||
$TestModel->Behaviors->unload('Containable');
|
||||
$this->assertEquals($expected, array_keys($Validator->getMethods()));
|
||||
}
|
||||
|
||||
|
|
@ -1772,13 +1841,13 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertEquals('title', $titleValidator->field);
|
||||
$this->assertCount(1, $titleValidator->getRules());
|
||||
$rule = current($titleValidator->getRules());
|
||||
$this->assertEquals('notEmpty', $rule->rule);
|
||||
$this->assertEquals('notBlank', $rule->rule);
|
||||
|
||||
$titleValidator = $Validator['body'];
|
||||
$this->assertEquals('body', $titleValidator->field);
|
||||
$this->assertCount(1, $titleValidator->getRules());
|
||||
$rule = current($titleValidator->getRules());
|
||||
$this->assertEquals('notEmpty', $rule->rule);
|
||||
$this->assertEquals('notBlank', $rule->rule);
|
||||
|
||||
$titleValidator = $Validator['user_id'];
|
||||
$this->assertEquals('user_id', $titleValidator->field);
|
||||
|
|
@ -1813,7 +1882,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$set = array(
|
||||
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
|
||||
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false),
|
||||
'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
|
||||
);
|
||||
$Validator['other'] = $set;
|
||||
$rules = $Validator['other'];
|
||||
|
|
@ -1822,7 +1891,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$validators = $rules->getRules();
|
||||
$this->assertCount(2, $validators);
|
||||
$this->assertEquals('numeric', $validators['numeric']->rule);
|
||||
$this->assertEquals(array('between', 1, 5), $validators['range']->rule);
|
||||
$this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
|
||||
|
||||
$Validator['new'] = new CakeValidationSet('new', $set, array());
|
||||
$rules = $Validator['new'];
|
||||
|
|
@ -1831,7 +1900,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$validators = $rules->getRules();
|
||||
$this->assertCount(2, $validators);
|
||||
$this->assertEquals('numeric', $validators['numeric']->rule);
|
||||
$this->assertEquals(array('between', 1, 5), $validators['range']->rule);
|
||||
$this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1886,7 +1955,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$set = array(
|
||||
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
|
||||
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false),
|
||||
'range' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
|
||||
);
|
||||
$Validator['other'] = $set;
|
||||
$this->assertCount(4, $Validator);
|
||||
|
|
@ -1907,14 +1976,14 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$Validator = $TestModel->validator();
|
||||
|
||||
$Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false));
|
||||
$Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false));
|
||||
$Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false));
|
||||
$rules = $Validator['other'];
|
||||
$this->assertEquals('other', $rules->field);
|
||||
|
||||
$validators = $rules->getRules();
|
||||
$this->assertCount(2, $validators);
|
||||
$this->assertEquals('numeric', $validators['numeric']->rule);
|
||||
$this->assertEquals(array('between', 1, 5), $validators['range']->rule);
|
||||
$this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1931,13 +2000,13 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertFalse(isset($Validator['title']));
|
||||
|
||||
$Validator->add('other', 'numeric', array('rule' => 'numeric', 'allowEmpty' => false));
|
||||
$Validator->add('other', 'range', array('rule' => array('between', 1, 5), 'allowEmpty' => false));
|
||||
$Validator->add('other', 'between', array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false));
|
||||
$this->assertTrue(isset($Validator['other']));
|
||||
|
||||
$Validator->remove('other', 'numeric');
|
||||
$this->assertTrue(isset($Validator['other']));
|
||||
$this->assertFalse(isset($Validator['other']['numeric']));
|
||||
$this->assertTrue(isset($Validator['other']['range']));
|
||||
$this->assertTrue(isset($Validator['other']['between']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1965,8 +2034,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$model = new CustomArticle();
|
||||
$model->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => true,
|
||||
'allowEmpty' => false
|
||||
)
|
||||
|
|
@ -2019,8 +2088,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$model = new CustomArticle();
|
||||
$model->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
|
|
@ -2047,7 +2116,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
/**
|
||||
* testValidateFirstWithDefaults method
|
||||
*
|
||||
* return @void
|
||||
* @return void
|
||||
*/
|
||||
public function testFirstWithDefaults() {
|
||||
$this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag');
|
||||
|
|
@ -2095,7 +2164,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
|
||||
$set = array(
|
||||
'numeric' => array('rule' => 'numeric', 'allowEmpty' => false),
|
||||
'range' => array('rule' => array('between', 1, 5), 'allowEmpty' => false),
|
||||
'between' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
|
||||
);
|
||||
|
||||
$Validator->add('other', $set);
|
||||
|
|
@ -2105,11 +2174,11 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$validators = $rules->getRules();
|
||||
$this->assertCount(2, $validators);
|
||||
$this->assertEquals('numeric', $validators['numeric']->rule);
|
||||
$this->assertEquals(array('between', 1, 5), $validators['range']->rule);
|
||||
$this->assertEquals(array('lengthBetween', 1, 5), $validators['between']->rule);
|
||||
|
||||
$set = new CakeValidationSet('other', array(
|
||||
'a' => array('rule' => 'numeric', 'allowEmpty' => false),
|
||||
'b' => array('rule' => array('between', 1, 5), 'allowEmpty' => false),
|
||||
'b' => array('rule' => array('lengthBetween', 1, 5), 'allowEmpty' => false),
|
||||
));
|
||||
|
||||
$Validator->add('other', $set);
|
||||
|
|
@ -2134,6 +2203,39 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->assertTrue($result instanceof CakeValidationSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that validator override works as expected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatorOverride() {
|
||||
$TestModel = new Article();
|
||||
$ValidatorA = new ModelValidator($TestModel);
|
||||
$ValidatorB = new ModelValidator($TestModel);
|
||||
|
||||
$TestModel->validator($ValidatorA);
|
||||
$TestModel->validator($ValidatorB);
|
||||
|
||||
$this->assertSame($ValidatorB, $TestModel->validator());
|
||||
$this->assertNotSame($ValidatorA, $TestModel->validator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that type hint exception is thrown
|
||||
*
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
* @return void
|
||||
* @throws PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testValidatorTypehintException() {
|
||||
try {
|
||||
new ModelValidator('asdasds');
|
||||
$this->fail('No exeption raised');
|
||||
} catch (TypeError $e) {
|
||||
throw new PHPUnit_Framework_Error('Raised an error', 100, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that altering data in a beforeValidate callback will lead to saving those
|
||||
* values in database, this time with belongsTo associations
|
||||
|
|
@ -2145,8 +2247,8 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$model = new CustomArticle();
|
||||
$model->validate = array(
|
||||
'title' => array(
|
||||
'notempty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
|
|
@ -2169,7 +2271,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
* after a presentation made to show off this new feature
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
public function testDynamicValidationRuleBuilding() {
|
||||
$model = new Article;
|
||||
$validator = $model->validator();
|
||||
|
|
@ -2236,7 +2338,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->loadFixtures('Comment', 'Article', 'User', 'Attachment');
|
||||
$Attachment = ClassRegistry::init('Attachment');
|
||||
$Attachment->Comment->validator()->add('comment', array(
|
||||
array('rule' => 'notEmpty')
|
||||
array('rule' => 'notBlank')
|
||||
));
|
||||
$Attachment->Comment->User->bindModel(array(
|
||||
'hasMany' => array(
|
||||
|
|
@ -2283,7 +2385,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
),
|
||||
),
|
||||
);
|
||||
$this->assertEquals($result, $expected);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2295,7 +2397,7 @@ class ModelValidationTest extends BaseModelTest {
|
|||
$this->loadFixtures('Comment', 'Article', 'User');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->Comment->validator()->add('comment', array(
|
||||
array('rule' => 'notEmpty')
|
||||
array('rule' => 'notBlank')
|
||||
));
|
||||
|
||||
$data = array(
|
||||
|
|
@ -2344,7 +2446,96 @@ class ModelValidationTest extends BaseModelTest {
|
|||
),
|
||||
),
|
||||
);
|
||||
$this->assertEquals($result, $expected);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the isUnique method when used as a validator for multiple fields.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsUniqueValidator() {
|
||||
$this->loadFixtures('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->validate = array(
|
||||
'user_id' => array(
|
||||
'duplicate' => array(
|
||||
'rule' => array('isUnique', array('user_id', 'title'), false)
|
||||
)
|
||||
)
|
||||
);
|
||||
$data = array(
|
||||
'user_id' => 1,
|
||||
'title' => 'First Article',
|
||||
);
|
||||
$Article->create($data);
|
||||
$this->assertFalse($Article->validates(), 'Contains a dupe');
|
||||
|
||||
$data = array(
|
||||
'user_id' => 1,
|
||||
'title' => 'Unique Article',
|
||||
);
|
||||
$Article->create($data);
|
||||
$this->assertTrue($Article->validates(), 'Should pass');
|
||||
|
||||
$Article->validate = array(
|
||||
'user_id' => array(
|
||||
'duplicate' => array(
|
||||
'rule' => array('isUnique', array('user_id', 'title'))
|
||||
)
|
||||
)
|
||||
);
|
||||
$data = array(
|
||||
'user_id' => 1,
|
||||
'title' => 'Unique Article',
|
||||
);
|
||||
$Article->create($data);
|
||||
$this->assertFalse($Article->validates(), 'Should fail, conditions are combined with or');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test backward compatibility of the isUnique method when used as a validator for a single field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBackwardCompatIsUniqueValidator() {
|
||||
$this->loadFixtures('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->validate = array(
|
||||
'title' => array(
|
||||
'duplicate' => array(
|
||||
'rule' => 'isUnique',
|
||||
'message' => 'Title must be unique',
|
||||
),
|
||||
'minLength' => array(
|
||||
'rule' => array('minLength', 1),
|
||||
'message' => 'Title cannot be empty',
|
||||
),
|
||||
)
|
||||
);
|
||||
$data = array(
|
||||
'title' => 'First Article',
|
||||
);
|
||||
$data = $Article->create($data);
|
||||
$this->assertFalse($Article->validates(), 'Contains a dupe');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Behavior for testing validation rules.
|
||||
*/
|
||||
class ValidationRuleBehavior extends ModelBehavior {
|
||||
|
||||
public function setup(Model $Model, $config = array()) {
|
||||
$this->settings[$Model->alias] = $config;
|
||||
}
|
||||
|
||||
public function beforeValidate(Model $Model, $options = array()) {
|
||||
$fields = $this->settings[$Model->alias]['fields'];
|
||||
foreach ($fields as $field) {
|
||||
$Model->whitelist[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* CakeValidationRuleTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* 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/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Model.Validator
|
||||
* @since CakePHP(tm) v 2.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeValidationRule', 'Model/Validator');
|
||||
|
|
@ -29,8 +28,8 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
/**
|
||||
* Auxiliary method to test custom validators
|
||||
*
|
||||
* @return boolean
|
||||
**/
|
||||
* @return bool
|
||||
*/
|
||||
public function myTestRule() {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -38,8 +37,8 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
/**
|
||||
* Auxiliary method to test custom validators
|
||||
*
|
||||
* @return boolean
|
||||
**/
|
||||
* @return bool
|
||||
*/
|
||||
public function myTestRule2() {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -48,7 +47,7 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
* Auxiliary method to test custom validators
|
||||
*
|
||||
* @return string
|
||||
**/
|
||||
*/
|
||||
public function myTestRule3() {
|
||||
return 'string';
|
||||
}
|
||||
|
|
@ -59,7 +58,7 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testIsValid() {
|
||||
$def = array('rule' => 'notEmpty', 'message' => 'Can not be empty');
|
||||
$def = array('rule' => 'notBlank', 'message' => 'Can not be empty');
|
||||
$data = array(
|
||||
'fieldName' => ''
|
||||
);
|
||||
|
|
@ -123,19 +122,19 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testIsRequired() {
|
||||
$def = array('rule' => 'notEmpty', 'required' => true);
|
||||
$def = array('rule' => 'notBlank', 'required' => true);
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertTrue($Rule->isRequired());
|
||||
|
||||
$def = array('rule' => 'notEmpty', 'required' => false);
|
||||
$def = array('rule' => 'notBlank', 'required' => false);
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertFalse($Rule->isRequired());
|
||||
|
||||
$def = array('rule' => 'notEmpty', 'required' => 'create');
|
||||
$def = array('rule' => 'notBlank', 'required' => 'create');
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertTrue($Rule->isRequired());
|
||||
|
||||
$def = array('rule' => 'notEmpty', 'required' => 'update');
|
||||
$def = array('rule' => 'notBlank', 'required' => 'update');
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertFalse($Rule->isRequired());
|
||||
|
||||
|
|
@ -157,14 +156,14 @@ class CakeValidationRuleTest extends CakeTestCase {
|
|||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertFalse($Rule->isEmptyAllowed());
|
||||
|
||||
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'update');
|
||||
$def = array('rule' => 'notBlank', 'allowEmpty' => false, 'on' => 'update');
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertTrue($Rule->isEmptyAllowed());
|
||||
|
||||
$Rule->isUpdate(true);
|
||||
$this->assertFalse($Rule->isEmptyAllowed());
|
||||
|
||||
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'create');
|
||||
$def = array('rule' => 'notBlank', 'allowEmpty' => false, 'on' => 'create');
|
||||
$Rule = new CakeValidationRule($def);
|
||||
$this->assertFalse($Rule->isEmptyAllowed());
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* CakeValidationSetTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
||||
* 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/view/1196/Testing CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Model.Validator
|
||||
* @since CakePHP(tm) v 2.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeValidationSet', 'Model/Validator');
|
||||
|
|
@ -24,7 +23,17 @@ App::uses('CakeValidationSet', 'Model/Validator');
|
|||
*
|
||||
* @package Cake.Test.Case.Model.Validator
|
||||
*/
|
||||
class CakeValidationSetTest extends CakeTestCase {
|
||||
class CakeValidationSetTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* override locale to the default (eng).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Config.language', 'eng');
|
||||
}
|
||||
|
||||
/**
|
||||
* testValidate method
|
||||
|
|
@ -32,7 +41,7 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testValidate() {
|
||||
$Field = new CakeValidationSet('title', 'notEmpty');
|
||||
$Field = new CakeValidationSet('title', 'notBlank');
|
||||
$data = array(
|
||||
'title' => '',
|
||||
'body' => 'a body'
|
||||
|
|
@ -42,20 +51,20 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
$expected = array('This field cannot be left blank');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Field = new CakeValidationSet('body', 'notEmpty');
|
||||
$Field = new CakeValidationSet('body', 'notBlank');
|
||||
|
||||
$result = $Field->validate($data);
|
||||
$this->assertEmpty($result);
|
||||
|
||||
$Field = new CakeValidationSet('nothere', array(
|
||||
'notEmpty' => array(
|
||||
'rule' => 'notEmpty',
|
||||
'notBlank' => array(
|
||||
'rule' => 'notBlank',
|
||||
'required' => true
|
||||
)
|
||||
));
|
||||
|
||||
$result = $Field->validate($data);
|
||||
$expected = array('notEmpty');
|
||||
$expected = array('notBlank');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$Field = new CakeValidationSet('body', array(
|
||||
|
|
@ -74,16 +83,11 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetRule() {
|
||||
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
|
||||
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
|
||||
$Field = new CakeValidationSet('title', $rules);
|
||||
$data = array(
|
||||
'title' => '',
|
||||
'body' => 'a body'
|
||||
);
|
||||
|
||||
$result = $Field->getRule('notEmpty');
|
||||
$result = $Field->getRule('notBlank');
|
||||
$this->assertInstanceOf('CakeValidationRule', $result);
|
||||
$this->assertEquals('notEmpty', $result->rule);
|
||||
$this->assertEquals('notBlank', $result->rule);
|
||||
$this->assertEquals(null, $result->required);
|
||||
$this->assertEquals(false, $result->allowEmpty);
|
||||
$this->assertEquals(null, $result->on);
|
||||
|
|
@ -97,12 +101,12 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetRules() {
|
||||
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
|
||||
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
|
||||
$Field = new CakeValidationSet('title', $rules);
|
||||
|
||||
$result = $Field->getRules();
|
||||
$this->assertEquals(array('notEmpty'), array_keys($result));
|
||||
$this->assertInstanceOf('CakeValidationRule', $result['notEmpty']);
|
||||
$this->assertEquals(array('notBlank'), array_keys($result));
|
||||
$this->assertInstanceOf('CakeValidationRule', $result['notBlank']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,23 +115,23 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSetRule() {
|
||||
$rules = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
|
||||
$rules = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
|
||||
$Field = new CakeValidationSet('title', $rules);
|
||||
$Rule = new CakeValidationRule($rules['notEmpty']);
|
||||
$Rule = new CakeValidationRule($rules['notBlank']);
|
||||
|
||||
$this->assertEquals($Rule, $Field->getRule('notEmpty'));
|
||||
$this->assertEquals($Rule, $Field->getRule('notBlank'));
|
||||
|
||||
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
|
||||
$Rule = new CakeValidationRule($rules['validEmail']);
|
||||
$Field->setRule('validEmail', $Rule);
|
||||
$result = $Field->getRules();
|
||||
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
|
||||
$this->assertEquals(array('notBlank', 'validEmail'), array_keys($result));
|
||||
|
||||
$rules = array('validEmail' => array('rule' => 'email', 'message' => 'Other message'));
|
||||
$Rule = new CakeValidationRule($rules['validEmail']);
|
||||
$Field->setRule('validEmail', $Rule);
|
||||
$result = $Field->getRules();
|
||||
$this->assertEquals(array('notEmpty', 'validEmail'), array_keys($result));
|
||||
$this->assertEquals(array('notBlank', 'validEmail'), array_keys($result));
|
||||
$result = $Field->getRule('validEmail');
|
||||
$this->assertInstanceOf('CakeValidationRule', $result);
|
||||
$this->assertEquals('email', $result->rule);
|
||||
|
|
@ -144,9 +148,9 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSetRules() {
|
||||
$rule = array('notEmpty' => array('rule' => 'notEmpty', 'message' => 'Can not be empty'));
|
||||
$rule = array('notBlank' => array('rule' => 'notBlank', 'message' => 'Can not be empty'));
|
||||
$Field = new CakeValidationSet('title', $rule);
|
||||
$RuleEmpty = new CakeValidationRule($rule['notEmpty']);
|
||||
$RuleEmpty = new CakeValidationRule($rule['notBlank']);
|
||||
|
||||
$rule = array('validEmail' => array('rule' => 'email', 'message' => 'Invalid email'));
|
||||
$RuleEmail = new CakeValidationRule($rule['validEmail']);
|
||||
|
|
@ -161,15 +165,15 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
$this->assertEquals(array('validEmail'), array_keys($result));
|
||||
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||
|
||||
$rules = array('notEmpty' => $RuleEmpty);
|
||||
$rules = array('notBlank' => $RuleEmpty);
|
||||
$Field->setRules($rules, true);
|
||||
$result = $Field->getRules();
|
||||
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
|
||||
$this->assertEquals(array('validEmail', 'notBlank'), array_keys($result));
|
||||
|
||||
$rules = array('notEmpty' => array('rule' => 'notEmpty'));
|
||||
$rules = array('notBlank' => array('rule' => 'notBlank'));
|
||||
$Field->setRules($rules, true);
|
||||
$result = $Field->getRules();
|
||||
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
|
||||
$this->assertEquals(array('validEmail', 'notBlank'), array_keys($result));
|
||||
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||
}
|
||||
|
|
@ -181,14 +185,14 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testArrayAccessGet() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
||||
$rule = $Set['notEmpty'];
|
||||
$rule = $Set['notBlank'];
|
||||
$this->assertInstanceOf('CakeValidationRule', $rule);
|
||||
$this->assertEquals('notEmpty', $rule->rule);
|
||||
$this->assertEquals('notBlank', $rule->rule);
|
||||
|
||||
$rule = $Set['numeric'];
|
||||
$this->assertInstanceOf('CakeValidationRule', $rule);
|
||||
|
|
@ -206,12 +210,12 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testArrayAccessExists() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
||||
$this->assertTrue(isset($Set['notEmpty']));
|
||||
$this->assertTrue(isset($Set['notBlank']));
|
||||
$this->assertTrue(isset($Set['numeric']));
|
||||
$this->assertTrue(isset($Set['other']));
|
||||
$this->assertFalse(isset($Set['fail']));
|
||||
|
|
@ -224,7 +228,7 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testArrayAccessSet() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
));
|
||||
|
||||
$this->assertFalse(isset($Set['other']));
|
||||
|
|
@ -247,19 +251,19 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testArrayAccessUnset() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
||||
unset($Set['notEmpty']);
|
||||
$this->assertFalse(isset($Set['notEmpty']));
|
||||
unset($Set['notBlank']);
|
||||
$this->assertFalse(isset($Set['notBlank']));
|
||||
|
||||
unset($Set['numeric']);
|
||||
$this->assertFalse(isset($Set['notEmpty']));
|
||||
$this->assertFalse(isset($Set['notBlank']));
|
||||
|
||||
unset($Set['other']);
|
||||
$this->assertFalse(isset($Set['notEmpty']));
|
||||
$this->assertFalse(isset($Set['notBlank']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -269,7 +273,7 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testIterator() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
|
@ -277,7 +281,7 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
$i = 0;
|
||||
foreach ($Set as $name => $rule) {
|
||||
if ($i === 0) {
|
||||
$this->assertEquals('notEmpty', $name);
|
||||
$this->assertEquals('notBlank', $name);
|
||||
}
|
||||
if ($i === 1) {
|
||||
$this->assertEquals('numeric', $name);
|
||||
|
|
@ -298,7 +302,7 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testCount() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
|
@ -315,13 +319,13 @@ class CakeValidationSetTest extends CakeTestCase {
|
|||
*/
|
||||
public function testRemoveRule() {
|
||||
$Set = new CakeValidationSet('title', array(
|
||||
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
|
||||
'notBlank' => array('rule' => 'notBlank', 'required' => true),
|
||||
'numeric' => array('rule' => 'numeric'),
|
||||
'other' => array('rule' => array('other', 1)),
|
||||
));
|
||||
|
||||
$Set->removeRule('notEmpty');
|
||||
$this->assertFalse(isset($Set['notEmpty']));
|
||||
$Set->removeRule('notBlank');
|
||||
$this->assertFalse(isset($Set['notBlank']));
|
||||
|
||||
$Set->removeRule('numeric');
|
||||
$this->assertFalse(isset($Set['numeric']));
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue