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:
DarkAngelBGE 2009-07-06 22:38:37 +00:00
parent 508f0651a4
commit 9918583e7e

View file

@ -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
*