function EntityKeysTest::testMultipleKeysCache
Tests the cache when multiple keys reference a single field.
@dataProvider multipleKeysCacheTestCases
File
- 
              core/tests/ Drupal/ KernelTests/ Core/ Entity/ EntityKeysTest.php, line 20 
Class
- EntityKeysTest
- Test the behavior of entity keys.
Namespace
Drupal\KernelTests\Core\EntityCode
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'));
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
