3 namespace Drupal\KernelTests\Core\Entity;
5 use Drupal\language\Entity\ConfigurableLanguage;
8 * Tests correct field method invocation order.
12 class ContentEntityFieldMethodInvocationOrderTest extends EntityKernelTestBase {
19 public static $modules = ['language', 'system', 'entity_test'];
22 * The EntityTest entity type storage.
24 * @var \Drupal\Core\Entity\ContentEntityStorageInterface
26 protected $entityTestFieldMethodsStorage;
31 protected function setUp() {
34 // Enable an additional language.
35 ConfigurableLanguage::createFromLangcode('de')->save();
36 ConfigurableLanguage::createFromLangcode('fr')->save();
38 $this->installEntitySchema('entity_test_field_methods');
40 $this->entityTestFieldMethodsStorage = $this->entityManager->getStorage('entity_test_field_methods');
44 * Tests correct field method invocation order.
46 public function testFieldMethodInvocationOrder() {
48 // Create a test entity.
49 $entity = $this->entityTestFieldMethodsStorage->create([
50 'name' => $this->randomString(),
55 $entity->addTranslation('fr')
58 // Reset the current value of the test field.
59 foreach (['de', 'fr'] as $langcode) {
60 $entity->getTranslation($langcode)->test_invocation_order->value = 0;
62 $entity->getTranslation('de')
64 $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.');
66 // Reset the current value of the test field.
67 foreach (['de', 'fr'] as $langcode) {
68 $entity->getTranslation($langcode)->test_invocation_order->value = 0;
70 $entity->getTranslation('fr')
72 $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.');