View source
<?php
namespace Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
use Drupal\commerce_migrate_csv_example\Plugin\migrate\process\AttributeDestination;
use Drupal\migrate\MigrateException;
class AttributeDestinationTest extends MigrateProcessTestCase {
public function testAttributeDestination($value = NULL, $expected = NULL) {
$configuration = [];
$this->row = $this
->getMockBuilder('Drupal\\migrate\\Row')
->setMethods([
'get',
])
->disableOriginalConstructor()
->getMock();
$this->row
->expects($this
->once())
->method('get')
->with("attribute_{$value[0]}")
->willReturn($value[1]);
$this->plugin = new AttributeDestination($configuration, 'map', []);
$this->plugin
->transform($value, $this->migrateExecutable, $this->row, 'foo');
$property = $this->row
->get($expected[0]);
$this
->assertSame($expected[1], $property);
}
public function providerTestAttributeDestination() {
return [
'one' => [
[
'able',
'baker',
],
[
'attribute_able',
'baker',
],
],
];
}
public function testInvalidValue($value = NULL) {
$this
->expectException(MigrateException::class);
$this
->expectExceptionMessage("There must be an even number of input values.");
$this->plugin = new AttributeDestination([], 'test_format_date', []);
$this->plugin
->transform($value, $this->migrateExecutable, $this->row, 'foo');
}
public function providerTestInvalidValue() {
return [
'one argument' => [
[
'a',
],
],
'three arguments' => [
[
'a',
'b',
'c',
],
],
];
}
}