3 namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d6;
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;
12 * @coversDefaultClass \Drupal\file\Plugin\migrate\field\d6\FileField
15 class FileFieldTest extends UnitTestCase {
18 * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
23 * @var \Drupal\migrate\Plugin\MigrationInterface
30 protected function setUp() {
31 $this->plugin = new FileField([], 'file', []);
33 $migration = $this->prophesize(MigrationInterface::class);
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]);
43 $this->migration = $migration->reveal();
47 * @covers ::defineValueProcessPipeline
49 public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
50 $this->plugin->$method($this->migration, 'somefieldname', []);
53 'plugin' => 'd6_field_file',
54 'source' => 'somefieldname',
56 $this->assertSame($expected, $this->migration->getProcess());
60 * Data provider for testGetFieldType().
62 public function getFieldTypeProvider() {
64 ['image', 'imagefield_widget'],
65 ['file', 'filefield_widget'],
71 * @covers ::getFieldType
72 * @dataProvider getFieldTypeProvider
74 public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
76 $row->setSourceProperty('widget_type', $widget_type);
77 $row->setSourceProperty('global_settings', $settings);
78 $this->assertSame($expected_type, $this->plugin->getFieldType($row));