3 namespace Drupal\KernelTests\Core\Entity;
5 use Drupal\Core\Field\BaseFieldDefinition;
6 use Drupal\entity_test\Entity\EntityTest;
9 * Test the behavior of entity keys.
13 class EntityKeysTest extends EntityKernelTestBase {
16 * Test the cache when multiple keys reference a single field.
18 * @dataProvider multipleKeysCacheTestCases
20 public function testMultipleKeysCache($translatable) {
21 $this->state->set('entity_test.additional_base_field_definitions', [
22 'test_field' => BaseFieldDefinition::create('string')->setTranslatable($translatable),
24 $this->state->set('entity_test.entity_keys', [
25 'key_1' => 'test_field',
26 'key_2' => 'test_field',
28 drupal_flush_all_caches();
29 $this->installEntitySchema('entity_test');
31 $entity = EntityTest::create([]);
33 $entity->set('test_field', 'foo');
34 $this->assertEquals('foo', $entity->getEntityKey('key_1'));
35 $this->assertEquals('foo', $entity->getEntityKey('key_2'));
37 $entity->set('test_field', 'bar');
38 $this->assertEquals('bar', $entity->getEntityKey('key_1'));
39 $this->assertEquals('bar', $entity->getEntityKey('key_2'));
43 * Data provider for ::testMultipleKeysCache.
45 public function multipleKeysCacheTestCases() {
47 'translatable Entity Key' => [
50 'Non-translatable entity key' => [