StandaloneTest.php in Commerce Recurring Framework 8
File
tests/src/Kernel/Plugin/Commerce/SubscriptionType/StandaloneTest.php
View source
<?php
namespace Drupal\Tests\commerce_recurring\Kernel\Plugin\Commerce\SubscriptionType;
use Drupal\commerce_price\Price;
use Drupal\commerce_recurring\BillingPeriod;
use Drupal\commerce_recurring\Charge;
use Drupal\commerce_recurring\Entity\Subscription;
use Drupal\Tests\commerce_recurring\Kernel\RecurringKernelTestBase;
class StandaloneTest extends RecurringKernelTestBase {
public function testGetters() {
$plugin_manager = $this->container
->get('plugin.manager.commerce_subscription_type');
$plugin = $plugin_manager
->createInstance('standalone');
$this
->assertEquals('Standalone', $plugin
->getLabel());
$this
->assertNull($plugin
->getPurchasableEntityTypeId());
}
public function testCharges() {
$subscription = Subscription::create([
'type' => 'standalone',
'store_id' => $this->store
->id(),
'billing_schedule' => $this->billingSchedule,
'uid' => $this->user,
'title' => 'My donation',
'quantity' => 1,
'unit_price' => new Price('19', 'USD'),
'starts' => strtotime('2019-02-24 17:00:00'),
]);
$subscription
->save();
$start_date = $subscription
->getStartDate();
$billing_period = $this->billingSchedule
->getPlugin()
->generateFirstBillingPeriod($start_date);
$expected_billing_period = new BillingPeriod($subscription
->getStartDate(), $billing_period
->getEndDate());
$charges = $subscription
->getType()
->collectCharges($subscription, $billing_period);
$this
->assertCount(1, $charges);
$base_charge = reset($charges);
$this
->assertInstanceOf(Charge::class, $base_charge);
$this
->assertNull($base_charge
->getPurchasedEntity());
$this
->assertEquals($subscription
->getTitle(), $base_charge
->getTitle());
$this
->assertEquals($subscription
->getQuantity(), $base_charge
->getQuantity());
$this
->assertEquals($subscription
->getUnitPrice(), $base_charge
->getUnitPrice());
$this
->assertEquals($expected_billing_period, $base_charge
->getBillingPeriod());
}
}