mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding testcases to disprove #6111
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8224 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
508f0651a4
commit
9918583e7e
1 changed files with 103 additions and 1 deletions
|
@ -337,6 +337,58 @@ class Test2Behavior extends TestBehavior{
|
|||
*/
|
||||
class Test3Behavior extends TestBehavior{
|
||||
}
|
||||
/**
|
||||
* Test4Behavior class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Test4Behavior extends ModelBehavior{
|
||||
function setup(&$model, $config = null) {
|
||||
$model->bindModel(
|
||||
array('hasMany' => array('Comment'))
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test5Behavior class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Test5Behavior extends ModelBehavior{
|
||||
function setup(&$model, $config = null) {
|
||||
$model->bindModel(
|
||||
array('belongsTo' => array('User'))
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test6Behavior class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Test6Behavior extends ModelBehavior{
|
||||
function setup(&$model, $config = null) {
|
||||
$model->bindModel(
|
||||
array('hasAndBelongsToMany' => array('Tag'))
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test7Behavior class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Test7Behavior extends ModelBehavior{
|
||||
function setup(&$model, $config = null) {
|
||||
$model->bindModel(
|
||||
array('hasOne' => array('Attachment'))
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* BehaviorTest class
|
||||
*
|
||||
|
@ -350,7 +402,10 @@ class BehaviorTest extends CakeTestCase {
|
|||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.apple', 'core.sample');
|
||||
var $fixtures = array(
|
||||
'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment',
|
||||
'core.attachment', 'core.tag', 'core.articles_tag'
|
||||
);
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
|
@ -948,6 +1003,53 @@ class BehaviorTest extends CakeTestCase {
|
|||
$expected = array('TestBehavior', 'Test2Behavior');
|
||||
$this->assertIdentical($Apple->beforeTestResult, $expected);
|
||||
}
|
||||
/**
|
||||
* undocumented function
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function testBindModelCallsInBehaviors() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
|
||||
// hasMany
|
||||
$Article = new Article();
|
||||
$Article->unbindModel(array('hasMany' => array('Comment')));
|
||||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('Comment', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test4');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('Comment', $result));
|
||||
|
||||
// belongsTo
|
||||
$Article->unbindModel(array('belongsTo' => array('User')));
|
||||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('User', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test5');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('User', $result));
|
||||
|
||||
// hasAndBelongsToMany
|
||||
$Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
|
||||
$result = $Article->find('first');
|
||||
$this->assertFalse(array_key_exists('Tag', $result));
|
||||
|
||||
$Article->Behaviors->attach('Test6');
|
||||
$result = $Article->find('first');
|
||||
$this->assertTrue(array_key_exists('Comment', $result));
|
||||
|
||||
// hasOne
|
||||
$Comment = new Comment();
|
||||
$Comment->unbindModel(array('hasOne' => array('Attachment')));
|
||||
$result = $Comment->find('first');
|
||||
$this->assertFalse(array_key_exists('Attachment', $result));
|
||||
|
||||
$Comment->Behaviors->attach('Test7');
|
||||
$result = $Comment->find('first');
|
||||
$this->assertTrue(array_key_exists('Attachment', $result));
|
||||
}
|
||||
/**
|
||||
* Test attach and detaching
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue