3 namespace Drupal\Tests\text\Unit\Plugin\migrate\field\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
15 class TextFieldTest extends UnitTestCase {
18 * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
23 * @var \Drupal\migrate\Plugin\MigrationInterface
30 protected function setUp() {
31 $this->plugin = new TextField([], 'text', []);
33 $migration = $this->prophesize(MigrationInterface::class);
35 // The plugin's defineValueProcessPipeline() method will call
36 // setProcessOfProperty() and return nothing. So, in order to examine the
37 // process pipeline created by the plugin, we need to ensure that
38 // getProcess() always returns the last input to setProcessOfProperty().
39 $migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
40 ->will(function ($arguments) use ($migration) {
41 $migration->getProcess()->willReturn($arguments[1]);
44 $this->migration = $migration->reveal();
48 * @covers ::defineValueProcessPipeline
50 public function testProcessFilteredTextFieldValues($method = 'defineValueProcessPipeline') {
52 'widget_type' => 'text_textfield',
54 $this->plugin->$method($this->migration, 'body', $field_info);
56 $process = $this->migration->getProcess();
57 $this->assertSame('sub_process', $process['plugin']);
58 $this->assertSame('body', $process['source']);
59 $this->assertSame('value', $process['process']['value']);
61 // Ensure that filter format IDs will be looked up in the filter format
63 $lookup = $process['process']['format'][2];
64 $this->assertSame('migration', $lookup['plugin']);
65 $this->assertContains('d6_filter_format', $lookup['migration']);
66 $this->assertContains('d7_filter_format', $lookup['migration']);
67 $this->assertSame('format', $lookup['source']);
71 * @covers ::defineValueProcessPipeline
73 public function testProcessBooleanTextImplicitValues($method = 'defineValueProcessPipeline') {
75 'widget_type' => 'optionwidgets_onoff',
76 'global_settings' => [
77 'allowed_values' => "foo\nbar",
80 $this->plugin->$method($this->migration, 'field', $info);
84 'plugin' => 'static_map',
92 $this->assertSame($expected, $this->migration->getProcess()['process']);
96 * @covers ::defineValueProcessPipeline
98 public function testProcessBooleanTextExplicitValues($method = 'defineValueProcessPipeline') {
100 'widget_type' => 'optionwidgets_onoff',
101 'global_settings' => [
102 'allowed_values' => "foo|Foo\nbaz|Baz",
105 $this->plugin->$method($this->migration, 'field', $info);
109 'plugin' => 'static_map',
111 'default_value' => 0,
117 $this->assertSame($expected, $this->migration->getProcess()['process']);
121 * Data provider for testGetFieldType().
123 public function getFieldTypeProvider() {
125 ['string_long', 'text_textfield', ['text_processing' => FALSE]],
126 ['string', 'text_textfield', [
127 'text_processing' => FALSE,
131 ['string_long', 'text_textfield', [
132 'text_processing' => FALSE,
133 'max_length' => 4096,
136 ['text_long', 'text_textfield', ['text_processing' => TRUE]],
137 ['text', 'text_textfield', [
138 'text_processing' => TRUE,
142 ['text_long', 'text_textfield', [
143 'text_processing' => TRUE,
144 'max_length' => 4096,
147 ['list_string', 'optionwidgets_buttons'],
148 ['list_string', 'optionwidgets_select'],
149 ['boolean', 'optionwidgets_onoff'],
150 ['text_long', 'text_textarea', ['text_processing' => TRUE]],
151 ['string_long', 'text_textarea', ['text_processing' => FALSE]],
157 * @covers ::getFieldType
158 * @dataProvider getFieldTypeProvider
160 public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
162 $row->setSourceProperty('widget_type', $widget_type);
163 $row->setSourceProperty('global_settings', $settings);
164 $this->assertSame($expected_type, $this->plugin->getFieldType($row));