class ContentEntityFieldMethodInvocationOrderTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest
- 10 core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ContentEntityFieldMethodInvocationOrderTest.php \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest
Tests correct field method invocation order.
@group Entity
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Core\Entity\ContentEntityFieldMethodInvocationOrderTest extends \Drupal\KernelTests\Core\Entity\EntityKernelTestBase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ContentEntityFieldMethodInvocationOrderTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ ContentEntityFieldMethodInvocationOrderTest.php, line 12
Namespace
Drupal\KernelTests\Core\EntityView source
class ContentEntityFieldMethodInvocationOrderTest extends EntityKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'language',
'system',
'entity_test',
];
/**
* The EntityTest entity type storage.
*
* @var \Drupal\Core\Entity\ContentEntityStorageInterface
*/
protected $entityTestFieldMethodsStorage;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Enable an additional language.
ConfigurableLanguage::createFromLangcode('de')->save();
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->installEntitySchema('entity_test_field_methods');
$this->entityTestFieldMethodsStorage = $this->entityTypeManager
->getStorage('entity_test_field_methods');
}
/**
* Tests correct field method invocation order.
*/
public function testFieldMethodInvocationOrder() {
// 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.