class CommercePriceTest in Commerce Migrate 8.2
Same name in this branch
- 8.2 modules/magento/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_magento\Unit\Plugin\migrate\process\CommercePriceTest
- 8.2 modules/csv_example/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_csv_example\Unit\Plugin\migrate\process\CommercePriceTest
- 8.2 modules/shopify/tests/src/Unit/Plugin/migrate/process/CommercePriceTest.php \Drupal\Tests\commerce_migrate_shopify\Unit\Plugin\migrate\process\CommercePriceTest
- 8.2 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
- 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
- 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 PhpunitCompatibilityTrait
- 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:: |
19 |
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | An array of migration configuration values. | 16 |
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. | 1 |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | 1 |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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. |