3cab3537089f8b58e24db98a073c0b439226c4bd
[yaffs-website] / web / core / modules / file / tests / src / Unit / Plugin / migrate / field / d7 / ImageFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Unit\Plugin\migrate\field\d7;
4
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\file\Plugin\migrate\field\d7\ImageField;
8 use Prophecy\Argument;
9
10 /**
11  * @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField
12  * @group file
13  */
14 class ImageFieldTest extends UnitTestCase {
15
16   /**
17    * @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
18    */
19   protected $plugin;
20
21   /**
22    * @var \Drupal\migrate\Plugin\MigrationInterface
23    */
24   protected $migration;
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     $this->plugin = new ImageField([], 'image', []);
31
32     $migration = $this->prophesize(MigrationInterface::class);
33
34     // The plugin's processFieldValues() method will call
35     // mergeProcessOfProperty() and return nothing. So, in order to examine the
36     // process pipeline created by the plugin, we need to ensure that
37     // getProcess() always returns the last input to mergeProcessOfProperty().
38     $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
39       ->will(function ($arguments) use ($migration) {
40         $migration->getProcess()->willReturn($arguments[1]);
41       });
42     $this->migration = $migration->reveal();
43   }
44
45   /**
46    * @covers ::processFieldValues
47    */
48   public function testProcessFieldValues() {
49     $this->plugin->processFieldValues($this->migration, 'somefieldname', []);
50
51     $expected = [
52       'plugin' => 'sub_process',
53       'source' => 'somefieldname',
54       'process' => [
55         'target_id' => 'fid',
56         'alt' => 'alt',
57         'title' => 'title',
58         'width' => 'width',
59         'height' => 'height',
60       ],
61     ];
62     $this->assertSame($expected, $this->migration->getProcess());
63   }
64
65 }