ContentEntityFieldMethodInvocationOrderTest.php in Drupal 8
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 {
public static $modules = [
'language',
'system',
'entity_test',
];
protected $entityTestFieldMethodsStorage;
protected function setUp() {
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
->assertTrue($entity
->getTranslation('fr')->test_invocation_order->value > $entity
->getTranslation('de')->test_invocation_order->value, 'The field presave method has been invoked in the correct entity translation order.');
foreach ([
'de',
'fr',
] as $langcode) {
$entity
->getTranslation($langcode)->test_invocation_order->value = 0;
}
$entity
->getTranslation('fr')
->save();
$this
->assertTrue($entity
->getTranslation('de')->test_invocation_order->value > $entity
->getTranslation('fr')->test_invocation_order->value, 'The field presave method has been invoked in the correct entity translation order.');
}
}