You are here

public function BundleEntityDuplicatorTest::testDuplicateFields in Entity API 8

@covers ::duplicateFields

File

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

Class

BundleEntityDuplicatorTest
Tests the bundle entity duplicator.

Namespace

Drupal\Tests\entity\Kernel

Code

public function testDuplicateFields() {
  $this
    ->createTextField('field_text', 'test', 'Test text');
  $this
    ->createTextField('field_text2', 'test', 'Test text2');
  $second_bundle_entity = EntityTestBundle::create([
    'id' => 'test2',
    'label' => 'Test2',
  ]);
  $second_bundle_entity
    ->save();
  $entity = EntityTestWithBundle::create([
    'type' => 'test2',
  ]);
  $this
    ->assertFalse($entity
    ->hasField('field_text'));
  $this
    ->assertFalse($entity
    ->hasField('field_text2'));
  $this->duplicator
    ->duplicateFields($this->bundleEntity, 'test2');
  $entity = EntityTestWithBundle::create([
    'type' => 'test2',
  ]);
  $this
    ->assertTrue($entity
    ->hasField('field_text'));
  $this
    ->assertTrue($entity
    ->hasField('field_text2'));
}