NumberElementTest.php in Commerce Core 8.2
File
modules/price/tests/src/Functional/NumberElementTest.php
View source
<?php
namespace Drupal\Tests\commerce_price\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
class NumberElementTest extends CommerceBrowserTestBase {
public static $modules = [
'commerce_price_test',
'language',
];
public function testInput() {
$this
->drupalGet('/commerce_price_test/number_test_form');
$this
->assertSession()
->fieldExists('number');
$this
->assertSession()
->fieldValueEquals('number', '99.99');
$edit = [
'number' => 'invalid',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be a number.');
$edit = [
'number' => '1',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be higher than or equal to 2.');
$edit = [
'number' => '101',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('Amount must be lower than or equal to 100.');
$edit = [
'number' => '10.99 ',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99".');
}
public function testLocalFormat() {
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
$this
->drupalGet('/commerce_price_test/number_test_form');
$this
->assertSession()
->fieldExists('number');
$this
->assertSession()
->fieldValueEquals('number', '99,99');
$edit = [
'number' => '10,99',
];
$this
->submitForm($edit, 'Submit');
$this
->assertSession()
->pageTextContains('The number is "10.99".');
}
}