You are here

public function DemoImageTest::testTransformSuccess in Panopoly 8.2

Tests a successful call to transform().

@covers ::transform

File

modules/panopoly/panopoly_core/tests/src/Unit/Plugin/migrate/process/DemoImageTest.php, line 129

Class

DemoImageTest
Tests for the 'panopoly_demo_image' migrate process plugin.

Namespace

Drupal\Tests\panopoly_core\Unit\Plugin\migrate\process

Code

public function testTransformSuccess() {
  $image = $this
    ->prophesize(ImageInterface::class);
  $image
    ->getWidth()
    ->willReturn(300);
  $image
    ->getHeight()
    ->willReturn(200);
  $this->imageFactory
    ->get('public://demo_images/image.jpg')
    ->willReturn($image);
  $executable = $this
    ->prophesize(MigrateExecutableInterface::class);
  $row = $this
    ->prophesize(Row::class);
  $row
    ->getSourceProperty('image_filename')
    ->willReturn('image.jpg');
  $plugin = $this
    ->createPlugin([
    'filename_property' => 'image_filename',
  ], [
    'getSourcePath',
    'getDestinationPath',
    'checkFile',
    'findOrCreateFile',
    'getOptionalProperty',
  ]);
  $plugin
    ->method('getSourcePath')
    ->willReturn('modules/demo_module/images');
  $plugin
    ->method('getDestinationPath')
    ->willReturn('public://demo_images');
  $plugin
    ->method('checkFile')
    ->willReturn(TRUE);
  $file = $this
    ->prophesize(File::class);
  $file
    ->id()
    ->willReturn(32);
  $plugin
    ->method('findOrCreateFile')
    ->with('modules/demo_module/images/image.jpg', 'public://demo_images/image.jpg')
    ->willReturn($file
    ->reveal());
  $plugin
    ->expects($this
    ->exactly(3))
    ->method('getOptionalProperty')
    ->willReturnMap([
    [
      'description_property',
      $row
        ->reveal(),
      NULL,
    ],
    [
      'alt_property',
      $row
        ->reveal(),
      'This is the alternative text',
    ],
    [
      'title',
      $row
        ->reveal(),
      '',
    ],
  ]);
  $result = $plugin
    ->transform(NULL, $executable
    ->reveal(), $row
    ->reveal(), 'field_image');
  $this
    ->assertEquals([
    'target_id' => 32,
    'display' => 1,
    'description' => '',
    'alt' => 'This is the alternative text',
    'title' => '',
    'width' => 300,
    'height' => 200,
  ], $result);
}