606572ecd85834fdcff949158a1f9e88980f5d4f
[yaffs-website] / web / core / modules / language / tests / src / Unit / process / LanguageTypesTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Unit\process;
4
5 use Drupal\language\Plugin\migrate\process\LanguageTypes;
6 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
7 use Drupal\migrate\MigrateException;
8
9 /**
10  * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
11  * @group language
12  */
13 class LanguageTypesTest extends MigrateProcessTestCase {
14
15   /**
16    * Tests successful transformation of all language types.
17    */
18   public function testTransformAll() {
19     $this->plugin = new LanguageTypes([], 'map', []);
20     $source = [
21       'language' => TRUE,
22       'language_url' => FALSE,
23       'language_content' => FALSE,
24     ];
25     $expected = [
26       0 => 'language_url',
27       1 => 'language_content',
28       2 => 'language_interface',
29     ];
30     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
31     $this->assertSame($value, $expected);
32   }
33
34   /**
35    * Tests successful transformation of configurable language types.
36    */
37   public function testTransformConfigurable() {
38     $this->plugin = new LanguageTypes(['filter_configurable' => TRUE], 'map', []);
39     $source = [
40       'language' => TRUE,
41       'language_url' => FALSE,
42       'language_content' => FALSE,
43     ];
44     $expected = [
45       0 => 'language_interface',
46     ];
47     $value = $this->plugin->transform($source, $this->migrateExecutable, $this->row, 'destinationproperty');
48     $this->assertSame($value, $expected);
49   }
50
51   /**
52    * Tests string input.
53    */
54   public function testStringInput() {
55     $this->plugin = new LanguageTypes([], 'map', []);
56     $this->setExpectedException(MigrateException::class, 'The input should be an array');
57     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
58   }
59
60 }