1<?php
2
3/**
4 * @file
5 * Contains \Drupal\Tests\migrate\Unit\destination\PerComponentEntityFormDisplayTest.
6 */
7
8namespace Drupal\Tests\migrate\Unit\destination;
9
10use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityFormDisplay;
11use Drupal\migrate\Row;
12use Drupal\Tests\migrate\Unit\MigrateTestCase;
13
14/**
15 * Tests the entity display destination plugin.
16 *
17 * @group migrate
18 */
19class PerComponentEntityFormDisplayTest extends MigrateTestCase {
20
21  /**
22   * Tests the entity display import method.
23   */
24  public function testImport() {
25    $values = [
26      'entity_type' => 'entity_type_test',
27      'bundle' => 'bundle_test',
28      'form_mode' => 'form_mode_test',
29      'field_name' => 'field_name_test',
30      'options' => ['test setting'],
31    ];
32    $row = new Row();
33    foreach ($values as $key => $value) {
34      $row->setDestinationProperty($key, $value);
35    }
36    $entity = $this->getMockBuilder('Drupal\Core\Entity\Entity\EntityFormDisplay')
37      ->disableOriginalConstructor()
38      ->getMock();
39    $entity->expects($this->once())
40      ->method('setComponent')
41      ->with('field_name_test', ['test setting'])
42      ->will($this->returnSelf());
43    $entity->expects($this->once())
44      ->method('save')
45      ->with();
46    $plugin = new TestPerComponentEntityFormDisplay($entity);
47    $this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test'], $plugin->import($row));
48    $this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test'], $plugin->getTestValues());
49  }
50
51}
52
53class TestPerComponentEntityFormDisplay extends PerComponentEntityFormDisplay {
54  const MODE_NAME = 'form_mode';
55  protected $testValues;
56
57  public function __construct($entity) {
58    $this->entity = $entity;
59  }
60
61  protected function getEntity($entity_type, $bundle, $form_mode) {
62    $this->testValues = func_get_args();
63    return $this->entity;
64  }
65
66  public function getTestValues() {
67    return $this->testValues;
68  }
69
70}
71