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
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue