You are here

protected function EmailRegistrationLoginTest::setUp in Email Registration 8

Overrides CommerceBrowserTestBase::setUp

File

tests/src/Functional/Plugin/Commerce/CheckoutPane/EmailRegistrationLoginTest.php, line 38

Class

EmailRegistrationLoginTest
Tests the login checkout pane.

Namespace

Drupal\Tests\email_registration\Functional\Plugin\Commerce\CheckoutPane

Code

protected function setUp() {
  parent::setUp();

  // Place commerce blocks.
  $this
    ->placeBlock('commerce_cart');
  $this
    ->placeBlock('commerce_checkout_progress');

  // Create a product with variation.
  $variation = $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'sku' => strtolower($this
      ->randomMachineName()),
    'price' => [
      'number' => 9.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,
    ],
  ]);

  // Enable the email_registration_login pane and disable the default login
  // pane.

  /** @var \Drupal\commerce_checkout\Entity\CheckoutFlowInterface $checkout_flow */
  $checkout_flow = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_checkout_flow')
    ->load('default');

  /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface $checkout_flow_plugin */
  $checkout_flow_plugin = $checkout_flow
    ->getPlugin();

  /** @var \Drupal\email_registration\Plugin\Commerce\CheckoutPane\EmailRegistrationLogin $pane */
  $er_login_pane = $checkout_flow_plugin
    ->getPane('email_registration_login');
  $er_login_pane
    ->setConfiguration([]);
  $er_login_pane
    ->setStepId('login');

  /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\Login $pane */
  $login_pane = $checkout_flow_plugin
    ->getPane('login');
  $login_pane
    ->setStepId('_disabled');

  // Save pane settings.
  $checkout_flow_plugin_configuration = $checkout_flow_plugin
    ->getConfiguration();
  $checkout_flow_plugin_configuration['panes']['email_registration_login'] = $er_login_pane
    ->getConfiguration();
  $checkout_flow_plugin_configuration['panes']['login'] = $login_pane
    ->getConfiguration();
  $checkout_flow_plugin
    ->setConfiguration($checkout_flow_plugin_configuration);
  $checkout_flow
    ->save();
  $this
    ->drupalLogout();
  $this
    ->addProductToCart($this->product);
}