3 namespace Drupal\Tests\text\Unit\Migrate;
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
15 class TextFieldTest extends UnitTestCase {
18 * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
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 processCckFieldValues() 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 ::processCckFieldValues
50 public function testProcessFilteredTextFieldValues() {
52 'widget_type' => 'text_textfield',
54 $this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
56 $process = $this->migration->getProcess();
57 $this->assertSame('iterator', $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 ::processCckFieldValues
73 public function testProcessBooleanTextImplicitValues() {
75 'widget_type' => 'optionwidgets_onoff',
76 'global_settings' => [
77 'allowed_values' => "foo\nbar",
80 $this->plugin->processCckFieldValues($this->migration, 'field', $info);
84 'plugin' => 'static_map',
92 $this->assertSame($expected, $this->migration->getProcess()['process']);
96 * @covers ::processCckFieldValues
98 public function testProcessBooleanTextExplicitValues() {
100 'widget_type' => 'optionwidgets_onoff',
101 'global_settings' => [
102 'allowed_values' => "foo|Foo\nbaz|Baz",
105 $this->plugin->processCckFieldValues($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', [
126 'text_processing' => FALSE,
128 ['string', 'text_textfield', [
129 'text_processing' => FALSE,
132 ['string_long', 'text_textfield', [
133 'text_processing' => FALSE,
134 'max_length' => 4096,
136 ['text_long', 'text_textfield', [
137 'text_processing' => TRUE,
139 ['text', 'text_textfield', [
140 'text_processing' => TRUE,
143 ['text_long', 'text_textfield', [
144 'text_processing' => TRUE,
145 'max_length' => 4096,
147 ['list_string', 'optionwidgets_buttons'],
148 ['list_string', 'optionwidgets_select'],
149 ['boolean', 'optionwidgets_onoff'],
150 ['text_long', 'text_textarea', [
151 'text_processing' => TRUE,
153 ['string_long', 'text_textarea', [
154 'text_processing' => FALSE,
161 * @covers ::getFieldType
162 * @dataProvider getFieldTypeProvider
164 public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
166 $row->setSourceProperty('widget_type', $widget_type);
167 $row->setSourceProperty('global_settings', $settings);
168 $this->assertSame($expected_type, $this->plugin->getFieldType($row));