You are here

public function CashOnDeliveryTest::testCashOnDelivery in Ubercart 8.4

Tests for CashOnDelivery payment method.

File

payment/uc_payment_pack/tests/src/Functional/CashOnDeliveryTest.php, line 17

Class

CashOnDeliveryTest
Tests the payment method pack CashOnDelivery payment method.

Namespace

Drupal\Tests\uc_payment_pack\Functional

Code

public function testCashOnDelivery() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet('admin/store/config/payment/add/cod');

  // Verify that default COD policy is found.
  $assert
    ->fieldValueEquals('settings[policy]', 'Full payment is expected upon delivery or prior to pick-up.');
  $cod = $this
    ->createPaymentMethod('cod', [
    'settings[policy]' => $this
      ->randomString(),
  ]);

  // @todo Test enabling delivery date on settings page.
  // Test checkout page.
  $this
    ->drupalGet('cart/checkout');

  // Verify that COD payment method is selected at checkout.
  $assert
    ->fieldValueEquals('panes[payment][payment_method]', $cod['id']);
  $assert
    ->assertEscaped($cod['settings[policy]'], 'COD policy found at checkout.');

  // Test review order page.
  $this
    ->submitForm([], 'Review order');

  // Check that COD payment method was found on the review order page.
  $assert
    ->pageTextContains('Cash on delivery');
  $this
    ->submitForm([], 'Submit order');

  // Test user order view.
  $order = Order::load(1);
  $this
    ->assertEquals($cod['id'], $order
    ->getPaymentMethodId(), 'Order has COD payment method.');
  $this
    ->drupalGet('user/' . $order
    ->getOwnerId() . '/orders/' . $order
    ->id());

  // Check that COD payment method is displayed on user orders page.
  $assert
    ->pageTextContains('Method: Cash on delivery');

  // Test admin order view.
  $this
    ->drupalGet('admin/store/orders/' . $order
    ->id());

  // Check that COD payment method is displayed on admin orders page.
  $assert
    ->pageTextContains('Method: Cash on delivery');
}