|
|
@@ -5,7 +5,7 @@ App::uses('Controller', 'Controller');
|
|
|
|
|
|
class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
- public $fixtures = array(
|
|
|
+ public $fixtures = array(
|
|
|
'plugin.tools.user',
|
|
|
'plugin.tools.profile',
|
|
|
'plugin.tools.generic',
|
|
|
@@ -23,7 +23,7 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
public function startTest() {
|
|
|
|
|
|
- $this->User = ClassRegistry::init('User');
|
|
|
+ $this->User = ClassRegistry::init('User');
|
|
|
}
|
|
|
|
|
|
public function endTest() {
|
|
|
@@ -33,13 +33,13 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
public function testBelongsTo()
|
|
|
{
|
|
|
- $arrayExpected = array(
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
- 'Profile' => array ('id' => 1, 'user_id' => 1, 'biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.')
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
+ 'Profile' => array ('id' => 1, 'user_id' => 1, 'biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.')
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'contain' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'contain' => array(
|
|
|
'Profile'
|
|
|
)
|
|
|
));
|
|
|
@@ -47,15 +47,15 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'belongsTo association via Containable: %s');
|
|
|
|
|
|
// Same association, but this time with Linkable
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'username'
|
|
|
),
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Profile' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Profile' => array(
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'user_id',
|
|
|
'biography'
|
|
|
@@ -69,9 +69,9 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'belongsTo association via Linkable: %s');
|
|
|
|
|
|
// Linkable association, no field lists
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
'Profile'
|
|
|
)
|
|
|
));
|
|
|
@@ -80,18 +80,18 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'belongsTo association via Linkable (automatic fields): %s');
|
|
|
|
|
|
// On-the-fly association via Linkable
|
|
|
- $arrayExpected = array(
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
- 'Generic' => array('id' => 1, 'text' => '')
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
+ 'Generic' => array('id' => 1, 'text' => '')
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Generic' => array(
|
|
|
- 'class' => 'Generic',
|
|
|
- 'conditions' => array('exactly' => 'User.id = Generic.id'),
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Generic' => array(
|
|
|
+ 'class' => 'Generic',
|
|
|
+ 'conditions' => array('exactly' => 'User.id = Generic.id'),
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'text'
|
|
|
)
|
|
|
@@ -103,24 +103,24 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'On-the-fly belongsTo association via Linkable: %s');
|
|
|
|
|
|
// On-the-fly association via Linkable, with order on the associations' row and using array conditions instead of plain string
|
|
|
- $arrayExpected = array(
|
|
|
- 'User' => array('id' => 4, 'username' => 'CodeIgniter'),
|
|
|
- 'Generic' => array('id' => 4, 'text' => '')
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'User' => array('id' => 4, 'username' => 'CodeIgniter'),
|
|
|
+ 'Generic' => array('id' => 4, 'text' => '')
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Generic' => array(
|
|
|
- 'class' => 'Generic',
|
|
|
- 'conditions' => array('exactly' => array('User.id = Generic.id')),
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Generic' => array(
|
|
|
+ 'class' => 'Generic',
|
|
|
+ 'conditions' => array('exactly' => array('User.id = Generic.id')),
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'text'
|
|
|
)
|
|
|
)
|
|
|
),
|
|
|
- 'order' => 'Generic.id DESC'
|
|
|
+ 'order' => 'Generic.id DESC'
|
|
|
));
|
|
|
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'On-the-fly belongsTo association via Linkable, with order: %s');
|
|
|
@@ -129,58 +129,58 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
public function testHasMany()
|
|
|
{
|
|
|
// hasMany association via Containable. Should still work when Linkable is loaded
|
|
|
- $arrayExpected = array(
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
- 'Comment' => array(
|
|
|
- 0 => array(
|
|
|
- 'id' => 1,
|
|
|
- 'user_id' => 1,
|
|
|
- 'body' => 'Text'
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
+ 'Comment' => array(
|
|
|
+ 0 => array(
|
|
|
+ 'id' => 1,
|
|
|
+ 'user_id' => 1,
|
|
|
+ 'body' => 'Text'
|
|
|
),
|
|
|
- 1 => array(
|
|
|
- 'id' => 2,
|
|
|
- 'user_id' => 1,
|
|
|
- 'body' => 'Text'
|
|
|
+ 1 => array(
|
|
|
+ 'id' => 2,
|
|
|
+ 'user_id' => 1,
|
|
|
+ 'body' => 'Text'
|
|
|
),
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'contain' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'contain' => array(
|
|
|
'Comment'
|
|
|
),
|
|
|
- 'order' => 'User.id ASC'
|
|
|
+ 'order' => 'User.id ASC'
|
|
|
));
|
|
|
$this->assertTrue(isset($arrayResult['Comment']), 'hasMany association via Containable: %s');
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'hasMany association via Containable: %s');
|
|
|
|
|
|
// Same association, but this time with Linkable
|
|
|
- $arrayExpected = array(
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
- 'Comment' => array(
|
|
|
- 'id' => 1,
|
|
|
- 'user_id' => 1,
|
|
|
- 'body' => 'Text'
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP'),
|
|
|
+ 'Comment' => array(
|
|
|
+ 'id' => 1,
|
|
|
+ 'user_id' => 1,
|
|
|
+ 'body' => 'Text'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->User->find('first', array(
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->User->find('first', array(
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'username'
|
|
|
),
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Comment' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Comment' => array(
|
|
|
+ 'fields' => array(
|
|
|
'id',
|
|
|
'user_id',
|
|
|
'body'
|
|
|
)
|
|
|
)
|
|
|
),
|
|
|
- 'order' => 'User.id ASC',
|
|
|
- 'group' => 'User.id'
|
|
|
+ 'order' => 'User.id ASC',
|
|
|
+ 'group' => 'User.id'
|
|
|
));
|
|
|
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'hasMany association via Linkable: %s');
|
|
|
@@ -188,43 +188,43 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
public function testComplexAssociations()
|
|
|
{
|
|
|
- $this->BlogPost = ClassRegistry::init('BlogPost');
|
|
|
-
|
|
|
- $arrayExpected = array(
|
|
|
- 'BlogPost' => array('id' => 1, 'title' => 'Post 1', 'user_id' => 1),
|
|
|
- 'Tag' => array('name' => 'General'),
|
|
|
- 'Profile' => array('biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.'),
|
|
|
- 'MainTag' => array('name' => 'General'),
|
|
|
- 'Generic' => array('id' => 1,'text' => ''),
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP')
|
|
|
+ $this->BlogPost = ClassRegistry::init('BlogPost');
|
|
|
+
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'BlogPost' => array('id' => 1, 'title' => 'Post 1', 'user_id' => 1),
|
|
|
+ 'Tag' => array('name' => 'General'),
|
|
|
+ 'Profile' => array('biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.'),
|
|
|
+ 'MainTag' => array('name' => 'General'),
|
|
|
+ 'Generic' => array('id' => 1,'text' => ''),
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP')
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->BlogPost->find('first', array(
|
|
|
- 'conditions' => array(
|
|
|
- 'MainTag.id' => 1
|
|
|
+ $arrayResult = $this->BlogPost->find('first', array(
|
|
|
+ 'conditions' => array(
|
|
|
+ 'MainTag.id' => 1
|
|
|
),
|
|
|
- 'link' => array(
|
|
|
- 'User' => array(
|
|
|
- 'Profile' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'link' => array(
|
|
|
+ 'User' => array(
|
|
|
+ 'Profile' => array(
|
|
|
+ 'fields' => array(
|
|
|
'biography'
|
|
|
),
|
|
|
- 'Generic' => array(
|
|
|
- 'class' => 'Generic',
|
|
|
- 'conditions' => array('exactly' => 'User.id = Generic.id'),
|
|
|
+ 'Generic' => array(
|
|
|
+ 'class' => 'Generic',
|
|
|
+ 'conditions' => array('exactly' => 'User.id = Generic.id'),
|
|
|
)
|
|
|
)
|
|
|
),
|
|
|
- 'Tag' => array(
|
|
|
- 'table' => 'tags',
|
|
|
- 'fields' => array(
|
|
|
+ 'Tag' => array(
|
|
|
+ 'table' => 'tags',
|
|
|
+ 'fields' => array(
|
|
|
'name'
|
|
|
)
|
|
|
),
|
|
|
- 'MainTag' => array(
|
|
|
- 'class' => 'Tag',
|
|
|
- 'conditions' => array('exactly' => 'BlogPostsTag.blog_post_id = BlogPost.id'),
|
|
|
- 'fields' => array(
|
|
|
+ 'MainTag' => array(
|
|
|
+ 'class' => 'Tag',
|
|
|
+ 'conditions' => array('exactly' => 'BlogPostsTag.blog_post_id = BlogPost.id'),
|
|
|
+ 'fields' => array(
|
|
|
'MainTag.name'
|
|
|
)
|
|
|
)
|
|
|
@@ -234,20 +234,20 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayExpected, $arrayResult, 'Complex find: %s');
|
|
|
|
|
|
// Linkable and Containable combined
|
|
|
- $arrayExpected = array(
|
|
|
- 'BlogPost' => array('id' => 1, 'title' => 'Post 1', 'user_id' => 1),
|
|
|
- 'Tag' => array(
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'BlogPost' => array('id' => 1, 'title' => 'Post 1', 'user_id' => 1),
|
|
|
+ 'Tag' => array(
|
|
|
array('id' => 1, 'name' => 'General', 'parent_id' => null, 'BlogPostsTag' => array('id' => 1, 'blog_post_id' => 1, 'tag_id' => 1, 'main' => 0)),
|
|
|
array('id' => 2, 'name' => 'Test I', 'parent_id' => 1, 'BlogPostsTag' => array('id' => 2, 'blog_post_id' => 1, 'tag_id' => 2, 'main' => 1))
|
|
|
),
|
|
|
- 'User' => array('id' => 1, 'username' => 'CakePHP')
|
|
|
+ 'User' => array('id' => 1, 'username' => 'CakePHP')
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->BlogPost->find('first', array(
|
|
|
- 'contain' => array(
|
|
|
+ $arrayResult = $this->BlogPost->find('first', array(
|
|
|
+ 'contain' => array(
|
|
|
'Tag'
|
|
|
),
|
|
|
- 'link' => array(
|
|
|
+ 'link' => array(
|
|
|
'User'
|
|
|
)
|
|
|
));
|
|
|
@@ -257,78 +257,78 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
public function _testPagination()
|
|
|
{
|
|
|
- $objController = new Controller(new CakeRequest('/'), new CakeResponse());
|
|
|
+ $objController = new Controller(new CakeRequest('/'), new CakeResponse());
|
|
|
$objController->layout = 'ajax';
|
|
|
- $objController->uses = array('User');
|
|
|
+ $objController->uses = array('User');
|
|
|
$objController->constructClasses();
|
|
|
- $objController->request->url = '/';
|
|
|
+ $objController->request->url = '/';
|
|
|
|
|
|
- $objController->paginate = array(
|
|
|
- 'fields' => array(
|
|
|
+ $objController->paginate = array(
|
|
|
+ 'fields' => array(
|
|
|
'username'
|
|
|
),
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Profile' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Profile' => array(
|
|
|
+ 'fields' => array(
|
|
|
'biography'
|
|
|
)
|
|
|
)
|
|
|
),
|
|
|
- 'limit' => 2
|
|
|
+ 'limit' => 2
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $objController->paginate('User');
|
|
|
+ $arrayResult = $objController->paginate('User');
|
|
|
|
|
|
$this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging: total records count: %s');
|
|
|
|
|
|
// Pagination with order on a row from table joined with Linkable
|
|
|
- $objController->paginate = array(
|
|
|
- 'fields' => array(
|
|
|
+ $objController->paginate = array(
|
|
|
+ 'fields' => array(
|
|
|
'id'
|
|
|
),
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
- 'Profile' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
+ 'Profile' => array(
|
|
|
+ 'fields' => array(
|
|
|
'user_id'
|
|
|
)
|
|
|
)
|
|
|
),
|
|
|
- 'limit' => 2,
|
|
|
- 'order' => 'Profile.user_id DESC'
|
|
|
+ 'limit' => 2,
|
|
|
+ 'order' => 'Profile.user_id DESC'
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $objController->paginate('User');
|
|
|
+ $arrayResult = $objController->paginate('User');
|
|
|
|
|
|
- $arrayExpected = array(
|
|
|
- 0 => array(
|
|
|
- 'User' => array(
|
|
|
+ $arrayExpected = array(
|
|
|
+ 0 => array(
|
|
|
+ 'User' => array(
|
|
|
'id' => 4
|
|
|
),
|
|
|
- 'Profile' => array ('user_id' => 4)
|
|
|
+ 'Profile' => array ('user_id' => 4)
|
|
|
),
|
|
|
- 1 => array(
|
|
|
- 'User' => array(
|
|
|
+ 1 => array(
|
|
|
+ 'User' => array(
|
|
|
'id' => 3
|
|
|
),
|
|
|
- 'Profile' => array ('user_id' => 3)
|
|
|
+ 'Profile' => array ('user_id' => 3)
|
|
|
)
|
|
|
);
|
|
|
|
|
|
$this->assertEquals($arrayResult, $arrayExpected, 'Paging with order on join table row: %s');
|
|
|
|
|
|
// Pagination without specifying any fields
|
|
|
- $objController->paginate = array(
|
|
|
- 'contain' => false,
|
|
|
- 'link' => array(
|
|
|
+ $objController->paginate = array(
|
|
|
+ 'contain' => false,
|
|
|
+ 'link' => array(
|
|
|
'Profile'
|
|
|
),
|
|
|
- 'limit' => 2,
|
|
|
- 'order' => 'Profile.user_id DESC'
|
|
|
+ 'limit' => 2,
|
|
|
+ 'order' => 'Profile.user_id DESC'
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $objController->paginate('User');
|
|
|
+ $arrayResult = $objController->paginate('User');
|
|
|
$this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging without any field lists: total records count: %s');
|
|
|
}
|
|
|
|
|
|
@@ -338,27 +338,27 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
*/
|
|
|
public function _testNonstandardAssociationNames()
|
|
|
{
|
|
|
- $this->Tag = ClassRegistry::init('Tag');
|
|
|
+ $this->Tag = ClassRegistry::init('Tag');
|
|
|
|
|
|
- $arrayExpected = array(
|
|
|
- 'Tag' => array(
|
|
|
- 'name' => 'Test I'
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'Tag' => array(
|
|
|
+ 'name' => 'Test I'
|
|
|
),
|
|
|
- 'Parent' => array(
|
|
|
- 'name' => 'General'
|
|
|
+ 'Parent' => array(
|
|
|
+ 'name' => 'General'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->Tag->find('first', array(
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->Tag->find('first', array(
|
|
|
+ 'fields' => array(
|
|
|
'name'
|
|
|
),
|
|
|
- 'conditions' => array(
|
|
|
- 'Tag.id' => 2
|
|
|
+ 'conditions' => array(
|
|
|
+ 'Tag.id' => 2
|
|
|
),
|
|
|
- 'link' => array(
|
|
|
- 'Parent' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'link' => array(
|
|
|
+ 'Parent' => array(
|
|
|
+ 'fields' => array(
|
|
|
'name'
|
|
|
)
|
|
|
)
|
|
|
@@ -368,35 +368,35 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
$this->assertEquals($arrayExpected, $arrayResult, 'Association with non-standard name: %s');
|
|
|
|
|
|
|
|
|
- $this->LegacyProduct = ClassRegistry::init('LegacyProduct');
|
|
|
+ $this->LegacyProduct = ClassRegistry::init('LegacyProduct');
|
|
|
|
|
|
- $arrayExpected = array(
|
|
|
- 'LegacyProduct' => array(
|
|
|
- 'name' => 'Velocipede'
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'LegacyProduct' => array(
|
|
|
+ 'name' => 'Velocipede'
|
|
|
),
|
|
|
- 'Maker' => array(
|
|
|
- 'company_name' => 'Vintage Stuff Manufactory'
|
|
|
+ 'Maker' => array(
|
|
|
+ 'company_name' => 'Vintage Stuff Manufactory'
|
|
|
),
|
|
|
- 'Transporter' => array(
|
|
|
- 'company_name' => 'Joe & Co Crate Shipping Company'
|
|
|
+ 'Transporter' => array(
|
|
|
+ 'company_name' => 'Joe & Co Crate Shipping Company'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->LegacyProduct->find('first', array(
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->LegacyProduct->find('first', array(
|
|
|
+ 'fields' => array(
|
|
|
'name'
|
|
|
),
|
|
|
- 'conditions' => array(
|
|
|
- 'LegacyProduct.product_id' => 1
|
|
|
+ 'conditions' => array(
|
|
|
+ 'LegacyProduct.product_id' => 1
|
|
|
),
|
|
|
- 'link' => array(
|
|
|
- 'Maker' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'link' => array(
|
|
|
+ 'Maker' => array(
|
|
|
+ 'fields' => array(
|
|
|
'company_name'
|
|
|
)
|
|
|
),
|
|
|
- 'Transporter' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'Transporter' => array(
|
|
|
+ 'fields' => array(
|
|
|
'company_name'
|
|
|
)
|
|
|
)
|
|
|
@@ -405,25 +405,25 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
$this->assertEquals($arrayExpected, $arrayResult, 'belongsTo associations with custom foreignKey: %s');
|
|
|
|
|
|
- $arrayExpected = array(
|
|
|
- 'ProductsMade' => array(
|
|
|
- 'name' => 'Velocipede'
|
|
|
+ $arrayExpected = array(
|
|
|
+ 'ProductsMade' => array(
|
|
|
+ 'name' => 'Velocipede'
|
|
|
),
|
|
|
- 'Maker' => array(
|
|
|
- 'company_name' => 'Vintage Stuff Manufactory'
|
|
|
+ 'Maker' => array(
|
|
|
+ 'company_name' => 'Vintage Stuff Manufactory'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->LegacyProduct->Maker->find('first', array(
|
|
|
- 'fields' => array(
|
|
|
+ $arrayResult = $this->LegacyProduct->Maker->find('first', array(
|
|
|
+ 'fields' => array(
|
|
|
'company_name'
|
|
|
),
|
|
|
- 'conditions' => array(
|
|
|
- 'Maker.company_id' => 1
|
|
|
+ 'conditions' => array(
|
|
|
+ 'Maker.company_id' => 1
|
|
|
),
|
|
|
- 'link' => array(
|
|
|
- 'ProductsMade' => array(
|
|
|
- 'fields' => array(
|
|
|
+ 'link' => array(
|
|
|
+ 'ProductsMade' => array(
|
|
|
+ 'fields' => array(
|
|
|
'name'
|
|
|
)
|
|
|
)
|
|
|
@@ -435,23 +435,23 @@ class LinkableBehaviorTest extends CakeTestCase {
|
|
|
|
|
|
public function _testAliasedBelongsToWithSameModelAsHasMany()
|
|
|
{
|
|
|
- $this->OrderItem = ClassRegistry::init('OrderItem');
|
|
|
+ $this->OrderItem = ClassRegistry::init('OrderItem');
|
|
|
|
|
|
- $arrayExpected = array(
|
|
|
- 0 => array(
|
|
|
- 'OrderItem' => array(
|
|
|
- 'id' => 50,
|
|
|
- 'active_shipment_id' => 320
|
|
|
+ $arrayExpected = array(
|
|
|
+ 0 => array(
|
|
|
+ 'OrderItem' => array(
|
|
|
+ 'id' => 50,
|
|
|
+ 'active_shipment_id' => 320
|
|
|
),
|
|
|
- 'ActiveShipment' => array(
|
|
|
- 'id' => 320,
|
|
|
- 'ship_date' => '2011-01-07',
|
|
|
- 'order_item_id' => 50
|
|
|
+ 'ActiveShipment' => array(
|
|
|
+ 'id' => 320,
|
|
|
+ 'ship_date' => '2011-01-07',
|
|
|
+ 'order_item_id' => 50
|
|
|
)
|
|
|
)
|
|
|
);
|
|
|
|
|
|
- $arrayResult = $this->OrderItem->find('all', array(
|
|
|
+ $arrayResult = $this->OrderItem->find('all', array(
|
|
|
'recursive' => -1,
|
|
|
'conditions' => array(
|
|
|
'ActiveShipment.ship_date' => date('2011-01-07'),
|
|
|
@@ -468,35 +468,35 @@ class TestModel extends CakeTestModel {
|
|
|
|
|
|
public $recursive = 0;
|
|
|
|
|
|
- public $actsAs = array(
|
|
|
+ public $actsAs = array(
|
|
|
'Containable',
|
|
|
'Tools.Linkable',
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class User extends TestModel {
|
|
|
- public $hasOne = array(
|
|
|
+ public $hasOne = array(
|
|
|
'Profile'
|
|
|
);
|
|
|
|
|
|
- public $hasMany = array(
|
|
|
+ public $hasMany = array(
|
|
|
'Comment',
|
|
|
'BlogPost'
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class Profile extends TestModel {
|
|
|
- public $belongsTo = array(
|
|
|
+ public $belongsTo = array(
|
|
|
'User'
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class BlogPost extends TestModel {
|
|
|
- public $belongsTo = array(
|
|
|
+ public $belongsTo = array(
|
|
|
'User'
|
|
|
);
|
|
|
|
|
|
- public $hasAndBelongsToMany = array(
|
|
|
+ public $hasAndBelongsToMany = array(
|
|
|
'Tag'
|
|
|
);
|
|
|
}
|
|
|
@@ -505,52 +505,52 @@ class BlogPostTag extends TestModel {
|
|
|
}
|
|
|
|
|
|
class Tag extends TestModel {
|
|
|
- public $hasAndBelongsToMany = array(
|
|
|
+ public $hasAndBelongsToMany = array(
|
|
|
'BlogPost'
|
|
|
);
|
|
|
|
|
|
- public $belongsTo = array(
|
|
|
- 'Parent' => array(
|
|
|
- 'className' => 'Tag',
|
|
|
- 'foreignKey' => 'parent_id'
|
|
|
+ public $belongsTo = array(
|
|
|
+ 'Parent' => array(
|
|
|
+ 'className' => 'Tag',
|
|
|
+ 'foreignKey' => 'parent_id'
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class LegacyProduct extends TestModel {
|
|
|
- public $primaryKey = 'product_id';
|
|
|
+ public $primaryKey = 'product_id';
|
|
|
|
|
|
- public $belongsTo = array(
|
|
|
- 'Maker' => array(
|
|
|
- 'className' => 'LegacyCompany',
|
|
|
- 'foreignKey' => 'the_company_that_builds_it_id'
|
|
|
+ public $belongsTo = array(
|
|
|
+ 'Maker' => array(
|
|
|
+ 'className' => 'LegacyCompany',
|
|
|
+ 'foreignKey' => 'the_company_that_builds_it_id'
|
|
|
),
|
|
|
- 'Transporter' => array(
|
|
|
- 'className' => 'LegacyCompany',
|
|
|
- 'foreignKey' => 'the_company_that_delivers_it_id'
|
|
|
+ 'Transporter' => array(
|
|
|
+ 'className' => 'LegacyCompany',
|
|
|
+ 'foreignKey' => 'the_company_that_delivers_it_id'
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class LegacyCompany extends TestModel {
|
|
|
- public $primaryKey = 'company_id';
|
|
|
+ public $primaryKey = 'company_id';
|
|
|
|
|
|
- public $hasMany = array(
|
|
|
- 'ProductsMade' => array(
|
|
|
- 'className' => 'LegacyProduct',
|
|
|
- 'foreignKey' => 'the_company_that_builds_it_id'
|
|
|
+ public $hasMany = array(
|
|
|
+ 'ProductsMade' => array(
|
|
|
+ 'className' => 'LegacyProduct',
|
|
|
+ 'foreignKey' => 'the_company_that_builds_it_id'
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class Shipment extends TestModel {
|
|
|
- public $belongsTo = array(
|
|
|
+ public $belongsTo = array(
|
|
|
'OrderItem'
|
|
|
);
|
|
|
}
|
|
|
|
|
|
class OrderItem extends TestModel {
|
|
|
- public $hasMany = array(
|
|
|
+ public $hasMany = array(
|
|
|
'Shipment'
|
|
|
);
|
|
|
|
|
|
@@ -560,4 +560,5 @@ class OrderItem extends TestModel {
|
|
|
'foreignKey' => 'active_shipment_id',
|
|
|
),
|
|
|
);
|
|
|
-}
|
|
|
+
|
|
|
+}
|