176657ff2733365d8be9099ece2a216b742bc0af
[yaffs-website] / web / core / modules / file / tests / src / Unit / Plugin / migrate / field / d6 / FileFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d6;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
7 use Drupal\Tests\UnitTestCase;
8 use Drupal\file\Plugin\migrate\field\d6\FileField;
9 use Prophecy\Argument;
10
11 /**
12  * @coversDefaultClass \Drupal\file\Plugin\migrate\field\d6\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' => 'd6_field_file',
54       'source' => 'somefieldname',
55     ];
56     $this->assertSame($expected, $this->migration->getProcess());
57   }
58
59   /**
60    * Data provider for testGetFieldType().
61    */
62   public function getFieldTypeProvider() {
63     return [
64       ['image', 'imagefield_widget'],
65       ['file', 'filefield_widget'],
66       ['file', 'x_widget'],
67     ];
68   }
69
70   /**
71    * @covers ::getFieldType
72    * @dataProvider getFieldTypeProvider
73    */
74   public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
75     $row = new Row();
76     $row->setSourceProperty('widget_type', $widget_type);
77     $row->setSourceProperty('global_settings', $settings);
78     $this->assertSame($expected_type, $this->plugin->getFieldType($row));
79   }
80
81 }