You are here

public function DefaultPaymentAdminTest::testPaymentCapture in Commerce Core 8.2

Tests capturing a payment after creation.

File

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

Class

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

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testPaymentCapture() {
  $payment = $this
    ->createEntity('commerce_payment', [
    'payment_gateway' => $this->paymentGateway
      ->id(),
    'payment_method' => $this->paymentMethod
      ->id(),
    'order_id' => $this->order
      ->id(),
    'amount' => new Price('10', 'USD'),
  ]);
  $this->paymentGateway
    ->getPlugin()
    ->createPayment($payment, FALSE);
  $this
    ->drupalGet($this->paymentUri);
  $this
    ->assertSession()
    ->pageTextContains('Authorization');
  $this
    ->drupalGet($this->paymentUri . '/' . $payment
    ->id() . '/operation/capture');
  $this
    ->submitForm([
    'payment[amount][number]' => '10',
  ], 'Capture');
  \Drupal::entityTypeManager()
    ->getStorage('commerce_payment')
    ->resetCache([
    $payment
      ->id(),
  ]);
  $payment = Payment::load($payment
    ->id());
  $this
    ->assertSession()
    ->addressEquals($this->paymentUri);
  $this
    ->assertSession()
    ->pageTextNotContains('Authorization');
  $this
    ->assertSession()
    ->elementContains('css', 'table tbody tr td:nth-child(2)', 'Completed');
  $date_formatter = $this->container
    ->get('date.formatter');
  $this
    ->assertSession()
    ->elementContains('css', 'table tbody tr td:nth-child(5)', $date_formatter
    ->format($payment
    ->getCompletedTime(), 'short'));
  $this
    ->assertEquals($payment
    ->getState()
    ->getLabel(), 'Completed');
}