You are here

public function PackageTypeTest::testPackageTypeCreation in Commerce Shipping 8.2

Tests creating a package type.

File

tests/src/Functional/PackageTypeTest.php, line 34

Class

PackageTypeTest
Tests the package type UI.

Namespace

Drupal\Tests\commerce_shipping\Functional

Code

public function testPackageTypeCreation() {
  $this
    ->drupalGet('admin/commerce/config/package-types');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add package type');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/package-types/add');
  $edit = [
    'label' => 'Example',
    'dimensions[length]' => '20',
    'dimensions[width]' => '10',
    'dimensions[height]' => '10',
    'dimensions[unit]' => 'in',
    'weight[number]' => '10',
    'weight[unit]' => 'oz',
    // Setting the 'id' can fail if focus switches to another field.
    // This is a bug in the machine name JS that can be reproduced manually.
    'id' => 'example',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->addressEquals('admin/commerce/config/package-types');
  $this
    ->assertSession()
    ->responseContains('Example');
  $package_type = PackageType::load('example');
  $this
    ->assertEquals('example', $package_type
    ->id());
  $this
    ->assertEquals('Example', $package_type
    ->label());
  $this
    ->assertEquals('20', $package_type
    ->getDimensions()['length']);
  $this
    ->assertEquals('10', $package_type
    ->getDimensions()['width']);
  $this
    ->assertEquals('10', $package_type
    ->getDimensions()['height']);
  $this
    ->assertEquals('in', $package_type
    ->getDimensions()['unit']);
  $this
    ->assertEquals('10', $package_type
    ->getWeight()['number']);
  $this
    ->assertEquals('oz', $package_type
    ->getWeight()['unit']);
}