diff --git a/src/Template/Bake/Model/table.twig b/src/Template/Bake/Model/table.twig index 959da6330..0527995ec 100644 --- a/src/Template/Bake/Model/table.twig +++ b/src/Template/Bake/Model/table.twig @@ -57,7 +57,7 @@ class {{ name }}Table extends Table {% endif %} {%- for behavior, behaviorData in behaviors %} - $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", [" ~ behaviorData|join(', ') ~ ']') : '')|raw }}); + $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", [" ~ Bake.stringifyList(behaviorData, {'indent': 3, 'quotes': false})|raw ~ ']') : '')|raw }}); {% endfor %} {%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %} diff --git a/tests/TestCase/Shell/Task/ModelTaskTest.php b/tests/TestCase/Shell/Task/ModelTaskTest.php index 37960ca87..ae0144c88 100644 --- a/tests/TestCase/Shell/Task/ModelTaskTest.php +++ b/tests/TestCase/Shell/Task/ModelTaskTest.php @@ -1039,11 +1039,14 @@ public function testGetBehaviors() $model = TableRegistry::get('Posts', [ 'table' => 'counter_cache_posts' ]); - $result = $this->Task->getBehaviors($model); - $expected = [ - 'CounterCache' => ["'Users' => ['post_count']"] + $behaviors = $this->Task->getBehaviors($model); + + $behaviors['Translate'] = [ + 'defaultLocale' => "'fr_FR'" ]; - $this->assertEquals($expected, $result); + + $result = $this->Task->bakeTable($model, ['behaviors' => $behaviors]); + $this->assertSameAsFile(__FUNCTION__ . '.php', $result); } /** diff --git a/tests/comparisons/Model/testGetBehaviors.php b/tests/comparisons/Model/testGetBehaviors.php new file mode 100644 index 000000000..014269f79 --- /dev/null +++ b/tests/comparisons/Model/testGetBehaviors.php @@ -0,0 +1,55 @@ +setPrimaryKey('id'); + + $this->addBehavior('CounterCache', [ + 'Users' => ['post_count'] + ]); + $this->addBehavior('Translate', [ + 'defaultLocale' => 'fr_FR' + ]); + } + + /** + * Returns the database connection name to use by default. + * + * @return string + */ + public static function defaultConnectionName() + { + return 'test'; + } +}