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