浏览代码

fix tests

euromark 13 年之前
父节点
当前提交
ec043bb509

+ 9 - 0
Model/Behavior/LinkableBehavior.php

@@ -118,6 +118,7 @@ class LinkableBehavior extends ModelBehavior {
 							$referenceKey = $Reference->escapeField($Reference->primaryKey);
 							$options['conditions'][] = "{$referenceKey} = {$modelKey}";
 						} elseif ($type === 'hasAndBelongsToMany') {
+							// try to determine fields by HABTM model
 							if (isset($association['with'])) {
 								$Link = $_Model->{$association['with']};
 								if (isset($Link->belongsTo[$_Model->alias])) {
@@ -129,6 +130,14 @@ class LinkableBehavior extends ModelBehavior {
 							} else {
 								$Link = $_Model->{Inflector::classify($association['joinTable'])};
 							}
+							// try to determine fields by current model relation settings
+							if (empty($modelLink) && !empty($_Model->{$type}[$Reference->alias]['foreignKey'])) {
+								$modelLink = $Link->escapeField($_Model->{$type}[$Reference->alias]['foreignKey']);
+							}
+							if (empty($referenceLink) && !empty($_Model->{$type}[$Reference->alias]['associationForeignKey'])) {
+								$referenceLink = $Link->escapeField($_Model->{$type}[$Reference->alias]['associationForeignKey']);
+							}
+							// fallback to defaults otherwise
 							if (empty($modelLink)) {
 								$modelLink = $Link->escapeField(Inflector::underscore($_Model->alias) . '_id');
 							}

+ 8 - 6
Test/Case/AllToolsTest.php

@@ -1,18 +1,20 @@
 <?php
 /**
- * group test - Tools
+ * Tools Plugin - All plugin tests
  */
-class AllAuthTestsTest extends PHPUnit_Framework_TestSuite {
+class AllToolsTest extends PHPUnit_Framework_TestSuite {
 
 	/**
-	 * suite method, defines tests for this suite.
+	 * Suite method, defines tests for this suite.
 	 *
 	 * @return void
 	 */
 	public static function suite() {
-		$Suite = new CakeTestSuite('All Auth tests');
-		$path = dirname(__FILE__);
-		$Suite->addTestDirectory($path . DS . 'Controller' . DS . 'Component' . DS . 'Auth');
+		$Suite = new CakeTestSuite('All Tools tests');
+
+		$path = CakePlugin::path('Tools') . 'Test' . DS . 'Case' . DS;
+		$Suite->addTestDirectoryRecursive($path);
 		return $Suite;
 	}
+
 }

+ 1 - 1
Test/Case/Controller/Component/AutoLoginComponentTest.php

@@ -11,7 +11,7 @@ App::uses('Controller', 'Controller');
  */
 class AutoLoginComponentTest extends CakeTestCase {
 
-	public $fixtures = array('core.cake_session', 'plugin.tools.user');
+	public $fixtures = array('core.cake_session', 'core.user');
 
 	/**
 	 * setUp method

+ 3 - 1
Test/Case/Lib/Utility/NumberTextLibTest.php

@@ -3,11 +3,13 @@
 App::uses('NumberTextLib', 'Tools.Utility');
 App::uses('MyCakeTestCase', 'Tools.TestSuite');
 
-class NumberLibTest extends MyCakeTestCase {
+class NumberTextLibTest extends MyCakeTestCase {
 
 	public $NumberText = null;
 
 	public function setUp() {
+		parent::setUp();
+
 		//$this->NumberText = new NumberTextLib();
 	}
 

+ 3 - 3
Test/Case/Model/Behavior/BitmaskedBehaviorTest.php

@@ -1,6 +1,6 @@
 <?php
 
-App::import('Behavior', 'Tools.Bitmasked');
+App::uses('BitmaskedBehavior', 'Tools.Model/Behavior');
 App::uses('AppModel', 'Model');
 App::uses('MyCakeTestCase', 'Tools.TestSuite');
 App::uses('MyModel', 'Tools.Model');
@@ -16,7 +16,7 @@ class BitmaskedBehaviorTest extends MyCakeTestCase {
 	public function setUp() {
 
 		$this->Comment = new BitmaskedComment();
-		$this->Comment->Behaviors->load('Bitmasked', array('mappedField'=>'statuses'));
+		$this->Comment->Behaviors->load('Tools.Bitmasked', array('mappedField'=>'statuses'));
 	}
 
 	public function testEncodeBitmask() {
@@ -106,7 +106,7 @@ class BitmaskedBehaviorTest extends MyCakeTestCase {
 	 * assert that you can manually trigger "notEmpty" rule with null instead of 0 for "not null" db fields
 	 */
 	public function testSaveWithDefaultValue() {
-		$this->Comment->Behaviors->load('Bitmasked', array('mappedField'=>'statuses', 'defaultValue' => ''));
+		$this->Comment->Behaviors->load('Tools.Bitmasked', array('mappedField'=>'statuses', 'defaultValue' => ''));
 		$data = array(
 			'comment' => 'test save',
 			'statuses' => array(),

+ 10 - 10
Test/Case/Model/Behavior/CustomFindsBehaviorTest.php

@@ -1,23 +1,14 @@
 <?php
-
 App::uses('CustomFindsBehavior', 'Tools.Model/Behavior');
 App::uses('AppModel', 'Model');
 App::uses('MyCakeTestCase', 'Tools.TestSuite');
 
-class Test extends AppModel {
-
-
-	public $useTable = false;
-	public $actsAs = array('Tools.CustomFinds');
-
-}
-
 class CustomFindsBehaviorTest extends MyCakeTestCase {
 
 	public function setUp() {
 		$this->CustomFinds = new CustomFindsBehavior();
 
-		$this->Model = new Test();
+		$this->Model = new CustomFindsTest();
 
 		$this->Model->customFinds = array(
 			'topSellers' => array(
@@ -90,3 +81,12 @@ class CustomFindsBehaviorTest extends MyCakeTestCase {
 	}
 
 }
+
+
+class CustomFindsTest extends AppModel {
+
+	public $useTable = false;
+
+	public $actsAs = array('Tools.CustomFinds');
+
+}

+ 110 - 86
Test/Case/Model/Behavior/LinkableBehaviorTest.php

@@ -6,13 +6,13 @@ App::uses('Controller', 'Controller');
 class LinkableBehaviorTest extends CakeTestCase {
 
 	public $fixtures = array(
-		'plugin.tools.user',
-		'plugin.tools.profile',
+		'plugin.tools.linkable_user',
+		'plugin.tools.linkable_profile',
 		'plugin.tools.generic',
-		'plugin.tools.comment',
+		'plugin.tools.linkable_comment',
 		'plugin.tools.blog_post',
-		'plugin.tools.blog_posts_tag',
-		'plugin.tools.tag',
+		'plugin.tools.blog_posts_linkable_tag',
+		'plugin.tools.linkable_tag',
 		'plugin.tools.legacy_product',
 		'plugin.tools.legacy_company',
 		'plugin.tools.shipment',
@@ -22,7 +22,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 	public $User;
 
 	public function setUp() {
-		$this->User = ClassRegistry::init('User');
+		$this->User = ClassRegistry::init('LinkableUser');
 	}
 
 	public function tearDown() {
@@ -31,19 +31,19 @@ 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.')
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP'),
+			'LinkableProfile' => 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(
-				'Profile'
+				'LinkableProfile'
 			)
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
-		$this->assertTrue(isset($arrayResult['Profile']), 'belongsTo association via Containable: %s');
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
+		$this->assertTrue(isset($arrayResult['LinkableProfile']), 'belongsTo association via Containable: %s');
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'belongsTo association via Containable: %s');
 
 		// Same association, but this time with Linkable
@@ -54,7 +54,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			),
 			'contain' => false,
 			'link' => array(
-				'Profile' => array(
+				'LinkableProfile' => array(
 					'fields' => array(
 						'id',
 						'user_id',
@@ -64,26 +64,26 @@ class LinkableBehaviorTest extends CakeTestCase {
 			)
 		));
 
-		$this->assertTrue(isset($arrayResult['Profile']), 'belongsTo association via Linkable: %s');
-		$this->assertTrue(!empty($arrayResult['Profile']), 'belongsTo association via Linkable: %s');
+		$this->assertTrue(isset($arrayResult['LinkableProfile']), 'belongsTo association via Linkable: %s');
+		$this->assertTrue(!empty($arrayResult['LinkableProfile']), 'belongsTo association via Linkable: %s');
 		$this->assertEquals($arrayExpected, $arrayResult, 'belongsTo association via Linkable: %s');
 
 		// Linkable association, no field lists
 		$arrayResult = $this->User->find('first', array(
 			'contain' => false,
 			'link' => array(
-				'Profile'
+				'LinkableProfile'
 			)
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
-		$this->assertTrue(isset($arrayResult['Profile']), 'belongsTo association via Linkable (automatic fields): %s');
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
+		$this->assertTrue(isset($arrayResult['LinkableProfile']), 'belongsTo association via Linkable (automatic fields): %s');
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'belongsTo association via Linkable (automatic fields): %s');
 
 		// On-the-fly association via Linkable
 		$arrayExpected = array(
-			'User' => array('id' => 1, 'username' => 'CakePHP'),
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP'),
 			'Generic' => array('id' => 1, 'text' => '')
 		);
 
@@ -92,7 +92,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			'link' => array(
 				'Generic' => array(
 					'class' => 'Generic',
-					'conditions' => array('exactly' => 'User.id = Generic.id'),
+					'conditions' => array('exactly' => 'LinkableUser.id = Generic.id'),
 					'fields' => array(
 						'id',
 						'text'
@@ -102,13 +102,13 @@ class LinkableBehaviorTest extends CakeTestCase {
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
 		$this->assertTrue(isset($arrayResult['Generic']), 'On-the-fly belongsTo association via Linkable: %s');
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, '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'),
+			'LinkableUser' => array('id' => 4, 'username' => 'CodeIgniter'),
 			'Generic' => array('id' => 4, 'text' => '')
 		);
 
@@ -117,7 +117,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			'link' => array(
 				'Generic' => array(
 					'class' => 'Generic',
-					'conditions' => array('exactly' => array('User.id = Generic.id')),
+					'conditions' => array('exactly' => array('LinkableUser.id = Generic.id')),
 					'fields' => array(
 						'id',
 						'text'
@@ -128,15 +128,15 @@ class LinkableBehaviorTest extends CakeTestCase {
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 3;
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 3;
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'On-the-fly belongsTo association via Linkable, with order: %s');
 	}
 
 	public function testHasMany() {
 		// hasMany association via Containable. Should still work when Linkable is loaded
 		$arrayExpected = array(
-			'User' => array('id' => 1, 'username' => 'CakePHP'),
-			'Comment' => array(
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP'),
+			'LinkableComment' => array(
 				0 => array(
 					'id' => 1,
 					'user_id' => 1,
@@ -152,20 +152,20 @@ class LinkableBehaviorTest extends CakeTestCase {
 
 		$arrayResult = $this->User->find('first', array(
 			'contain' => array(
-				'Comment'
+				'LinkableComment'
 			),
-			'order' => 'User.id ASC'
+			'order' => 'LinkableUser.id ASC'
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
-		$this->assertTrue(isset($arrayResult['Comment']), 'hasMany association via Containable: %s');
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
+		$this->assertTrue(isset($arrayResult['LinkableComment']), 'hasMany association via Containable: %s');
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'hasMany association via Containable: %s');
 
 		// Same association, but this time with Linkable
 		$arrayExpected = array(
-			'User' => array('id' => 1, 'username' => 'CakePHP'),
-			'Comment' => array(
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP'),
+			'LinkableComment' => array(
 				'id' => 1,
 				'user_id' => 1,
 				'body' => 'Text'
@@ -179,7 +179,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			),
 			'contain' => false,
 			'link' => array(
-				'Comment' => array(
+				'LinkableComment' => array(
 					'fields' => array(
 						'id',
 						'user_id',
@@ -187,8 +187,8 @@ class LinkableBehaviorTest extends CakeTestCase {
 					)
 				)
 			),
-			'order' => 'User.id ASC',
-			'group' => 'User.id'
+			'order' => 'LinkableUser.id ASC',
+			'group' => 'LinkableUser.id'
 		));
 
 		$this->assertEquals($arrayExpected, $arrayResult, 'hasMany association via Linkable: %s');
@@ -199,77 +199,77 @@ class LinkableBehaviorTest extends CakeTestCase {
 
 		$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'),
+			'LinkableTag' => array('name' => 'General'),
+			'LinkableProfile' => array('biography' => 'CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications.'),
+			'MainLinkableTag' => array('name' => 'General'),
 			'Generic' => array('id' => 1,'text' => ''),
-			'User' => array('id' => 1, 'username' => 'CakePHP')
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP')
 		);
 
 		$arrayResult = $this->BlogPost->find('first', array(
 			'conditions' => array(
-				'MainTag.id' => 1
+				'MainLinkableTag.id' => 1
 			),
 			'link' => array(
-				'User' => array(
-					'Profile' => array(
+				'LinkableUser' => array(
+					'LinkableProfile' => array(
 						'fields' => array(
 							'biography'
 						),
 						'Generic' => array(
 							'class'	 => 'Generic',
-							'conditions' => array('exactly' => 'User.id = Generic.id'),
+							'conditions' => array('exactly' => 'LinkableUser.id = Generic.id'),
 						)
 					)
 				),
-				'Tag' => array(
-					'table' => 'tags',
+				'LinkableTag' => array(
+					'table' => 'linkable_tags',
 					'fields' => array(
 						'name'
 					)
 				),
-				'MainTag' => array(
-					'class' => 'Tag',
-					'conditions' => array('exactly' => 'BlogPostsTag.blog_post_id = BlogPost.id'),
+				'MainLinkableTag' => array(
+					'class' => 'LinkableTag',
+					'conditions' => array('exactly' => 'BlogPostsLinkableTag.blog_post_id = BlogPost.id'),
 					'fields' => array(
-						'MainTag.name'
+						'MainLinkableTag.name'
 					)
 				)
 			)
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'Complex find: %s');
 
 		// Linkable and Containable combined
 		$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))
+			'LinkableUser' => array('id' => 1, 'username' => 'CakePHP'),
+			'LinkableTag' => array(
+				array('id' => 1, 'name' => 'General', 'parent_id' => null, 'BlogPostsLinkableTag' => array('id' => 1, 'blog_post_id' => 1, 'tag_id' => 1, 'main' => 0)),
+				//array('id' => 2, 'name' => 'Test I', 'parent_id' => 1, 'BlogPostsLinkableTag' => array('id' => 2, 'blog_post_id' => 1, 'tag_id' => 2, 'main' => 1))
 			),
-			'User' => array('id' => 1, 'username' => 'CakePHP')
 		);
 
 		$arrayResult = $this->BlogPost->find('first', array(
 			'contain' => array(
-				'Tag'
+				'LinkableTag'
 			),
 			'link' => array(
-				'User'
+				'LinkableUser'
 			)
 		));
 
 		$arrayExpectedTmp = $arrayExpected;
-		$arrayExpectedTmp['User']['role_id'] = 1;
+		$arrayExpectedTmp['LinkableUser']['role_id'] = 1;
 		$this->assertEquals($arrayExpectedTmp, $arrayResult, 'Linkable and Containable combined: %s');
 	}
 
 	public function _testPagination() {
 		$objController = new Controller(new CakeRequest('/'), new CakeResponse());
 		$objController->layout = 'ajax';
-		$objController->uses = array('User');
+		$objController->uses = array('LinkableUser');
 		$objController->constructClasses();
 		$objController->request->url = '/';
 
@@ -279,7 +279,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			),
 			'contain' => false,
 			'link' => array(
-				'Profile' => array(
+				'LinkableProfile' => array(
 					'fields' => array(
 						'biography'
 					)
@@ -288,9 +288,9 @@ class LinkableBehaviorTest extends CakeTestCase {
 			'limit' => 2
 		);
 
-		$arrayResult = $objController->paginate('User');
+		$arrayResult = $objController->paginate('LinkableUser');
 
-		$this->assertEquals(4, $objController->params['paging']['User']['count'], 'Paging: total records count: %s');
+		$this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging: total records count: %s');
 
 		// Pagination with order on a row from table joined with Linkable
 		$objController->paginate = array(
@@ -299,7 +299,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 			),
 			'contain' => false,
 			'link' => array(
-				'Profile' => array(
+				'LinkableProfile' => array(
 					'fields' => array(
 						'user_id'
 					)
@@ -309,20 +309,20 @@ class LinkableBehaviorTest extends CakeTestCase {
 			'order' => 'Profile.user_id DESC'
 		);
 
-		$arrayResult = $objController->paginate('User');
+		$arrayResult = $objController->paginate('LinkableUser');
 
 		$arrayExpected = array(
 			0 => array(
-				'User' => array(
+				'LinkableUser' => array(
 					'id' => 4
 				),
-				'Profile' => array ('user_id' => 4)
+				'LinkableProfile' => array ('user_id' => 4)
 			),
 			1 => array(
-				'User' => array(
+				'LinkableUser' => array(
 					'id' => 3
 				),
-				'Profile' => array ('user_id' => 3)
+				'LinkableProfile' => array ('user_id' => 3)
 			)
 		);
 
@@ -332,14 +332,14 @@ class LinkableBehaviorTest extends CakeTestCase {
 		$objController->paginate = array(
 			'contain' => false,
 			'link' => array(
-				'Profile'
+				'LinkableProfile'
 			),
 			'limit' => 2,
 			'order' => 'Profile.user_id DESC'
 		);
 
-		$arrayResult = $objController->paginate('User');
-		$this->assertEquals(4, $objController->params['paging']['User']['count'], 'Paging without any field lists: total records count: %s');
+		$arrayResult = $objController->paginate('LinkableUser');
+		$this->assertEquals(4, $objController->params['paging']['LinkableUser']['count'], 'Paging without any field lists: total records count: %s');
 	}
 
 	/**
@@ -347,10 +347,10 @@ class LinkableBehaviorTest extends CakeTestCase {
 	 *	have aliases different from their standard model names
 	 */
 	public function _testNonstandardAssociationNames() {
-		$this->Tag = ClassRegistry::init('Tag');
+		$this->LinkableTag = ClassRegistry::init('LinkableTag');
 
 		$arrayExpected = array(
-			'Tag' => array(
+			'LinkableTag' => array(
 				'name' => 'Test I'
 			),
 			'Parent' => array(
@@ -358,12 +358,12 @@ class LinkableBehaviorTest extends CakeTestCase {
 			)
 		);
 
-		$arrayResult = $this->Tag->find('first', array(
+		$arrayResult = $this->LinkableTag->find('first', array(
 			'fields' => array(
 				'name'
 			),
 			'conditions' => array(
-				'Tag.id' => 2
+				'LinkableTag.id' => 2
 			),
 			'link' => array(
 				'Parent' => array(
@@ -475,7 +475,7 @@ class LinkableBehaviorTest extends CakeTestCase {
 
 class LinkableTestModel extends CakeTestModel {
 
-	public $recursive = 0;
+	public $recursive = -1;
 
 	public $actsAs = array(
 		'Containable',
@@ -483,48 +483,72 @@ class LinkableTestModel extends CakeTestModel {
 	);
 }
 
-class User extends LinkableTestModel {
+class LinkableUser extends LinkableTestModel {
 
 	public $hasOne = array(
-		'Profile'
+		'LinkableProfile' => array(
+			'className' => 'LinkableProfile',
+			'foreignKey' => 'user_id'
+		)
 	);
 
 	public $hasMany = array(
-		'Comment',
-		'BlogPost'
+		'LinkableComment' => array(
+			'className' => 'LinkableComment',
+			'foreignKey' => 'user_id'
+		),
+		'BlogPost' => array(
+			'foreignKey' => 'user_id'
+		)
 	);
 }
 
-class Profile extends LinkableTestModel {
+class LinkableComment extends LinkableTestModel {
+
+}
+
+class LinkableProfile extends LinkableTestModel {
 
 	public $belongsTo = array(
-		'User'
+		'LinkableUser' => array(
+			'className' => 'LinkableUser',
+			'foreignKey' => 'user_id'
+		)
 	);
 }
 
 class BlogPost extends LinkableTestModel {
 
 	public $belongsTo = array(
-		'User'
+		'LinkableUser' => array(
+			'className' => 'LinkableUser',
+			'foreignKey' => 'user_id'
+		),
 	);
 
 	public $hasAndBelongsToMany = array(
-		'Tag'
+		'LinkableTag' => array(
+			'foreignKey' => 'tag_id',
+			'associationForeignKey' => 'blog_post_id',
+		)
 	);
 }
 
-class BlogPostTag extends LinkableTestModel {
+class BlogPostLinkableTag extends LinkableTestModel {
 }
 
-class Tag extends LinkableTestModel {
+class LinkableTag extends LinkableTestModel {
 
 	public $hasAndBelongsToMany = array(
-		'BlogPost'
+		'BlogPost' => array(
+			'foreignKey' => 'blog_post_id',
+			'associationForeignKey' => 'tag_id',
+		)
 	);
 
 	public $belongsTo = array(
 		'Parent' => array(
-			'className' => 'Tag',
+			'className' => 'LinkableTag',
 			'foreignKey' => 'parent_id'
 		)
 	);

+ 12 - 4
Test/Case/Model/MyModelTest.php

@@ -15,9 +15,9 @@ class MyModelTest extends MyCakeTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Model = ClassRegistry::init('Post');
+		$this->Model = ClassRegistry::init('MyAppModelPost');
 
-		$this->App = ClassRegistry::init('User');
+		$this->App = ClassRegistry::init('MyAppModelUser');
 	}
 
 	public function testObject() {
@@ -660,13 +660,21 @@ class MyModelTest extends MyCakeTestCase {
 
 }
 
-class Post extends MyModel {
+class MyAppModelPost extends MyModel {
+
+	public $name = 'Post';
+
+	public $alias = 'Post';
 
 	public $belongsTo = 'Author';
 
 }
 
-class User extends MyModel {
+class MyAppModelUser extends MyModel {
+
+	public $name = 'User';
+
+	public $alias = 'User';
 
 }
 

+ 1 - 1
Test/Fixture/BlogPostsTagFixture.php

@@ -1,6 +1,6 @@
 <?php
 
-class BlogPostsTagFixture extends CakeTestFixture {
+class BlogPostsLinkableTagFixture extends CakeTestFixture {
 
 	public $fields = array(
 		'id'		=> array('type' => 'integer', 'key' => 'primary'),

+ 1 - 2
Test/Fixture/CommentFixture.php

@@ -1,7 +1,6 @@
 <?php
 
-class CommentFixture extends CakeTestFixture {
-
+class LinkableCommentFixture extends CakeTestFixture {
 
 	public $fields = array(
 		'id'		=> array('type' => 'integer', 'key' => 'primary'),

+ 1 - 2
Test/Fixture/ProfileFixture.php

@@ -1,7 +1,6 @@
 <?php
 
-class ProfileFixture extends CakeTestFixture {
-
+class LinkableProfileFixture extends CakeTestFixture {
 
 	public $fields = array(
 		'id'		=> array('type' => 'integer', 'key' => 'primary'),

+ 1 - 2
Test/Fixture/TagFixture.php

@@ -1,7 +1,6 @@
 <?php
 
-class TagFixture extends CakeTestFixture {
-
+class LinkableTagFixture extends CakeTestFixture {
 
 	public $fields = array(
 		'id'		=> array('type' => 'integer', 'key' => 'primary'),

+ 2 - 2
Test/Fixture/UserFixture.php

@@ -1,7 +1,6 @@
 <?php
 
-class UserFixture extends CakeTestFixture {
-
+class LinkableUserFixture extends CakeTestFixture {
 
 	public $fields = array(
 		'id'			=> array('type' => 'integer', 'key' => 'primary'),
@@ -15,4 +14,5 @@ class UserFixture extends CakeTestFixture {
 		array('id' => 3, 'username' => 'Symfony', 'role_id' => 2),
 		array('id' => 4, 'username' => 'CodeIgniter', 'role_id' => 3)
 	);
+
 }