class CommerceFieldNameTest in Commerce Migrate 3.1.x
Same name and namespace in other branches
- 8.2 modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/CommerceFieldNameTest.php \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommerceFieldNameTest
- 3.0.x modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/CommerceFieldNameTest.php \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommerceFieldNameTest
Tests the CommerceFieldName plugin.
@coversDefaultClass \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommerceFieldName
@group commerce_migrate_commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommerceFieldNameTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of CommerceFieldNameTest
File
- modules/
commerce/ tests/ src/ Unit/ Plugin/ migrate/ process/ commerce1/ CommerceFieldNameTest.php, line 15
Namespace
Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1View source
class CommerceFieldNameTest extends MigrateProcessTestCase {
/**
* Process plugin make_entity_unique.
*
* @var \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField
*/
protected $makeEntityUnique;
/**
* Process plugin manager.
*
* @var \Drupal\migrate\Plugin\MigratePluginManagerInterface
*/
protected $processPluginManager;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$migration_plugin_manager = $this
->getMockBuilder('Drupal\\migrate\\Plugin\\MigrationPluginManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->processPluginManager = $this
->getMockBuilder('Drupal\\migrate\\Plugin\\MigratePluginManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->makeEntityUnique = $this
->getMockBuilder('Drupal\\migrate\\Plugin\\migrate\\process\\MakeUniqueEntityField')
->disableOriginalConstructor()
->getMock();
$this->migrateExecutable = $this
->getMockBuilder('Drupal\\migrate\\MigrateExecutable')
->disableOriginalConstructor()
->getMock();
$this->plugin = new CommerceFieldName([], 'test', [], $migration_plugin_manager, $this->processPluginManager);
}
/**
* Tests CommerceFieldName plugin for an attribute.
*
* @dataProvider providerCommerceFieldName
*/
public function testCommerceFieldName($destination_property = NULL, $source_properties = NULL, $expected = NULL) {
$this->makeEntityUnique
->expects($this
->once())
->method('transform')
->willReturn('color');
$this->processPluginManager
->method('createInstance')
->willReturn($this->makeEntityUnique);
$this->row
->expects($this
->any())
->method('getDestinationProperty')
->willReturn($destination_property);
$this->row
->method('getSourceProperty')
->will($this
->onConsecutiveCalls($source_properties[0], $source_properties[1], $source_properties[2], $source_properties[3]));
$value = $this->plugin
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $value);
}
/**
* Data provider for testCommerceFieldName().
*/
public function providerCommerceFieldName() {
// Tests attribute field name is stripped of leading 'field_'.
$tests[0]['destination_property'] = NULL;
$field_name = 'field_color';
$entity_type = 'commerce_product';
$type = 'taxonomy_term_reference';
$instances = [
[
'data' => serialize([
'widget' => [
'type' => 'options_select',
],
]),
],
[
'data' => serialize([
'widget' => [
'type' => 'text',
],
]),
],
];
$tests[0]['source_properties'] = [
$field_name,
$entity_type,
$type,
$instances,
];
$tests[0]['expected'] = 'color';
return $tests;
}
/**
* Tests CommerceFieldName plugin for address field input.
*
* @dataProvider providerCommerceFieldNameAddress
*/
public function testCommerceFieldNameAddress($source_properties = NULL, $expected = NULL) {
$this->makeEntityUnique
->expects($this
->never())
->method('transform');
$this->row
->expects($this
->never())
->method('getDestinationProperty');
// Put the input values onto the Row.
$this->row
->method('getSourceProperty')
->will($this
->onConsecutiveCalls($source_properties[0], $source_properties[1], $source_properties[2], $source_properties[3]));
$value = $this->plugin
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $value);
}
/**
* Data provider for testCommerceFieldNameAddress().
*/
public function providerCommerceFieldNameAddress() {
$tests = [];
// Tests address field name is changed.
$field_name = 'color';
$entity_type = 'commerce_customer_profile';
$type = 'addressfield';
$instances = [
[
'data' => serialize([
'widget' => [
'type' => 'options_select',
],
]),
],
[
'data' => serialize([
'widget' => [
'type' => 'text',
],
]),
],
];
$tests[0]['source_properties'] = [
$field_name,
$entity_type,
$type,
$instances,
];
$tests[0]['expected'] = 'address';
// Tests address field name not on commerce_customer_profile is not changed.
$field_name = 'field_address';
$entity_type = 'node';
$type = 'addressfield';
$instances = [
[
'data' => serialize([
'widget' => [
'type' => 'options_select',
],
]),
],
[
'data' => serialize([
'widget' => [
'type' => 'text',
],
]),
],
];
$tests[1]['source_properties'] = [
$field_name,
$entity_type,
$type,
$instances,
];
$tests[1]['expected'] = 'field_address';
// Tests the field name for field that is not an address is not changed.
$field_name = 'field_text';
$entity_type = 'node';
$type = 'text';
$instances = [
[
'data' => serialize([
'widget' => [
'type' => 'options_select',
],
]),
],
[
'data' => serialize([
'widget' => [
'type' => 'text',
],
]),
],
];
$tests[1]['source_properties'] = [
$field_name,
$entity_type,
$type,
$instances,
];
$tests[1]['expected'] = 'field_text';
return $tests;
}
/**
* Tests CommerceFieldName plugin for other entity types.
*
* @dataProvider providerCommerceFieldNameOther
*/
public function testCommerceFieldNameOther($source_properties = NULL, $expected = NULL) {
$this->makeEntityUnique
->expects($this
->never())
->method('transform');
$this->row
->expects($this
->never())
->method('getDestinationProperty');
$this->row
->method('getSourceProperty')
->will($this
->onConsecutiveCalls($source_properties[0], $source_properties[1], $source_properties[2], $source_properties[3]));
$value = $this->plugin
->transform('', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame($expected, $value);
}
/**
* Data provider for testCommerceFieldNameOther().
*/
public function providerCommerceFieldNameOther() {
$tests = [];
// Tests address field name is changed.
$field_name = 'field_image';
$entity_type = 'node';
$type = 'text';
$instances = [
[
'data' => serialize([
'widget' => [
'type' => 'options_select',
],
]),
],
[
'data' => serialize([
'widget' => [
'type' => 'text',
],
]),
],
];
$tests[0]['source_properties'] = [
$field_name,
$entity_type,
$type,
$instances,
];
$tests[0]['expected'] = 'field_image';
return $tests;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceFieldNameTest:: |
protected | property | Process plugin make_entity_unique. | |
CommerceFieldNameTest:: |
protected | property | Process plugin manager. | |
CommerceFieldNameTest:: |
public | function | Data provider for testCommerceFieldName(). | |
CommerceFieldNameTest:: |
public | function | Data provider for testCommerceFieldNameAddress(). | |
CommerceFieldNameTest:: |
public | function | Data provider for testCommerceFieldNameOther(). | |
CommerceFieldNameTest:: |
protected | function |
Overrides MigrateProcessTestCase:: |
|
CommerceFieldNameTest:: |
public | function | Tests CommerceFieldName plugin for an attribute. | |
CommerceFieldNameTest:: |
public | function | Tests CommerceFieldName plugin for address field input. | |
CommerceFieldNameTest:: |
public | function | Tests CommerceFieldName plugin for other entity types. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | An array of migration configuration values. | 7 |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |