You are here

public function PerComponentEntityDisplayTest::testImport in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/destination/PerComponentEntityDisplayTest.php \Drupal\Tests\migrate\Unit\destination\PerComponentEntityDisplayTest::testImport()
  2. 9 core/modules/migrate/tests/src/Unit/destination/PerComponentEntityDisplayTest.php \Drupal\Tests\migrate\Unit\destination\PerComponentEntityDisplayTest::testImport()

Tests the entity display import method.

File

core/modules/migrate/tests/src/Unit/destination/PerComponentEntityDisplayTest.php, line 24
Contains \Drupal\Tests\migrate\Unit\destination\PerComponentEntityDisplayTest.

Class

PerComponentEntityDisplayTest
Tests the entity display destination plugin.

Namespace

Drupal\Tests\migrate\Unit\destination

Code

public function testImport() {
  $values = [
    'entity_type' => 'entity_type_test',
    'bundle' => 'bundle_test',
    'view_mode' => 'view_mode_test',
    'field_name' => 'field_name_test',
    'options' => [
      'test setting',
    ],
  ];
  $row = new Row();
  foreach ($values as $key => $value) {
    $row
      ->setDestinationProperty($key, $value);
  }
  $entity = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Entity\\EntityViewDisplay')
    ->disableOriginalConstructor()
    ->getMock();
  $entity
    ->expects($this
    ->once())
    ->method('setComponent')
    ->with('field_name_test', [
    'test setting',
  ])
    ->will($this
    ->returnSelf());
  $entity
    ->expects($this
    ->once())
    ->method('save')
    ->with();
  $plugin = new TestPerComponentEntityDisplay($entity);
  $this
    ->assertSame([
    'entity_type_test',
    'bundle_test',
    'view_mode_test',
    'field_name_test',
  ], $plugin
    ->import($row));
  $this
    ->assertSame([
    'entity_type_test',
    'bundle_test',
    'view_mode_test',
  ], $plugin
    ->getTestValues());
}