You are here

public function DefaultPaymentAdminTest::testPaymentCreation in Commerce Core 8.2

Tests creating a payment for an order.

File

modules/payment/tests/src/Functional/DefaultPaymentAdminTest.php, line 162

Class

DefaultPaymentAdminTest
Tests the admin UI for payments of type 'payment_default'.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testPaymentCreation() {
  $this
    ->drupalGet($this->paymentUri);
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add payment');
  $this
    ->assertSession()
    ->addressEquals($this->paymentUri . '/add');
  $this
    ->assertSession()
    ->pageTextContains('Visa ending in 1111');
  $this
    ->assertSession()
    ->checkboxChecked('payment_option');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Continue');
  $this
    ->submitForm([
    'payment[amount][number]' => '100',
  ], 'Add payment');
  $this
    ->assertSession()
    ->addressEquals($this->paymentUri);
  $this
    ->assertSession()
    ->elementContains('css', 'table tbody tr td:nth-child(2)', 'Completed');
  \Drupal::entityTypeManager()
    ->getStorage('commerce_payment')
    ->resetCache([
    1,
  ]);

  /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
  $payment = Payment::load(1);
  $this
    ->assertEquals($this->order
    ->id(), $payment
    ->getOrderId());
  $this
    ->assertEquals('100.00', $payment
    ->getAmount()
    ->getNumber());
  $this
    ->assertNotEmpty($payment
    ->getCompletedTime());
  $this
    ->assertEquals('A', $payment
    ->getAvsResponseCode());
  $this
    ->assertEquals('Address', $payment
    ->getAvsResponseCodeLabel());
}