AmountWebTest.php in Currency 8.3
File
tests/src/Functional/Plugin/views/field/AmountWebTest.php
View source
<?php
namespace Drupal\Tests\currency\Functional\Plugin\views\field;
use Drupal\Tests\BrowserTestBase;
use Drupal\views\Entity\View;
class AmountWebTest extends BrowserTestBase {
public static $modules = array(
'currency_test',
'views_ui',
);
protected $defaultTheme = 'stark';
public function setUp() : void {
parent::setUp();
$config_importer = \Drupal::service('currency.config_importer');
$config_importer
->importCurrency('EUR');
$config_importer
->importCurrency('UAH');
$config_importer
->importCurrency('USD');
}
public function testHandler() {
$view_id = 'currency_test';
$account = $this
->drupalCreateUser(array(
'administer views',
));
$this
->drupalLogin($account);
$this
->drupalPostForm('admin/structure/views/nojs/handler/' . $view_id . '/default/field/amount_currency_code_definition', array(
'options[currency_round]' => TRUE,
), t('Apply'));
$this
->drupalPostForm('admin/structure/views/view/' . $view_id, array(), t('Save'));
$view = View::load($view_id);
$view
->getExecutable()
->execute('default');
$values = array(
array(
'amount_currency_code_definition' => 'EUR 123.46',
'amount_currency_code_field_definition' => 'EUR 123.456',
'amount_currency_code_field_table_definition' => 'EUR 123.456',
'amount_currency_undefined' => 'XXX 123.456',
),
array(
'amount_currency_code_definition' => 'EUR 123.46',
'amount_currency_code_field_definition' => 'USD 123.456',
'amount_currency_code_field_table_definition' => 'USD 123.456',
'amount_currency_undefined' => 'XXX 123.456',
),
array(
'amount_currency_code_definition' => 'EUR 123.46',
'amount_currency_code_field_definition' => 'UAH 123.456',
'amount_currency_code_field_table_definition' => 'UAH 123.456',
'amount_currency_undefined' => 'XXX 123.456',
),
);
foreach ($values as $row => $row_values) {
foreach ($row_values as $field => $value) {
$this
->assertEqual($view
->get('executable')->field[$field]
->advancedRender($view
->get('executable')->result[$row]), $value);
}
}
}
}