Skip to content
Permalink
Browse files

Fix ViewTask generating links for self associations.

When getting the list of associations, self associations should be
excluded.

Refs #4440
  • Loading branch information...
markstory committed Sep 1, 2014
1 parent 081f271 commit ae7d61042abfbb5f477cdb42832492ae7a991275
@@ -444,6 +444,10 @@ protected function _associations(Table $model) {
$assocName = $assoc->name();
$alias = $target->alias();
if (get_class($target) === get_class($model)) {
continue;
}
$associations[$type][$assocName] = [
'property' => $assoc->property(),
'variable' => Inflector::variable($assocName),
@@ -25,7 +25,6 @@
/**
* Test View Task Comment Model
*
*/
class ViewTaskCommentsTable extends Table {
@@ -40,7 +39,6 @@ public function initialize(array $config) {
/**
* Test View Task Article Model
*
*/
class ViewTaskArticlesTable extends Table {
@@ -52,7 +50,6 @@ public function intialize(array $config) {
/**
* Test View Task Comments Controller
*
*/
class ViewTaskCommentsController extends Controller {
@@ -76,7 +73,6 @@ public function add() {
}
/**
* ViewTaskTest class
*/
@@ -89,7 +85,11 @@ class ViewTaskTest extends TestCase {
*/
public $fixtures = array(
'core.article', 'core.post', 'core.comment',
'core.articles_tag', 'core.tag', 'core.test_plugin_comment');
'core.articles_tag',
'core.tag',
'core.test_plugin_comment',
'core.category_thread',
);
/**
* setUp method
@@ -430,6 +430,26 @@ public function testBakeIndexPlugin() {
$this->Task->bake('index', true);
}
/**
* Ensure that models associated with themselves do not have action
* links generated.
*
* @return void
*/
public function testBakeSelfAssociations() {
$this->Task->controllerName = 'CategoryThreads';
$this->Task->modelName = 'TestApp\Model\Table\CategoryThreadsTable';
$this->Task->expects($this->once())
->method('createFile')
->with(
$this->_normalizePath(APP . 'Template/CategoryThreads/index.ctp'),
$this->logicalNot($this->stringContains('ParentCategoryThread'))
);
$this->Task->bake('index', true);
}
/**
* test that baking a view with no template doesn't make a file.
*
@@ -0,0 +1,33 @@
<?php
/**
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2013, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Model\Table;
use Cake\ORM\Table;
/**
* CategoryThreadsTable
*/
class CategoryThreadsTable extends Table {
public function initialize(array $config) {
$this->table('category_threads');
$this->belongsTo('ParentCategoryThreads', [
'className' => __CLASS__,
'foreignKey' => 'parent_id'
]);
$this->hasMany('ChildCategoryThreads', [
'className' => __CLASS__,
'foreignKey' => 'parent_id'
]);
}
}

0 comments on commit ae7d610

Please sign in to comment.
You can’t perform that action at this time.