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