You are here

protected function EntityReferenceItemTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::setUp()
  2. 9 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::setUp()

Sets up the test.

File

core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php, line 77

Class

EntityReferenceItemTest
Tests the new entity API for the entity reference field type.

Namespace

Drupal\Tests\field\Kernel\EntityReference

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('entity_test_string_id');
  $this
    ->installEntitySchema('taxonomy_term');
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('comment');
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('comment', [
    'comment_entity_statistics',
  ]);
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this->vocabulary = Vocabulary::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => mb_strtolower($this
      ->randomMachineName()),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $this->vocabulary
    ->save();
  $this->term = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => $this->vocabulary
      ->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $this->term
    ->save();
  NodeType::create([
    'type' => $this
      ->randomMachineName(),
  ])
    ->save();
  CommentType::create([
    'id' => $this
      ->randomMachineName(),
    'target_entity_type_id' => 'node',
  ])
    ->save();
  $this->entityStringId = EntityTestStringId::create([
    'id' => $this
      ->randomMachineName(),
  ]);
  $this->entityStringId
    ->save();

  // Use the util to create an instance.
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term');
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_entity_test_string_id', 'Test content entity reference with string ID', 'entity_test_string_id');
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_node', 'Test node entity reference', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user');
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment');
  $this
    ->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file');
  $this
    ->createEntityReferenceField('entity_test_string_id', 'entity_test_string_id', 'field_test_entity_test', 'Test content entity reference with string ID', 'entity_test');
}