class EntityKeysTest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php \Drupal\KernelTests\Core\Entity\EntityKeysTest
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityKeysTest.php \Drupal\KernelTests\Core\Entity\EntityKeysTest
Test the behavior of entity keys.
@group entity
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
- class \Drupal\KernelTests\Core\Entity\EntityKeysTest
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
Expanded class hierarchy of EntityKeysTest
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityKeysTest.php, line 13
Namespace
Drupal\KernelTests\Core\EntityView source
class EntityKeysTest extends EntityKernelTestBase {
/**
* Tests the cache when multiple keys reference a single field.
*
* @dataProvider multipleKeysCacheTestCases
*/
public function testMultipleKeysCache($translatable) {
$this->state
->set('entity_test.additional_base_field_definitions', [
'test_field' => BaseFieldDefinition::create('string')
->setTranslatable($translatable),
]);
$this->state
->set('entity_test.entity_keys', [
'key_1' => 'test_field',
'key_2' => 'test_field',
]);
$this
->installEntitySchema('entity_test');
$entity = EntityTest::create([]);
$entity
->set('test_field', 'foo');
$this
->assertEquals('foo', $entity
->getEntityKey('key_1'));
$this
->assertEquals('foo', $entity
->getEntityKey('key_2'));
$entity
->set('test_field', 'bar');
$this
->assertEquals('bar', $entity
->getEntityKey('key_1'));
$this
->assertEquals('bar', $entity
->getEntityKey('key_2'));
}
/**
* Data provider for ::testMultipleKeysCache.
*/
public function multipleKeysCacheTestCases() {
return [
'translatable Entity Key' => [
TRUE,
],
'Non-translatable entity key' => [
FALSE,
],
];
}
}