MeasurementElementTest.php in Physical Fields 8
File
tests/src/Functional/MeasurementElementTest.php
View source
<?php
namespace Drupal\Tests\physical\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class MeasurementElementTest extends BrowserTestBase {
public static $modules = [
'physical_test',
'language',
];
protected $defaultTheme = 'stark';
public function testSingleUnit() {
$this
->drupalGet('/physical/measurement_test_form/TRUE');
$this
->assertSession()
->fieldExists('height[number]');
$this
->assertSession()
->fieldValueEquals('height[number]', '1.92');
$edit = [
'height[number]' => 'invalid',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Height must be a number.');
$edit = [
'height[number]' => '10.99',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99" and the unit is "m".');
}
public function testMultipleCurrency() {
$this
->drupalGet('/physical/measurement_test_form');
$this
->assertSession()
->fieldExists('height[number]');
$this
->assertSession()
->fieldExists('height[unit]');
$this
->assertSession()
->fieldValueEquals('height[number]', '1.92');
$this
->assertSession()
->optionExists('height[unit]', 'in');
$element = $this
->assertSession()
->optionExists('height[unit]', 'm');
$this
->assertTrue($element
->isSelected());
$edit = [
'height[number]' => 'invalid',
'height[unit]' => 'm',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Height must be a number.');
$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".');
}
public function testLocalFormat() {
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
$this
->drupalGet('/physical/measurement_test_form');
$this
->assertSession()
->fieldExists('height[number]');
$this
->assertSession()
->fieldValueEquals('height[number]', '1,92');
$edit = [
'height[number]' => '10,99',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99" and the unit is "m".');
}
}