class OrderItemAdjustmentTest in Commerce Migrate 3.1.x
Same name and namespace in other branches
- 8.2 modules/ubercart/tests/src/Unit/Plugin/migrate/process/OrderItemAdjustmentTest.php \Drupal\Tests\ubercart\Unit\Plugin\migrate\process\ubercart\OrderItemAdjustmentTest
- 3.0.x modules/ubercart/tests/src/Unit/Plugin/migrate/process/OrderItemAdjustmentTest.php \Drupal\Tests\ubercart\Unit\Plugin\migrate\process\ubercart\OrderItemAdjustmentTest
Tests order item adjustment process plugin.
@coversDefaultClass \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\OrderItemAdjustment
@group commerce_migrate_ubercart
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\ubercart\Unit\Plugin\migrate\process\ubercart\OrderItemAdjustmentTest
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of OrderItemAdjustmentTest
File
- modules/
ubercart/ tests/ src/ Unit/ Plugin/ migrate/ process/ OrderItemAdjustmentTest.php, line 21
Namespace
Drupal\Tests\ubercart\Unit\Plugin\migrate\process\ubercartView source
class OrderItemAdjustmentTest extends MigrateProcessTestCase {
/**
* The mocked migration.
*
* @var \Drupal\migrate\Plugin\MigrationInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $migration;
/**
* The mocked migration.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager|\Prophecy\Prophecy\ObjectProphecy
*/
protected $migrationPluginManager;
/**
* The mocked migration.
*
* @var \Drupal\core\Entity\EntityTypeManager|\Prophecy\Prophecy\ObjectProphecy
*/
protected $entityTypeManager;
/**
* The mocked migration.
*
* @var \Drupal\commerce_price\Rounder|\Prophecy\Prophecy\ObjectProphecy
*/
protected $rounder;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$this->migration = $this
->prophesize(Migration::class);
$this->migrationPluginManager = $this
->prophesize(MigrationPluginManager::class);
$this->entityTypeManager = $this
->prophesize(EntityTypeManager::class);
$this->rounder = $this
->prophesize(Rounder::class);
}
/**
* Tests valid input.
*
* @dataProvider providerTestTransform
*/
public function testTransform($value, $num_product_line, $last_line, $rounder_output, $order_product_id, $max_order_product_id, $split, $expected) {
$row = $this
->prophesize(Row::class);
$row
->getSourceProperty('num_product_line')
->willReturn($num_product_line);
$row
->getSourceProperty('order_product_id')
->willReturn($order_product_id);
$row
->getSourceProperty('max_order_product_id')
->willReturn($max_order_product_id);
$price = new Price((string) $value['amount'], $value['currency_code']);
$this->rounder
->round($price)
->willReturn($rounder_output);
$mock = $this
->getMockBuilder('\\Drupal\\Tests\\ubercart\\Unit\\Plugin\\migrate\\process\\ubercart\\TestOrderItemAdjustment')
->disableOriginalConstructor()
->setMethods([
'split',
])
->getMock();
$mock
->expects($this
->once())
->method('split')
->with($num_product_line, $last_line, $price)
->willReturn($split);
$mock
->setRounder($this->rounder
->reveal());
$result = $mock
->transform($value, $this->migrateExecutable, $row
->reveal(), 'foo');
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testTransform().
*/
public function providerTestTransform() {
return [
'one line item' => [
[
'line_item_id' => '6',
'order_id' => '2',
'type' => 'tax',
'title' => 'Handling',
'amount' => '60.00000',
'weight' => '9',
'data' => [
'tax_id' => '1',
'tax_rate' => '0.04',
'taxable_amount' => 1500.0,
'tax_jurisdiction' => 'Handling',
],
'currency_code' => 'NZD',
],
1,
TRUE,
new Price(60.0, 'NZD'),
2,
2,
new Price(60.0, 'NZD'),
[
'type' => 'tax',
'label' => 'Handling',
'amount' => '60',
'currency_code' => 'NZD',
'percentage' => '0.04',
'source_id' => 'custom',
'included' => FALSE,
'locked' => TRUE,
],
],
'first of 2 line items' => [
[
'line_item_id' => '5',
'order_id' => '1',
'type' => 'generic',
'title' => 'Service',
'amount' => '1.99000',
'weight' => '2',
'data' => NULL,
'currency_code' => 'NZD',
],
2,
FALSE,
new Price(1.99, 'NZD'),
3,
4,
new Price(0.99, 'NZD'),
[
'type' => 'tax',
'label' => 'Service',
'amount' => '0.99',
'currency_code' => 'NZD',
'percentage' => NULL,
'source_id' => 'custom',
'included' => FALSE,
'locked' => TRUE,
],
],
'second of 2 line items' => [
[
'line_item_id' => '99',
'order_id' => '1',
'type' => 'tax',
'title' => 'Handling',
'amount' => '1.40000',
'weight' => '9',
'data' => [
'tax_id' => '1',
'tax_rate' => '0.04',
'taxable_amount' => 35.0,
'tax_jurisdiction' => 'Handling',
],
'currency_code' => 'NZD',
],
2,
TRUE,
new Price(1.4, 'NZD'),
4,
4,
new Price(0.79, 'NZD'),
[
'type' => 'tax',
'label' => 'Handling',
'amount' => '0.79',
'currency_code' => 'NZD',
'percentage' => '0.04',
'source_id' => 'custom',
'included' => FALSE,
'locked' => TRUE,
],
],
'promotion' => [
[
'line_item_id' => '7',
'order_id' => '1',
'type' => 'coupon',
'title' => 'Handling',
'amount' => '1.40000',
'weight' => '9',
'data' => [],
'currency_code' => 'NZD',
],
2,
TRUE,
new Price(1.4, 'NZD'),
4,
4,
new Price(0.7, 'NZD'),
[
'type' => 'promotion',
'label' => 'Handling',
'amount' => '0.7',
'currency_code' => 'NZD',
'percentage' => NULL,
'source_id' => 'custom',
'included' => FALSE,
'locked' => TRUE,
],
],
'no product line' => [
[
'line_item_id' => '7',
'order_id' => '1',
'type' => 'tax',
'title' => 'Handling',
'amount' => '1.40000',
'weight' => '9',
'data' => [],
'currency_code' => 'NZD',
],
0,
TRUE,
new Price(1.4, 'NZD'),
4,
4,
NULL,
[],
],
];
}
/**
* Tests invalid input.
*
* @dataProvider providerTestTransformInvalid
*/
public function testTransformInvalid($value, $expected) {
$row = $this
->prophesize(Row::class);
$this->plugin = new OrderItemAdjustment([], 'map', [], $this->migration
->reveal(), $this->migrationPluginManager
->reveal(), $this->entityTypeManager
->reveal(), $this->rounder
->reveal());
$result = $this->plugin
->transform($value, $this->migrateExecutable, $row
->reveal(), 'foo');
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testTransformInvalid().
*/
public function providerTestTransformInvalid() {
return [
'not array' => [
'a string',
[],
],
];
}
/**
* Tests valid input.
*
* @dataProvider providerTestSplit
*/
public function testSplit($num_product_line, $last_line, $price, $split_rounder_input, $split_rounder_output, $expected) {
$this->rounder
->round($split_rounder_input, PHP_ROUND_HALF_DOWN)
->willReturn($split_rounder_output);
$configuration = [];
$this->plugin = new TestOrderItemAdjustment($configuration, 'map', [], $this->migration
->reveal(), $this->migrationPluginManager
->reveal(), $this->entityTypeManager
->reveal(), $this->rounder
->reveal());
$result = $this->plugin
->split($num_product_line, $last_line, $price);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testSplit().
*/
public function providerTestSplit() {
$zero_price = new Price(0, 'USD');
$ten_price = new Price(10.0, 'USD');
return [
'no product line' => [
0,
FALSE,
$zero_price,
$zero_price,
$zero_price,
NULL,
],
'one product line not last line' => [
1,
FALSE,
$ten_price,
$ten_price,
$ten_price,
$ten_price,
],
'one product line last line' => [
1,
TRUE,
$ten_price,
$ten_price,
$ten_price,
$ten_price,
],
'two product lines not last line' => [
2,
FALSE,
$ten_price,
new Price(5.0, 'USD'),
new Price(5.0, 'USD'),
new Price(5.0, 'USD'),
],
'two product lines last line' => [
2,
TRUE,
$ten_price,
new Price(5.0, 'USD'),
new Price(5.0, 'USD'),
new Price(5.0, 'USD'),
],
'three product lines not last line' => [
3,
FALSE,
new Price(10.0, 'USD'),
new Price(3.333333, 'USD'),
new Price(3.33, 'USD'),
new Price(3.33, 'USD'),
],
'three product lines last line' => [
3,
TRUE,
new Price(10.0, 'USD'),
new Price(3.333333, 'USD'),
new Price(3.33, 'USD'),
new Price(3.34, 'USD'),
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
OrderItemAdjustmentTest:: |
protected | property | The mocked migration. | |
OrderItemAdjustmentTest:: |
protected | property | The mocked migration. | |
OrderItemAdjustmentTest:: |
protected | property | The mocked migration. | |
OrderItemAdjustmentTest:: |
protected | property | The mocked migration. | |
OrderItemAdjustmentTest:: |
public | function | Data provider for testSplit(). | |
OrderItemAdjustmentTest:: |
public | function | Data provider for testTransform(). | |
OrderItemAdjustmentTest:: |
public | function | Data provider for testTransformInvalid(). | |
OrderItemAdjustmentTest:: |
public | function |
Overrides MigrateProcessTestCase:: |
|
OrderItemAdjustmentTest:: |
public | function | Tests valid input. | |
OrderItemAdjustmentTest:: |
public | function | Tests valid input. | |
OrderItemAdjustmentTest:: |
public | function | Tests invalid input. | |
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 |