414d9c21d9f9fe6dd76d0dbb27f6b0f90724c80e
[yaffs-website] / web / core / modules / file / tests / src / Unit / Plugin / migrate / cckfield / d7 / FileCckTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d7;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
7 use Drupal\Tests\UnitTestCase;
8 use Drupal\file\Plugin\migrate\cckfield\d7\FileField;
9 use Prophecy\Argument;
10
11 /**
12  * @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d7\FileField
13  * @group file
14  * @group legacy
15  */
16 class FileCckTest extends UnitTestCase {
17
18   /**
19    * @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
20    */
21   protected $plugin;
22
23   /**
24    * @var \Drupal\migrate\Plugin\MigrationInterface
25    */
26   protected $migration;
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     $this->plugin = new FileField([], 'file', []);
33
34     $migration = $this->prophesize(MigrationInterface::class);
35
36     // The plugin's processFieldValues() method will call
37     // mergeProcessOfProperty() and return nothing. So, in order to examine the
38     // process pipeline created by the plugin, we need to ensure that
39     // getProcess() always returns the last input to mergeProcessOfProperty().
40     $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
41       ->will(function ($arguments) use ($migration) {
42         $migration->getProcess()->willReturn($arguments[1]);
43       });
44     $this->migration = $migration->reveal();
45   }
46
47   /**
48    * @covers ::processCckFieldValues
49    */
50   public function testProcessCckFieldValues() {
51     $this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
52
53     $expected = [
54       'plugin' => 'sub_process',
55       'source' => 'somefieldname',
56       'process' => [
57         'target_id' => 'fid',
58         'display' => 'display',
59         'description' => 'description',
60       ],
61     ];
62     $this->assertSame($expected, $this->migration->getProcess());
63   }
64
65   /**
66    * Data provider for testGetFieldType().
67    */
68   public function getFieldTypeProvider() {
69     return [
70       ['image', 'imagefield_widget'],
71       ['file', 'filefield_widget'],
72       ['file', 'x_widget']
73     ];
74   }
75
76   /**
77    * @covers ::getFieldType
78    * @dataProvider getFieldTypeProvider
79    */
80   public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
81     $row = new Row();
82     $row->setSourceProperty('widget_type', $widget_type);
83     $row->setSourceProperty('global_settings', $settings);
84     $this->assertSame($expected_type, $this->plugin->getFieldType($row));
85   }
86
87 }