You are here

public function ManualPaymentAdminTest::testPaymentVoid in Commerce Core 8.2

Tests voiding a pending payment.

File

modules/payment/tests/src/Functional/ManualPaymentAdminTest.php, line 184

Class

ManualPaymentAdminTest
Tests the admin UI for payments of type 'payment_manual'.

Namespace

Drupal\Tests\commerce_payment\Functional

Code

public function testPaymentVoid() {
  $payment = $this
    ->createEntity('commerce_payment', [
    'payment_gateway' => $this->paymentGateway
      ->id(),
    'order_id' => $this->order
      ->id(),
    'amount' => new Price('10', 'USD'),
  ]);
  $this->paymentGateway
    ->getPlugin()
    ->createPayment($payment);
  $this
    ->drupalGet($this->paymentUri . '/' . $payment
    ->id() . '/operation/void');
  $this
    ->assertSession()
    ->pageTextContains('Are you sure you want to void the 10 USD payment?');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Void');
  $this
    ->assertSession()
    ->addressEquals($this->paymentUri);
  $this
    ->assertSession()
    ->pageTextContains('Voided');
  \Drupal::entityTypeManager()
    ->getStorage('commerce_payment')
    ->resetCache([
    $payment
      ->id(),
  ]);
  $payment = Payment::load($payment
    ->id());
  $this
    ->assertEquals($payment
    ->getState()
    ->getLabel(), 'Voided');
}