You are here

CashOnDeliveryTest.php in Ubercart 8.4

File

payment/uc_payment_pack/tests/src/Functional/CashOnDeliveryTest.php
View source
<?php

namespace Drupal\Tests\uc_payment_pack\Functional;

use Drupal\uc_order\Entity\Order;

/**
 * Tests the payment method pack CashOnDelivery payment method.
 *
 * @group ubercart
 */
class CashOnDeliveryTest extends PaymentPackTestBase {

  /**
   * Tests for CashOnDelivery payment method.
   */
  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');
  }

}

Classes

Namesort descending Description
CashOnDeliveryTest Tests the payment method pack CashOnDelivery payment method.