public function ProfileFieldCopyTest::testCheckoutWithMultipleGateways in Commerce Shipping 8.2
Tests checkout with multiple payment gateways.
File
- tests/
src/ FunctionalJavascript/ ProfileFieldCopyTest.php, line 654
Class
- ProfileFieldCopyTest
- Tests the "Shipping information" checkout pane.
Namespace
Drupal\Tests\commerce_shipping\FunctionalJavascriptCode
public function testCheckoutWithMultipleGateways() {
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $onsite_gateway */
$onsite_gateway = PaymentGateway::create([
'id' => 'onsite',
'label' => 'On-site',
'plugin' => 'example_onsite',
'configuration' => [
'api_key' => '2342fewfsfs',
'payment_method_types' => [
'credit_card',
],
],
]);
$onsite_gateway
->save();
$address_book_profile = $this
->createEntity('profile', [
'type' => 'customer',
'uid' => $this->adminUser
->id(),
'address' => $this->frenchAddress,
'is_default' => TRUE,
]);
$this
->drupalGet(Url::fromRoute('commerce_checkout.form', [
'commerce_order' => $this->order
->id(),
]));
$this
->assertSession()
->pageTextContains('Shipping information');
$this
->assertRenderedAddress($this->frenchAddress);
$this
->assertSession()
->pageTextContains('Payment information');
$this
->assertSession()
->checkboxChecked('payment_information[billing_information][copy_fields][enable]');
$this
->assertSession()
->fieldNotExists('payment_information[billing_information][address][0][address][address_line1]');
// Confirm that the copy_fields checkbox is still checked after selecting
// a different payment option ("Credit card", in this case).
$this
->getSession()
->getPage()
->selectFieldOption('payment_information[payment_method]', 'new--credit_card--onsite');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$billing_prefix = 'payment_information[add_payment_method][billing_information]';
$this
->assertSession()
->checkboxChecked($billing_prefix . '[copy_fields][enable]');
$billing_profile = $this->order
->getBillingProfile();
$this
->assertEmpty($billing_profile);
// Confirm that the shipping fields were copied on page submit.
$this
->submitForm([
'payment_information[add_payment_method][payment_details][security_code]' => '123',
], 'Continue to review');
$this->order = $this
->reloadEntity($this->order);
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $this->order
->get('payment_method')->entity;
$this
->assertNotEmpty($payment_method);
$payment_method_profile = $payment_method
->getBillingProfile();
$this
->assertNotEmpty($payment_method_profile);
$billing_profile = $this->order
->getBillingProfile();
$this
->assertNotEmpty($billing_profile);
$this
->assertTrue($payment_method_profile
->equalToProfile($billing_profile));
/** @var \Drupal\address\AddressInterface $address */
$address = $billing_profile
->get('address')
->first();
$this
->assertEquals($this->frenchAddress, array_filter($address
->toArray()));
$this
->assertNotEmpty($billing_profile
->getData('copy_fields'));
$this
->assertEmpty($billing_profile
->getData('copy_to_address_book'));
$this
->assertEquals($address_book_profile
->id(), $billing_profile
->getData('address_book_profile_id'));
}