Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / text / tests / src / Unit / Migrate / d6 / TextFieldTest.php
index 8bf5d2a2d07d5d1352d55f6f40335c90ab0f553a..807b9f16e5ec7d9d1231496f8e2a27f45756b7c4 100644 (file)
@@ -33,7 +33,7 @@ class TextFieldTest extends UnitTestCase {
 
     $migration = $this->prophesize(MigrationInterface::class);
 
-    // The plugin's processFieldValues() method will call
+    // The plugin's defineValueProcessPipeline() method will call
     // setProcessOfProperty() and return nothing. So, in order to examine the
     // process pipeline created by the plugin, we need to ensure that
     // getProcess() always returns the last input to setProcessOfProperty().
@@ -46,7 +46,11 @@ class TextFieldTest extends UnitTestCase {
   }
 
   /**
+   * Calls the deprecated processFieldValues() method to test BC.
+   *
    * @covers ::processFieldValues
+   *
+   * @depends testFilteredTextValueProcessPipeline
    */
   public function testProcessFilteredTextFieldValues() {
     $field_info = [
@@ -69,14 +73,41 @@ class TextFieldTest extends UnitTestCase {
   }
 
   /**
+   * @covers ::defineValueProcessPipeline
+   */
+  public function testFilteredTextValueProcessPipeline() {
+    $field_info = [
+      'widget_type' => 'text_textfield',
+    ];
+    $this->plugin->defineValueProcessPipeline($this->migration, 'body', $field_info);
+
+    $process = $this->migration->getProcess();
+    $this->assertSame('sub_process', $process['plugin']);
+    $this->assertSame('body', $process['source']);
+    $this->assertSame('value', $process['process']['value']);
+
+    // Ensure that filter format IDs will be looked up in the filter format
+    // migrations.
+    $lookup = $process['process']['format'][2];
+    $this->assertSame('migration', $lookup['plugin']);
+    $this->assertContains('d6_filter_format', $lookup['migration']);
+    $this->assertContains('d7_filter_format', $lookup['migration']);
+    $this->assertSame('format', $lookup['source']);
+  }
+
+  /**
+   * Calls the deprecated processFieldValues() method to test BC.
+   *
    * @covers ::processFieldValues
+   *
+   * @depends testBooleanTextImplicitValueProcessPipeline
    */
   public function testProcessBooleanTextImplicitValues() {
     $info = [
       'widget_type' => 'optionwidgets_onoff',
       'global_settings' => [
         'allowed_values' => "foo\nbar",
-      ]
+      ],
     ];
     $this->plugin->processFieldValues($this->migration, 'field', $info);
 
@@ -94,14 +125,43 @@ class TextFieldTest extends UnitTestCase {
   }
 
   /**
+   * @covers ::defineValueProcessPipeline
+   */
+  public function testBooleanTextImplicitValueProcessPipeline() {
+    $info = [
+      'widget_type' => 'optionwidgets_onoff',
+      'global_settings' => [
+        'allowed_values' => "foo\nbar",
+      ],
+    ];
+    $this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
+
+    $expected = [
+      'value' => [
+        'plugin' => 'static_map',
+        'source' => 'value',
+        'default_value' => 0,
+        'map' => [
+          'bar' => 1,
+        ],
+      ],
+    ];
+    $this->assertSame($expected, $this->migration->getProcess()['process']);
+  }
+
+  /**
+   * Calls the deprecated processFieldValues() method to test BC.
+   *
    * @covers ::processFieldValues
+   *
+   * @depends testBooleanTextExplicitValueProcessPipeline
    */
   public function testProcessBooleanTextExplicitValues() {
     $info = [
       'widget_type' => 'optionwidgets_onoff',
       'global_settings' => [
         'allowed_values' => "foo|Foo\nbaz|Baz",
-      ]
+      ],
     ];
     $this->plugin->processFieldValues($this->migration, 'field', $info);
 
@@ -118,6 +178,31 @@ class TextFieldTest extends UnitTestCase {
     $this->assertSame($expected, $this->migration->getProcess()['process']);
   }
 
+  /**
+   * @covers ::defineValueProcessPipeline
+   */
+  public function testBooleanTextExplicitValueProcessPipeline() {
+    $info = [
+      'widget_type' => 'optionwidgets_onoff',
+      'global_settings' => [
+        'allowed_values' => "foo|Foo\nbaz|Baz",
+      ],
+    ];
+    $this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
+
+    $expected = [
+      'value' => [
+        'plugin' => 'static_map',
+        'source' => 'value',
+        'default_value' => 0,
+        'map' => [
+          'baz' => 1,
+        ],
+      ],
+    ];
+    $this->assertSame($expected, $this->migration->getProcess()['process']);
+  }
+
   /**
    * Data provider for testGetFieldType().
    */