You are here

public function MeasurementElementTest::testSingleUnit in Physical Fields 8

Tests the element with a single unit.

File

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

Class

MeasurementElementTest
Tests the physical_measurement form element.

Namespace

Drupal\Tests\physical\Functional

Code

public function testSingleUnit() {
  $this
    ->drupalGet('/physical/measurement_test_form/TRUE');
  $this
    ->assertSession()
    ->fieldExists('height[number]');

  // Default value.
  $this
    ->assertSession()
    ->fieldValueEquals('height[number]', '1.92');

  // Invalid submit.
  $edit = [
    'height[number]' => 'invalid',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('Height must be a number.');

  // Valid submit.
  $edit = [
    'height[number]' => '10.99',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('The number is "10.99" and the unit is "m".');
}