BehaviorRegressionTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://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\TestSuite\TestCase;
  19. /**
  20. * Stub entity class
  21. */
  22. class NumberTree extends Entity
  23. {
  24. use TranslateTrait;
  25. }
  26. /**
  27. * Behavior regression tests
  28. */
  29. class BehaviorRegressionTest extends TestCase
  30. {
  31. /**
  32. * fixtures
  33. *
  34. * @var array
  35. */
  36. public $fixtures = [
  37. 'core.NumberTrees',
  38. 'core.Translates',
  39. ];
  40. /**
  41. * Tests that the tree behavior and the translations behavior play together
  42. *
  43. * @see https://github.com/cakephp/cakephp/issues/5982
  44. * @return void
  45. */
  46. public function testTreeAndTranslateIntegration()
  47. {
  48. $table = $this->getTableLocator()->get('NumberTrees');
  49. $table->setPrimaryKey(['id']);
  50. $table->addBehavior('Tree');
  51. $table->addBehavior('Translate', ['fields' => ['name']]);
  52. $table->setEntityClass(__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. }