You are here

protected function PaymentCheckoutTest::setUp in Commerce Core 8.2

Overrides CommerceWebDriverTestBase::setUp

File

modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php, line 96

Class

PaymentCheckoutTest
Tests the integration between payments and checkout.

Namespace

Drupal\Tests\commerce_payment\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  $this->store
    ->set('billing_countries', [
    'FR',
    'US',
  ]);
  $this->store
    ->save();
  $variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => '39.99',
      'currency_code' => 'USD',
    ],
  ]);

  /** @var \Drupal\commerce_product\Entity\ProductInterface $product */
  $this->product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => 'My product',
    'variations' => [
      $variation,
    ],
    'stores' => [
      $this->store,
    ],
  ]);

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $skipped_gateway */
  $skipped_gateway = PaymentGateway::create([
    'id' => 'onsite_skipped',
    'label' => 'On-site Skipped',
    'plugin' => 'example_onsite',
    'configuration' => [
      'api_key' => '2342fewfsfs',
      'payment_method_types' => [
        'credit_card',
      ],
    ],
    'conditions' => [
      [
        'plugin' => 'order_total_price',
        'configuration' => [
          'operator' => '<',
          'amount' => [
            'number' => '1.00',
            'currency_code' => 'USD',
          ],
        ],
      ],
    ],
  ]);
  $skipped_gateway
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'onsite',
    'label' => 'On-site',
    'plugin' => 'example_onsite',
    'configuration' => [
      'api_key' => '2342fewfsfs',
      'payment_method_types' => [
        'credit_card',
      ],
    ],
  ]);
  $payment_gateway
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'offsite',
    'label' => 'Off-site',
    'plugin' => 'example_offsite_redirect',
    'configuration' => [
      'redirect_method' => 'post',
      'payment_method_types' => [
        'credit_card',
      ],
    ],
  ]);
  $payment_gateway
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'stored_offsite',
    'label' => 'Stored off-site',
    'plugin' => 'example_stored_offsite_redirect',
    'configuration' => [
      'redirect_method' => 'post',
      'payment_method_types' => [
        'credit_card',
      ],
    ],
  ]);
  $payment_gateway
    ->save();

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
  $payment_gateway = PaymentGateway::create([
    'id' => 'manual',
    'label' => 'Manual',
    'plugin' => 'manual',
    'configuration' => [
      'display_label' => 'Cash on delivery',
      'instructions' => [
        'value' => 'Sample payment instructions.',
        'format' => 'plain_text',
      ],
    ],
  ]);
  $payment_gateway
    ->save();
  $this->defaultProfile = $this
    ->createEntity('profile', [
    'type' => 'customer',
    'uid' => $this->adminUser
      ->id(),
    'address' => $this->defaultAddress,
  ]);
  $profile = $this
    ->createEntity('profile', [
    'type' => 'customer',
    'uid' => 0,
    'address' => [
      'country_code' => 'US',
      'postal_code' => '53177',
      'locality' => 'Milwaukee',
      'address_line1' => 'Pabst Blue Ribbon Dr',
      'administrative_area' => 'WI',
      'given_name' => 'Frederick',
      'family_name' => 'Pabst',
    ],
  ]);
  $payment_method = $this
    ->createEntity('commerce_payment_method', [
    'uid' => $this->adminUser
      ->id(),
    'type' => 'credit_card',
    'payment_gateway' => 'onsite',
    'card_type' => 'visa',
    'card_number' => '1111',
    'billing_profile' => $profile,
    'reusable' => TRUE,
    'expires' => strtotime('2028/03/24'),
  ]);
  $payment_method
    ->setBillingProfile($profile);
  $payment_method
    ->save();
  $this->orderPaymentMethod = $this
    ->createEntity('commerce_payment_method', [
    'type' => 'credit_card',
    'payment_gateway' => 'onsite',
    'card_type' => 'visa',
    'card_number' => '9999',
    'reusable' => FALSE,
  ]);
  $this->user = $this
    ->createUser([
    'view commerce_product',
    'access checkout',
  ]);
}