class CommercePriceTest in Commerce Migrate 3.1.x
Same name in this branch
- 3.1.x modules/magento/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_magento\Unit\Plugin\migrate\process\CommercePriceTest
- 3.1.x modules/csv_example/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process\CommercePriceTest
- 3.1.x modules/shopify/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_shopify\Unit\Plugin\migrate\process\CommercePriceTest
- 3.1.x modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/CommercePriceTest.php \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommercePriceTest
Same name and namespace in other branches
- 8.2 modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/CommercePriceTest.php \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommercePriceTest
- 3.0.x modules/commerce/tests/src/Unit/Plugin/migrate/process/commerce1/CommercePriceTest.php \Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1\CommercePriceTest
Tests the Commerce Price plugin.
@coversDefaultClass \Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\CommercePrice
@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\CommercePriceTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of CommercePriceTest
File
- modules/
commerce/ tests/ src/ Unit/ Plugin/ migrate/ process/ commerce1/ CommercePriceTest.php, line 16
Namespace
Drupal\Tests\commerce_migrate_commerce\Unit\Plugin\migrate\process\commerce1View source
class CommercePriceTest extends MigrateProcessTestCase {
/**
* Tests Commerce Price plugin.
*
* @dataProvider providerTestCommercePrice
*/
public function testCommercePrice($value = NULL, $expected = NULL) {
$configuration = [];
$this->plugin = new CommercePrice($configuration, 'map', []);
$value = $this->plugin
->transform($value, $this->migrateExecutable, $this->row, 'destinationproperty');
$this
->assertSame($expected, $value);
}
/**
* Data provider for testSubstr().
*/
public function providerTestCommercePrice() {
// Test the input amount > 0 with different fraction digits.
$tests[0]['value'] = [
'amount' => '234',
'currency_code' => 'NZD',
'fraction_digits' => 0,
];
$tests[0]['expected'] = [
'number' => '234',
'currency_code' => 'NZD',
];
$tests[1]['value'] = $tests[0]['value'];
$tests[1]['value']['fraction_digits'] = 1;
$tests[1]['expected'] = [
'number' => '23.4',
'currency_code' => 'NZD',
];
// Tests with fractional input.
$tests[2]['value'] = [
'amount' => '234.56',
'currency_code' => 'NZD',
'fraction_digits' => 0,
];
$tests[2]['expected'] = [
'number' => '234.56',
'currency_code' => 'NZD',
];
$tests[3]['value'] = [
'amount' => '234.56',
'currency_code' => 'NZD',
'fraction_digits' => 3,
];
$tests[3]['expected'] = [
'number' => '0.23456',
'currency_code' => 'NZD',
];
return $tests;
}
/**
* Tests that exception is thrown when input is not an array.
*
* @dataProvider providerTestNotArray
*/
public function testNotArray($value = NULL) {
$this
->expectException(MigrateSkipRowException::class);
$this
->expectExceptionMessage("CommercePrice input is not an array for destination 'new_value'");
$this->plugin = new CommercePrice([], 'test_format_date', []);
$this->plugin
->transform($value, $this->migrateExecutable, $this->row, 'new_value');
}
/**
* Data provider for testSubstr().
*/
public function providerTestNotArray() {
// Test input not an array.
$tests[0]['value'] = NULL;
$tests[1]['value'] = 'string';
$tests[2]['value'] = 1;
return $tests;
}
/**
* Tests that exception is thrown when input is not valid.
*
* @dataProvider providerTestInvalidValue
*/
public function testInvalidValue($value = NULL) {
$this
->expectException(MigrateSkipRowException::class);
$this
->expectExceptionMessage("CommercePrice input array is invalid for destination 'new_value'");
$this->plugin = new CommercePrice([], 'test_format_date', []);
$this->plugin
->transform($value, $this->migrateExecutable, $this->row, 'new_value');
}
/**
* Data provider for testSubstr().
*/
public function providerTestInvalidValue() {
// Missing fraction_digits key.
$tests[0]['value'] = [
'amount' => '234',
'currency_code' => 'NZD',
];
// Missing currency_code key.
$tests[1]['value'] = [
'amount' => '234',
'fraction_digits' => 0,
];
// Missing amount key.
$tests[2]['value'] = [
'currency_code' => 'NZD',
'fraction_digits' => 0,
];
// Invalid fraction_digits.
$tests[3]['value'] = [
'amount' => '234',
'currency_code' => 'NZD',
'fraction_digits' => -1,
];
$tests[4]['value'] = [];
return $tests;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommercePriceTest:: |
public | function | Data provider for testSubstr(). | |
CommercePriceTest:: |
public | function | Data provider for testSubstr(). | |
CommercePriceTest:: |
public | function | Data provider for testSubstr(). | |
CommercePriceTest:: |
public | function | Tests Commerce Price plugin. | |
CommercePriceTest:: |
public | function | Tests that exception is thrown when input is not valid. | |
CommercePriceTest:: |
public | function | Tests that exception is thrown when input is not an array. | |
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | property | ||
MigrateProcessTestCase:: |
protected | function |
Overrides UnitTestCase:: |
17 |
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 |