You are here

public function OffsiteOrderDataTest::testSave in Commerce Core 8.2

Tests the order data saving.

@dataProvider saveDataProvider

File

modules/payment/tests/src/FunctionalJavascript/OffsiteOrderDataTest.php, line 81

Class

OffsiteOrderDataTest
Tests saving order data before and after saving the payment.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

public function testSave($when_to_save) {
  $state = $this->container
    ->get('state');
  $state
    ->set('offsite_order_data_test_save', $when_to_save);
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('checkout/1');
  $this
    ->submitForm([
    'payment_information[billing_information][address][0][address][given_name]' => 'Johnny',
    'payment_information[billing_information][address][0][address][family_name]' => 'Appleseed',
    'payment_information[billing_information][address][0][address][address_line1]' => '123 New York Drive',
    'payment_information[billing_information][address][0][address][locality]' => 'New York City',
    'payment_information[billing_information][address][0][address][administrative_area]' => 'NY',
    'payment_information[billing_information][address][0][address][postal_code]' => '10001',
  ], 'Continue to review');
  $this
    ->assertSession()
    ->pageTextContains('Payment information');
  $this
    ->assertSession()
    ->pageTextContains('Example');
  $this
    ->assertSession()
    ->pageTextContains('Johnny Appleseed');
  $this
    ->assertSession()
    ->pageTextContains('123 New York Drive');
  $this
    ->submitForm([], 'Pay and complete purchase');
  $this
    ->assertSession()
    ->pageTextContains('Your order number is 1. You can view your order on your account page when logged in.');
  $order = Order::load(1);
  $this
    ->assertEquals('offsite', $order
    ->get('payment_gateway')->target_id);
  $this
    ->assertFalse($order
    ->isLocked());
  $this
    ->assertTrue($order
    ->isPaid());
  $this
    ->assertTrue($order
    ->getData('paid_event_dispatched'));

  // Confirm that gateway data was set and preserved.
  $this
    ->assertEquals($order
    ->getData('test_offsite'), [
    'test' => TRUE,
  ]);
}