Browse Source

Added test to prove #5982

Jose Lorenzo Rodriguez 11 years ago
parent
commit
37fe4d455a

+ 3 - 1
tests/Fixture/TranslatesFixture.php

@@ -77,6 +77,8 @@ class TranslatesFixture extends TestFixture
         ['locale' => 'eng', 'model' => 'Comments', 'foreign_key' => 3, 'field' => 'comment', 'content' => 'Comment #3'],
         ['locale' => 'eng', 'model' => 'Comments', 'foreign_key' => 4, 'field' => 'comment', 'content' => 'Comment #4'],
         ['locale' => 'spa', 'model' => 'Comments', 'foreign_key' => 4, 'field' => 'comment', 'content' => 'Comentario #4'],
-        ['locale' => 'eng', 'model' => 'Authors', 'foreign_key' => 1, 'field' => 'name', 'content' => 'May-rianoh']
+        ['locale' => 'eng', 'model' => 'Authors', 'foreign_key' => 1, 'field' => 'name', 'content' => 'May-rianoh'],
+        ['locale' => 'dan', 'model' => 'NumberTrees', 'foreign_key' => 1, 'field' => 'name', 'content' => 'Elektroniker'],
+        ['locale' => 'dan', 'model' => 'NumberTrees', 'foreign_key' => 11, 'field' => 'name', 'content' => 'Alien Tingerne'],
     ];
 }

+ 67 - 0
tests/TestCase/ORM/Behavior/BehaviorRegressionTest.php

@@ -0,0 +1,67 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.0.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Test\TestCase\ORM\Behavior;
+
+use Cake\ORM\Behavior\Translate\TranslateTrait;
+use Cake\ORM\Entity;
+use Cake\ORM\TableRegistry;
+use Cake\TestSuite\TestCase;
+
+/**
+ * Stub entity class
+ */
+class NumberTree extends Entity
+{
+
+    use TranslateTrait;
+}
+
+/**
+ * Behavior regression tests
+ */
+class BehaviorRegressionTest extends TestCase
+{
+    /**
+     * fixtures
+     *
+     * @var array
+     */
+    public $fixtures = [
+        'core.translates',
+        'core.number_trees',
+    ];
+
+    /**
+     * Tests that the tree behavior and the translations behavior play together
+     *
+     * @see https://github.com/cakephp/cakephp/issues/5982
+     * @return void
+     */
+    public function testTreeAndTranslateIntegration() {
+        $table = TableRegistry::get('NumberTrees');
+        $table->primaryKey(['id']);
+        $table->addBehavior('Tree');
+        $table->addBehavior('Translate', ['fields' => ['name']]);
+        $table->entityClass(__NAMESPACE__ . '\\NumberTree');
+
+        $all = $table->find('threaded')->find('translations');
+        $results = [];
+        foreach ($all as $node) {
+            $results[] = $node->translation('dan')->name;
+        }
+        $this->assertEquals(['Elektroniker', 'Alien Tingerne'], $results);
+    }
+
+}