Version 1
[yaffs-website] / web / core / modules / field / tests / src / Unit / Plugin / migrate / process / d6 / FieldSettingsTest.php
1 <?php
2
3 namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d6;
4
5 use Drupal\field\Plugin\migrate\process\d6\FieldSettings;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\MigrateExecutableInterface;
8 use Drupal\migrate\Row;
9 use Drupal\Tests\UnitTestCase;
10
11 /**
12  * @coversDefaultClass \Drupal\field\Plugin\migrate\process\d6\FieldSettings
13  * @group field
14  */
15 class FieldSettingsTest extends UnitTestCase {
16
17   /**
18    * @covers ::getSettings
19    *
20    * @dataProvider getSettingsProvider
21    */
22   public function testGetSettings($field_type, $field_settings, $allowed_values) {
23     $migration = $this->getMock(MigrationInterface::class);
24     $plugin = new FieldSettings([], 'd6_field_settings', [], $migration);
25
26     $executable = $this->getMock(MigrateExecutableInterface::class);
27     $row = $this->getMockBuilder(Row::class)
28       ->disableOriginalConstructor()
29       ->getMock();
30
31     $result = $plugin->transform([$field_type, $field_settings, NULL], $executable, $row, 'foo');
32     $this->assertSame($allowed_values, $result['allowed_values']);
33   }
34
35   /**
36    * Provides field settings for testGetSettings().
37    */
38   public function getSettingsProvider() {
39     return [
40       [
41         'list_integer',
42         ['allowed_values' => "1|One\n2|Two\n3"],
43         [
44           '1' => 'One',
45           '2' => 'Two',
46           '3' => '3',
47         ],
48       ],
49       [
50         'list_string',
51         ['allowed_values' => NULL],
52         [],
53       ],
54       [
55         'list_float',
56         ['allowed_values' => ""],
57         [],
58       ],
59       [
60         'boolean',
61         [],
62         [],
63       ],
64     ];
65   }
66
67 }