You are here

public function ProportionalTest::testProrating in Commerce Recurring Framework 8

@covers ::prorateOrderItem @dataProvider testProratingProvider

File

tests/src/Kernel/Plugin/Commerce/Prorater/ProportionalTest.php, line 39

Class

ProportionalTest
Tests the proportional prorater.

Namespace

Drupal\Tests\commerce_recurring\Kernel\Plugin\Commerce\Prorater

Code

public function testProrating($expected_price, $billing_period_start_time) {

  /** @var \Drupal\commerce_recurring\Plugin\Commerce\Prorater\ProraterInterface $plugin */
  $plugin = $this->proraterManager
    ->createInstance('proportional');
  $order_item = OrderItem::create([
    'type' => 'default',
    'title' => $this->variation
      ->getOrderItemTitle(),
    'purchased_entity' => $this->variation
      ->id(),
    'unit_price' => new Price('30', 'USD'),
  ]);
  $order_item
    ->save();
  $billing_period = new BillingPeriod(new DrupalDateTime($billing_period_start_time), new DrupalDateTime('2019-06-01 18:00:00'));
  $full_billing_period = new BillingPeriod(new DrupalDateTime('2019-06-01 17:00:00'), new DrupalDateTime('2019-06-01 18:00:00'));
  $prorated_unit_price = $plugin
    ->prorateOrderItem($order_item, $billing_period, $full_billing_period);
  $this
    ->assertEquals($expected_price, $prorated_unit_price);
}