3 namespace Drupal\Tests\text\Unit\Migrate\d6;
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
7 use Drupal\Tests\UnitTestCase;
8 use Drupal\text\Plugin\migrate\field\d6\TextField;
12 * @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
16 class TextFieldTest extends UnitTestCase {
19 * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
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 defineValueProcessPipeline() 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 * Calls the deprecated processFieldValues() method to test BC.
51 * @covers ::processFieldValues
53 * @depends testFilteredTextValueProcessPipeline
55 public function testProcessFilteredTextFieldValues() {
57 'widget_type' => 'text_textfield',
59 $this->plugin->processFieldValues($this->migration, 'body', $field_info);
61 $process = $this->migration->getProcess();
62 $this->assertSame('sub_process', $process['plugin']);
63 $this->assertSame('body', $process['source']);
64 $this->assertSame('value', $process['process']['value']);
66 // Ensure that filter format IDs will be looked up in the filter format
68 $lookup = $process['process']['format'][2];
69 $this->assertSame('migration', $lookup['plugin']);
70 $this->assertContains('d6_filter_format', $lookup['migration']);
71 $this->assertContains('d7_filter_format', $lookup['migration']);
72 $this->assertSame('format', $lookup['source']);
76 * @covers ::defineValueProcessPipeline
78 public function testFilteredTextValueProcessPipeline() {
80 'widget_type' => 'text_textfield',
82 $this->plugin->defineValueProcessPipeline($this->migration, 'body', $field_info);
84 $process = $this->migration->getProcess();
85 $this->assertSame('sub_process', $process['plugin']);
86 $this->assertSame('body', $process['source']);
87 $this->assertSame('value', $process['process']['value']);
89 // Ensure that filter format IDs will be looked up in the filter format
91 $lookup = $process['process']['format'][2];
92 $this->assertSame('migration', $lookup['plugin']);
93 $this->assertContains('d6_filter_format', $lookup['migration']);
94 $this->assertContains('d7_filter_format', $lookup['migration']);
95 $this->assertSame('format', $lookup['source']);
99 * Calls the deprecated processFieldValues() method to test BC.
101 * @covers ::processFieldValues
103 * @depends testBooleanTextImplicitValueProcessPipeline
105 public function testProcessBooleanTextImplicitValues() {
107 'widget_type' => 'optionwidgets_onoff',
108 'global_settings' => [
109 'allowed_values' => "foo\nbar",
112 $this->plugin->processFieldValues($this->migration, 'field', $info);
116 'plugin' => 'static_map',
118 'default_value' => 0,
124 $this->assertSame($expected, $this->migration->getProcess()['process']);
128 * @covers ::defineValueProcessPipeline
130 public function testBooleanTextImplicitValueProcessPipeline() {
132 'widget_type' => 'optionwidgets_onoff',
133 'global_settings' => [
134 'allowed_values' => "foo\nbar",
137 $this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
141 'plugin' => 'static_map',
143 'default_value' => 0,
149 $this->assertSame($expected, $this->migration->getProcess()['process']);
153 * Calls the deprecated processFieldValues() method to test BC.
155 * @covers ::processFieldValues
157 * @depends testBooleanTextExplicitValueProcessPipeline
159 public function testProcessBooleanTextExplicitValues() {
161 'widget_type' => 'optionwidgets_onoff',
162 'global_settings' => [
163 'allowed_values' => "foo|Foo\nbaz|Baz",
166 $this->plugin->processFieldValues($this->migration, 'field', $info);
170 'plugin' => 'static_map',
172 'default_value' => 0,
178 $this->assertSame($expected, $this->migration->getProcess()['process']);
182 * @covers ::defineValueProcessPipeline
184 public function testBooleanTextExplicitValueProcessPipeline() {
186 'widget_type' => 'optionwidgets_onoff',
187 'global_settings' => [
188 'allowed_values' => "foo|Foo\nbaz|Baz",
191 $this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
195 'plugin' => 'static_map',
197 'default_value' => 0,
203 $this->assertSame($expected, $this->migration->getProcess()['process']);
207 * Data provider for testGetFieldType().
209 public function getFieldTypeProvider() {
211 ['string_long', 'text_textfield', ['text_processing' => FALSE]],
212 ['string', 'text_textfield', [
213 'text_processing' => FALSE,
217 ['string_long', 'text_textfield', [
218 'text_processing' => FALSE,
219 'max_length' => 4096,
222 ['text_long', 'text_textfield', ['text_processing' => TRUE]],
223 ['text', 'text_textfield', [
224 'text_processing' => TRUE,
228 ['text_long', 'text_textfield', [
229 'text_processing' => TRUE,
230 'max_length' => 4096,
233 ['list_string', 'optionwidgets_buttons'],
234 ['list_string', 'optionwidgets_select'],
235 ['boolean', 'optionwidgets_onoff'],
236 ['text_long', 'text_textarea', ['text_processing' => TRUE]],
237 ['string_long', 'text_textarea', ['text_processing' => FALSE]],
243 * @covers ::getFieldType
244 * @dataProvider getFieldTypeProvider
246 public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
248 $row->setSourceProperty('widget_type', $widget_type);
249 $row->setSourceProperty('global_settings', $settings);
250 $this->assertSame($expected_type, $this->plugin->getFieldType($row));