ContentEntityFieldMethodInvocationOrderTest.php in Drupal 9
File
core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\language\Entity\ConfigurableLanguage;
class ContentEntityFieldMethodInvocationOrderTest extends EntityKernelTestBase {
protected static $modules = [
'language',
'system',
'entity_test',
];
protected $entityTestFieldMethodsStorage;
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('de')
->save();
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->installEntitySchema('entity_test_field_methods');
$this->entityTestFieldMethodsStorage = $this->entityTypeManager
->getStorage('entity_test_field_methods');
}
public function testFieldMethodInvocationOrder() {
$entity = $this->entityTestFieldMethodsStorage
->create([
'name' => $this
->randomString(),
'langcode' => 'de',
]);
$entity
->save();
$entity
->addTranslation('fr')
->save();
foreach ([
'de',
'fr',
] as $langcode) {
$entity
->getTranslation($langcode)->test_invocation_order->value = 0;
}
$entity
->getTranslation('de')
->save();
$this
->assertGreaterThan($entity
->getTranslation('de')->test_invocation_order->value, $entity
->getTranslation('fr')->test_invocation_order->value);
foreach ([
'de',
'fr',
] as $langcode) {
$entity
->getTranslation($langcode)->test_invocation_order->value = 0;
}
$entity
->getTranslation('fr')
->save();
$this
->assertGreaterThan($entity
->getTranslation('fr')->test_invocation_order->value, $entity
->getTranslation('de')->test_invocation_order->value);
}
}