You are here

public function CheckoutPaneTest::testCheckoutPaneConfiguration in Commerce Checkout Order Fields 8

Tests the pane plugin.

@dataProvider dataCheckoutPaneConfiguration

File

tests/src/Kernel/CheckoutPaneTest.php, line 112

Class

CheckoutPaneTest
Tests the checkout pane.

Namespace

Drupal\Tests\commerce_checkout_order_fields\Kernel

Code

public function testCheckoutPaneConfiguration(array $pane_configuration, $test_string_value, array $expected) {
  $checkout_flow = CheckoutFlow::load('default');
  $configuration = $checkout_flow
    ->get('configuration');
  $configuration['panes']['order_fields:checkout'] = $pane_configuration;
  $checkout_flow
    ->set('configuration', $configuration);

  // Save so we can verify the config schema.
  $checkout_flow
    ->save();

  /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesInterface $plugin */
  $plugin = $checkout_flow
    ->getPlugin();
  $panes = $plugin
    ->getPanes();
  $this
    ->assertTrue(isset($panes['order_fields:checkout']));
  $pane = $panes['order_fields:checkout'];
  $order = Order::create([
    'type' => 'default',
    'store_id' => $this->store
      ->id(),
    'state' => 'draft',
    'mail' => 'text@example.com',
    'ip_address' => '127.0.0.1',
  ]);
  $order
    ->get('test_string_field')
    ->setValue($test_string_value);
  $pane
    ->setOrder($order);
  $this
    ->assertEquals($pane
    ->getStepId(), $expected[0]);
  $this
    ->assertEquals($expected[1], (string) $pane
    ->buildConfigurationSummary());
  $this
    ->assertEquals($expected[2], $pane
    ->getWrapperElement());
  $pane_summary = $pane
    ->buildPaneSummary();
  if (empty($test_string_value)) {
    $this
      ->assertEmpty($pane_summary, print_r($pane_summary, true));
  }
  else {
    $this
      ->render($pane_summary);
    $this
      ->assertText($test_string_value);
  }
}