function ContentEntityFieldMethodInvocationOrderTest::testFieldMethodInvocationOrder

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest::testFieldMethodInvocationOrder()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest::testFieldMethodInvocationOrder()
  3. 10 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest::testFieldMethodInvocationOrder()

Tests correct field method invocation order.

File

core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php, line 48

Class

ContentEntityFieldMethodInvocationOrderTest
Tests correct field method invocation order.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testFieldMethodInvocationOrder() : void {
    // Create a test entity.
    $entity = $this->entityTestFieldMethodsStorage
        ->create([
        'name' => $this->randomString(),
        'langcode' => 'de',
    ]);
    $entity->save();
    $entity->addTranslation('fr')
        ->save();
    // Reset the current value of the test field.
    foreach ([
        'de',
        'fr',
    ] as $langcode) {
        $entity->getTranslation($langcode)->test_invocation_order->value = 0;
    }
    $entity->getTranslation('de')
        ->save();
    // Verify that the field presave method has been invoked in the correct
    // entity translation order.
    $this->assertGreaterThan($entity->getTranslation('de')->test_invocation_order->value, $entity->getTranslation('fr')->test_invocation_order->value);
    // Reset the current value of the test field.
    foreach ([
        'de',
        'fr',
    ] as $langcode) {
        $entity->getTranslation($langcode)->test_invocation_order->value = 0;
    }
    $entity->getTranslation('fr')
        ->save();
    // Verify that the field presave method has been invoked in the correct
    // entity translation order.
    $this->assertGreaterThan($entity->getTranslation('fr')->test_invocation_order->value, $entity->getTranslation('de')->test_invocation_order->value);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.