public function SubscriptionTest::testSubscriptionPaymentMethodEditing in Commerce Recurring Framework 8
Tests editing the payment method of a subscription.
File
- tests/
src/ Functional/ SubscriptionTest.php, line 247
Class
- SubscriptionTest
- Tests the subscription UI.
Namespace
Drupal\Tests\commerce_recurring\FunctionalCode
public function testSubscriptionPaymentMethodEditing() {
/** @var \Drupal\commerce_recurring\Entity\SubscriptionInterface $subscription */
$subscription = $this
->createEntity('commerce_subscription', [
'title' => $this
->randomString(),
'uid' => $this->adminUser
->id(),
'billing_schedule' => $this->billingSchedule,
'payment_method' => $this->paymentMethod,
'type' => 'product_variation',
'purchased_entity' => $this->variation,
'store_id' => $this->store
->id(),
'unit_price' => $this->variation
->getPrice(),
'starts' => time() + 3600,
'state' => 'active',
]);
// Create an additional payment method for the subscription owner, as well
// as another one for a different user.
$payment_method_2 = PaymentMethod::create([
'type' => 'credit_card',
'payment_gateway' => $this->paymentGateway,
'card_type' => 'visa',
'card_number' => 2,
'uid' => $this->adminUser
->id(),
'billing_profile' => $this->billingProfile,
]);
$payment_method_2
->save();
$another_user = $this
->drupalCreateUser();
$payment_method_3 = PaymentMethod::create([
'type' => 'credit_card',
'payment_gateway' => $this->paymentGateway,
'card_type' => 'visa',
'card_number' => 3,
'uid' => $another_user
->id(),
'billing_profile' => $this->billingProfile,
]);
$payment_method_3
->save();
$this->container
->get('entity_type.manager')
->getStorage('commerce_payment_method')
->resetCache();
$this
->drupalGet('admin/commerce/subscriptions/' . $subscription
->id() . '/edit');
$this
->assertSession()
->pageTextContains('Visa ending in 1');
$this
->assertSession()
->pageTextContains('Visa ending in 2');
$this
->assertSession()
->pageTextNotContains('Visa ending in 3');
$values = [
'payment_method[target_id]' => 2,
];
$this
->submitForm($values, 'Save');
$subscription = $this
->reloadEntity($subscription);
$this
->assertEquals($payment_method_2
->id(), $subscription
->getPaymentMethodId());
}