public function PluginBasedExchangeRateProviderFormTest::testBuildForm in Currency 8.3
Same name in this branch
- 8.3 tests/src/Unit/Controller/PluginBasedExchangeRateProviderFormTest.php \Drupal\Tests\currency\Unit\Controller\PluginBasedExchangeRateProviderFormTest::testBuildForm()
- 8.3 tests/src/Unit/Form/PluginBasedExchangeRateProviderFormTest.php \Drupal\Tests\currency\Unit\Form\PluginBasedExchangeRateProviderFormTest::testBuildForm()
@covers ::buildForm
File
- tests/
src/ Unit/ Controller/ PluginBasedExchangeRateProviderFormTest.php, line 102
Class
- PluginBasedExchangeRateProviderFormTest
- @coversDefaultClass \Drupal\currency\Form\PluginBasedExchangeRateProviderForm
Namespace
Drupal\Tests\currency\Unit\ControllerCode
public function testBuildForm() {
$plugin_id_a = $this
->randomMachineName();
$plugin_id_b = $this
->randomMachineName();
$plugin_id_c = $this
->randomMachineName();
$plugin_definitions = [
$plugin_id_a => [
'description' => NULL,
'label' => $this
->randomMachineName(),
'operations' => [],
],
$plugin_id_b => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
'operations' => [],
],
$plugin_id_c => [
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
'operations' => [
[
'href' => $this
->randomMachineName(),
'title' => $this
->randomMachineName(),
],
],
],
];
$configuration = [
$plugin_id_a => TRUE,
$plugin_id_b => FALSE,
$plugin_id_c => TRUE,
];
$this->exchangeRateProvider
->expects($this
->atLeastOnce())
->method('loadConfiguration')
->willReturn($configuration);
$this->currencyExchangeRateProviderManager
->expects($this
->atLeastOnce())
->method('getDefinitions')
->willReturn($plugin_definitions);
$form = [];
$form_state = new FormState();
$build = $this->sut
->buildForm($form, $form_state);
foreach ([
$plugin_id_a,
$plugin_id_b,
$plugin_id_c,
] as $weight => $plugin_id) {
$this
->assertIsArray($build['exchange_rate_providers'][$plugin_id]['weight']);
$this
->assertIsArray($build['exchange_rate_providers'][$plugin_id]['label']);
$this
->assertSame($plugin_definitions[$plugin_id]['label'], $build['exchange_rate_providers'][$plugin_id]['label']['#markup']);
$this
->assertIsArray($build['exchange_rate_providers'][$plugin_id]['weight']);
$this
->assertSame($weight + 1, $build['exchange_rate_providers'][$plugin_id]['weight']['#default_value']);
}
$this
->assertIsArray($build['actions']);
}