Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding patch from 'CSdread_' Adds test coverage to Model::getAssociat…

…ed()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8168 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 029f4229533a42ce3a81e3d3b2133fa16289f841 1 parent bf7e257
@markstory markstory authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 cake/tests/cases/libs/model/model.test.php
View
43 cake/tests/cases/libs/model/model.test.php
@@ -99,6 +99,49 @@ function end() {
function endTest() {
ClassRegistry::flush();
}
+
+/**
+ * Tests getAssociated method
+ *
+ * @access public
+ * @return void
+ */
+ function testGetAssociated() {
+ $this->loadFixtures('Article');
+ $Article = ClassRegistry::init('Article');
+
+ $assocTypes = array('hasMany', 'hasOne', 'belongsTo', 'hasAndBelongsToMany');
+ foreach ($assocTypes as $type) {
+ $this->assertEqual($Article->getAssociated($type), array_keys($Article->{$type}));
+ }
+
+ $Article->bindModel(array('hasMany' => array('Category')));
+ $this->assertEqual($Article->getAssociated('hasMany'), array('Comment', 'Category'));
+
+ $results = $Article->getAssociated();
+ $this->assertEqual(sort(array_keys($results)), array('Category', 'Comment', 'Tag'));
+
+ $Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
+ $this->assertEqual($Article->getAssociated('hasAndBelongsToMany'), array());
+
+ $result = $Article->getAssociated('Category');
+ $expected = array(
+ 'className' => 'Category',
+ 'foreignKey' => 'article_id',
+ 'conditions' => '',
+ 'fields' => '',
+ 'order' => '',
+ 'limit' => '',
+ 'offset' => '',
+ 'dependent' => '',
+ 'exclusive' => '',
+ 'finderQuery' => '',
+ 'counterQuery' => '',
+ 'association' => 'hasMany',
+ );
+ $this->assertEqual($result, $expected);
+ }
+
/**
* testAutoConstructAssociations method
*
Please sign in to comment.
Something went wrong with that request. Please try again.