3 namespace Drupal\Tests\text\Unit\Plugin\migrate\cckfield;
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
7 use Drupal\Tests\UnitTestCase;
8 use Drupal\text\Plugin\migrate\cckfield\TextField;
12 * @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
16 class TextCckTest extends UnitTestCase {
19 * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
24 * @var \Drupal\migrate\Plugin\MigrationInterface
31 protected function setUp() {
32 $this->plugin = new TextField([], 'text', []);
34 $migration = $this->prophesize(MigrationInterface::class);
36 // The plugin's processCckFieldValues() method will call
37 // setProcessOfProperty() and return nothing. So, in order to examine the
38 // process pipeline created by the plugin, we need to ensure that
39 // getProcess() always returns the last input to setProcessOfProperty().
40 $migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
41 ->will(function ($arguments) use ($migration) {
42 $migration->getProcess()->willReturn($arguments[1]);
45 $this->migration = $migration->reveal();
49 * @covers ::processCckFieldValues
51 public function testProcessFilteredTextFieldValues() {
53 'widget_type' => 'text_textfield',
55 $this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
57 $process = $this->migration->getProcess();
58 $this->assertSame('sub_process', $process['plugin']);
59 $this->assertSame('body', $process['source']);
60 $this->assertSame('value', $process['process']['value']);
62 // Ensure that filter format IDs will be looked up in the filter format
64 $lookup = $process['process']['format'][2];
65 $this->assertSame('migration', $lookup['plugin']);
66 $this->assertContains('d6_filter_format', $lookup['migration']);
67 $this->assertContains('d7_filter_format', $lookup['migration']);
68 $this->assertSame('format', $lookup['source']);
72 * @covers ::processCckFieldValues
74 public function testProcessBooleanTextImplicitValues() {
76 'widget_type' => 'optionwidgets_onoff',
77 'global_settings' => [
78 'allowed_values' => "foo\nbar",
81 $this->plugin->processCckFieldValues($this->migration, 'field', $info);
85 'plugin' => 'static_map',
93 $this->assertSame($expected, $this->migration->getProcess()['process']);
97 * @covers ::processCckFieldValues
99 public function testProcessBooleanTextExplicitValues() {
101 'widget_type' => 'optionwidgets_onoff',
102 'global_settings' => [
103 'allowed_values' => "foo|Foo\nbaz|Baz",
106 $this->plugin->processCckFieldValues($this->migration, 'field', $info);
110 'plugin' => 'static_map',
112 'default_value' => 0,
118 $this->assertSame($expected, $this->migration->getProcess()['process']);
122 * Data provider for testGetFieldType().
124 public function getFieldTypeProvider() {
126 ['string_long', 'text_textfield', ['text_processing' => FALSE]],
127 ['string', 'text_textfield', [
128 'text_processing' => FALSE,
132 ['string_long', 'text_textfield', [
133 'text_processing' => FALSE,
134 'max_length' => 4096,
137 ['text_long', 'text_textfield', ['text_processing' => TRUE]],
138 ['text', 'text_textfield', [
139 'text_processing' => TRUE,
143 ['text_long', 'text_textfield', [
144 'text_processing' => TRUE,
145 'max_length' => 4096,
148 ['list_string', 'optionwidgets_buttons'],
149 ['list_string', 'optionwidgets_select'],
150 ['boolean', 'optionwidgets_onoff'],
151 ['text_long', 'text_textarea', ['text_processing' => TRUE]],
152 ['string_long', 'text_textarea', ['text_processing' => FALSE]],
158 * @covers ::getFieldType
159 * @dataProvider getFieldTypeProvider
161 public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
162 $row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
163 $row->setSourceProperty('global_settings', $settings);
164 $this->assertSame($expected_type, $this->plugin->getFieldType($row));