You are here

public function DimensionsElementTest::testMultipleCurrency in Physical Fields 8

Tests the element with multiple units.

File

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

Class

DimensionsElementTest
Tests the physical_dimensions form element.

Namespace

Drupal\Tests\physical\Functional

Code

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

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

  // Invalid submit.
  $edit = [
    'dimensions[length]' => 'invalid',
    'dimensions[width]' => '2.5',
    'dimensions[height]' => '2.1',
    'dimensions[unit]' => 'm',
  ];
  $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',
    'dimensions[unit]' => 'in',
  ];
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains('Length: "10.99", width: "2.5", height: "2.1", unit: "in".');
}