You are here

public function ShippingMethodTest::testShippingMethodCreation in Commerce Shipping 8.2

Tests creating a shipping method.

File

tests/src/FunctionalJavascript/ShippingMethodTest.php, line 35

Class

ShippingMethodTest
Tests the shipping method UI.

Namespace

Drupal\Tests\commerce_shipping\FunctionalJavascript

Code

public function testShippingMethodCreation() {
  $this
    ->drupalGet('admin/commerce/shipping-methods');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add shipping method');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/shipping-methods/add');
  $this
    ->assertSession()
    ->fieldExists('name[0][value]');
  $this
    ->getSession()
    ->getPage()
    ->fillField('plugin[0][target_plugin_id]', 'flat_rate');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $name = $this
    ->randomMachineName(8);
  $edit = [
    'name[0][value]' => $name,
    'plugin[0][target_plugin_configuration][flat_rate][rate_label]' => 'Test label',
    'plugin[0][target_plugin_configuration][flat_rate][rate_amount][number]' => '10.00',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/shipping-methods');
  $this
    ->assertSession()
    ->pageTextContains("Saved the {$name} shipping method.");
  $shipping_method = ShippingMethod::load(1);
  $plugin = $shipping_method
    ->getPlugin();
  $this
    ->assertEquals([
    'number' => '10.00',
    'currency_code' => 'USD',
  ], $plugin
    ->getConfiguration()['rate_amount']);
  $this
    ->assertEquals('shipment_default', $plugin
    ->getConfiguration()['workflow']);
}