OrderRefreshTest.php in Commerce Recurring Framework 8
File
tests/src/Kernel/OrderRefreshTest.php
View source
<?php
namespace Drupal\Tests\commerce_recurring\Kernel;
use Drupal\commerce_price\Price;
use Drupal\commerce_recurring\Entity\BillingScheduleInterface;
use Drupal\commerce_recurring\Entity\Subscription;
class OrderRefreshTest extends RecurringKernelTestBase {
protected $recurringOrderManager;
protected function setUp() : void {
parent::setUp();
$this->recurringOrderManager = $this->container
->get('commerce_recurring.order_manager');
}
public function testRefresh() {
$subscription = Subscription::create([
'type' => 'product_variation',
'store_id' => $this->store
->id(),
'billing_schedule' => $this->billingSchedule,
'uid' => $this->user,
'payment_method' => $this->paymentMethod,
'purchased_entity' => $this->variation,
'title' => $this->variation
->getOrderItemTitle(),
'unit_price' => new Price('2', 'USD'),
'state' => 'active',
'starts' => strtotime('2019-02-01 00:00'),
]);
$subscription
->save();
$order = $this->recurringOrderManager
->startRecurring($subscription);
$this
->assertEquals(new Price('2', 'USD'), $order
->getTotalPrice());
$subscription
->setUnitPrice(new Price('3', 'USD'));
$subscription
->save();
$order
->save();
$this
->assertEquals(new Price('3', 'USD'), $order
->getTotalPrice());
$this->billingSchedule
->setBillingType(BillingScheduleInterface::BILLING_TYPE_PREPAID);
$this->billingSchedule
->save();
$subscription
->cancel()
->save();
$order
->save();
$this
->assertEquals('canceled', $order
->getState()
->getId());
$this
->assertEmpty($order
->getItems());
}
}