BehaviorRegressionTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\ORM\Behavior;
  16. use Cake\ORM\Behavior\Translate\TranslateTrait;
  17. use Cake\ORM\Entity;
  18. use Cake\ORM\TableRegistry;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * Stub entity class
  22. */
  23. class NumberTree extends Entity
  24. {
  25. use TranslateTrait;
  26. }
  27. /**
  28. * Behavior regression tests
  29. */
  30. class BehaviorRegressionTest extends TestCase
  31. {
  32. /**
  33. * fixtures
  34. *
  35. * @var array
  36. */
  37. public $fixtures = [
  38. 'core.translates',
  39. 'core.number_trees',
  40. ];
  41. /**
  42. * Tests that the tree behavior and the translations behavior play together
  43. *
  44. * @see https://github.com/cakephp/cakephp/issues/5982
  45. * @return void
  46. */
  47. public function testTreeAndTranslateIntegration() {
  48. $table = TableRegistry::get('NumberTrees');
  49. $table->primaryKey(['id']);
  50. $table->addBehavior('Tree');
  51. $table->addBehavior('Translate', ['fields' => ['name']]);
  52. $table->entityClass(__NAMESPACE__ . '\\NumberTree');
  53. $all = $table->find('threaded')->find('translations');
  54. $results = [];
  55. foreach ($all as $node) {
  56. $results[] = $node->translation('dan')->name;
  57. }
  58. $this->assertEquals(['Elektroniker', 'Alien Tingerne'], $results);
  59. }
  60. }