You are here

public function BundleEntityDuplicatorTest::testDuplicateDisplays in Entity API 8

@covers ::duplicateDisplays

File

tests/src/Kernel/BundleEntityDuplicatorTest.php, line 192

Class

BundleEntityDuplicatorTest
Tests the bundle entity duplicator.

Namespace

Drupal\Tests\entity\Kernel

Code

public function testDuplicateDisplays() {
  $this
    ->createTextField('field_text', 'test', 'Test text');
  $form_display = $this
    ->getDisplay('entity_test_with_bundle', 'test', 'form');
  $form_display
    ->setComponent('field_text', [
    'type' => 'text_textfield',
    'weight' => 0,
  ]);
  $form_display
    ->save();
  $view_display = $this
    ->getDisplay('entity_test_with_bundle', 'test', 'view');
  $view_display
    ->setComponent('field_text', [
    'type' => 'text_default',
    'weight' => 0,
  ]);
  $view_display
    ->save();
  $second_bundle_entity = EntityTestBundle::create([
    'id' => 'test2',
    'label' => 'Test2',
  ]);
  $second_bundle_entity
    ->save();
  FieldConfig::create([
    'entity_type' => 'entity_test_with_bundle',
    'field_name' => 'field_text',
    'bundle' => 'test2',
    'label' => 'Test text',
  ])
    ->save();
  $this->duplicator
    ->duplicateDisplays($this->bundleEntity, 'test2');
  $form_display = $this
    ->getDisplay('entity_test_with_bundle', 'test2', 'form');
  $this
    ->assertNotEmpty($form_display
    ->getComponent('field_text'));
  $view_display = $this
    ->getDisplay('entity_test_with_bundle', 'test2', 'view');
  $this
    ->assertNotEmpty($view_display
    ->getComponent('field_text'));
}