View source
<?php
namespace Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
use Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommerceAttributeHandlerSetting;
use Drupal\migrate\MigrateSkipProcessException;
class CommerceAttributeHandlerSettingTest extends MigrateProcessTestCase {
protected function setUp() : void {
parent::setUp();
$this->plugin = new CommerceAttributeHandlerSetting([], 'test', []);
}
public function testCommerceAttributeTargetType($src = NULL, $dst = NULL, $expected = NULL) {
$this->row
->expects($this
->once())
->method('getDestinationProperty')
->willReturn($dst);
$this->row
->method('getSourceProperty')
->will($this
->onConsecutiveCalls($src[0], $src[1], $src[2], $src[3]));
$configuration = [];
$this->plugin = new CommerceAttributeHandlerSetting($configuration, 'map', []);
$value = $this->plugin
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $value);
}
public function providerTestCommerceAttributeTargetType() {
$tests = [
[
[
'commerce_product',
'taxonomy_term_reference',
[
'type' => 'options_select',
],
'product',
],
[
'settings',
],
[
'target_bundles' => [
'product',
],
],
],
];
return $tests;
}
public function testException($src = NULL) {
$this->row
->method('getSourceProperty')
->will($this
->onConsecutiveCalls($src[0], $src[1], $src[2], $src[3]));
$this
->expectException(MigrateSkipProcessException::class);
$this->plugin
->transform([], $this->migrateExecutable, $this->row, 'property');
}
public function providerTestException() {
$tests = [];
$tests = [
[
'node',
'taxonomy_term_reference',
[
'type' => 'options_select',
],
[],
],
[
'commerce_product',
'file',
[
'type' => 'options_select',
],
[],
],
[
'commerce_product',
'taxonomy_term_reference',
[
'type' => 'text',
],
[],
],
[
NULL,
NULL,
NULL,
NULL,
],
];
return $tests;
}
}