You are here

protected function MediaIefIntegrationTest::setUp in Media entity 8

Overrides MediaEntityJavascriptTestBase::setUp

File

tests/src/FunctionalJavascript/MediaIefIntegrationTest.php, line 27

Class

MediaIefIntegrationTest
Tests the integration between Inline Entity Form and Media Entity.

Namespace

Drupal\Tests\media_entity\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();

  /** @var \Drupal\media_entity\MediaBundleInterface $media_bundle */
  $media_bundle = $this
    ->drupalCreateMediaBundle();

  // Create a new content type.
  $values = [
    'name' => 'Media entity CT',
    'title_label' => 'An example Custom Content type.',
    'type' => 'media_entity_ct',
  ];
  $content_type = $this
    ->createContentType($values);

  // Create an entity_reference field.
  FieldStorageConfig::create([
    'field_name' => 'ref_media_entities',
    'type' => 'entity_reference',
    'entity_type' => 'node',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    'settings' => [
      'target_type' => 'media',
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'ref_media_entities',
    'field_type' => 'entity_reference',
    'entity_type' => 'node',
    'bundle' => $content_type
      ->id(),
    'label' => 'Media referenced',
    'settings' => [
      'handler' => 'default:media',
      'handler_settings' => [
        'target_bundles' => [
          $media_bundle
            ->id() => $media_bundle
            ->id(),
        ],
        'sort' => [
          'field' => '_none',
        ],
        'auto_create' => FALSE,
        'auto_create_bundle' => $media_bundle
          ->id(),
      ],
    ],
  ])
    ->save();

  // Set widget to inline_entity_form.

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
  $form_display = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_form_display')
    ->load('node.media_entity_ct.default');
  $form_display
    ->setComponent('ref_media_entities', [
    'type' => 'inline_entity_form_complex',
    'settings' => [],
  ])
    ->save();
}