You are here

public function DimensionsElementTest::testSingleUnit in Physical Fields 8

Tests the element with a single unit.

File

tests/src/Functional/DimensionsElementTest.php, line 33

Class

DimensionsElementTest
Tests the physical_dimensions form element.

Namespace

Drupal\Tests\physical\Functional

Code

public function testSingleUnit() {
  $this
    ->drupalGet('/physical/dimensions_test_form/TRUE');
  $this
    ->assertSession()
    ->fieldExists('dimensions[length]');
  $this
    ->assertSession()
    ->fieldExists('dimensions[width]');
  $this
    ->assertSession()
    ->fieldExists('dimensions[height]');

  // Default value.
  $this
    ->assertSession()
    ->fieldValueEquals('dimensions[length]', '1.92');
  $this
    ->assertSession()
    ->fieldValueEquals('dimensions[width]', '2.5');
  $this
    ->assertSession()
    ->fieldValueEquals('dimensions[height]', '2.1');

  // Invalid submit.
  $edit = [
    'dimensions[length]' => 'invalid',
    'dimensions[width]' => '2.5',
    'dimensions[height]' => '2.1',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('Length must be a number.');

  // Valid submit.
  $edit = [
    'dimensions[length]' => '10.99',
    'dimensions[width]' => '2.5',
    'dimensions[height]' => '2.1',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('Length: "10.99", width: "2.5", height: "2.1", unit: "m".');
}