View source
<?php
namespace Drupal\Tests\physical\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class DimensionsElementTest extends BrowserTestBase {
public static $modules = [
'physical_test',
'language',
];
protected $defaultTheme = 'stark';
public function testSingleUnit() {
$this
->drupalGet('/physical/dimensions_test_form/TRUE');
$this
->assertSession()
->fieldExists('dimensions[length]');
$this
->assertSession()
->fieldExists('dimensions[width]');
$this
->assertSession()
->fieldExists('dimensions[height]');
$this
->assertSession()
->fieldValueEquals('dimensions[length]', '1.92');
$this
->assertSession()
->fieldValueEquals('dimensions[width]', '2.5');
$this
->assertSession()
->fieldValueEquals('dimensions[height]', '2.1');
$edit = [
'dimensions[length]' => 'invalid',
'dimensions[width]' => '2.5',
'dimensions[height]' => '2.1',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Length must be a number.');
$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".');
}
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]');
$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());
$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.');
$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".');
}
public function testLocalFormat() {
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]');
$this
->assertSession()
->fieldValueEquals('dimensions[length]', '1,92');
$this
->assertSession()
->fieldValueEquals('dimensions[width]', '2,5');
$this
->assertSession()
->fieldValueEquals('dimensions[height]', '2,1');
$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".');
}
}