You are here

public function DimensionsElementTest::testLocalFormat in Physical Fields 8

Tests the element with a non-English length format.

File

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

Class

DimensionsElementTest
Tests the physical_dimensions form element.

Namespace

Drupal\Tests\physical\Functional

Code

public function testLocalFormat() {

  // French uses a comma as a decimal separator.
  ConfigurableLanguage::createFromLangcode('fr')
    ->save();
  $this
    ->config('system.site')
    ->set('default_langcode', 'fr')
    ->save();
  $this
    ->drupalGet('/physical/dimensions_test_form');
  $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');

  // 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".');
}