You are here

public function MeasurementElementTest::testMultipleCurrency in Physical Fields 8

Tests the element with multiple units.

File

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

Class

MeasurementElementTest
Tests the physical_measurement form element.

Namespace

Drupal\Tests\physical\Functional

Code

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

  // Default value.
  $this
    ->assertSession()
    ->fieldValueEquals('height[number]', '1.92');
  $this
    ->assertSession()
    ->optionExists('height[unit]', 'in');
  $element = $this
    ->assertSession()
    ->optionExists('height[unit]', 'm');
  $this
    ->assertTrue($element
    ->isSelected());

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

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