function IconPackManagerKernelTest::testGetExtractorPluginFormsWithDefault
Test the IconPackManager::getExtractorPluginForms method with default.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ Icon/ IconPackManagerKernelTest.php, line 243
Class
- IconPackManagerKernelTest
- @coversDefaultClass \Drupal\Core\Theme\Icon\Plugin\IconPackManager
Namespace
Drupal\KernelTests\Core\Theme\IconCode
public function testGetExtractorPluginFormsWithDefault() : void {
$form = [
'#parents' => [],
'test_settings' => [
'#parents' => [
'test_settings',
],
'#array_parents' => [
'test_settings',
],
],
];
$form_state = $this->getMockBuilder('Drupal\\Core\\Form\\FormState')
->disableOriginalConstructor()
->onlyMethods([
'setValue',
'getValue',
])
->getMock();
$this->pluginManagerIconPack
->getExtractorPluginForms($form, $form_state);
// Without default, values are from definition.
$expected = [
'width' => 32,
'height' => 33,
'title' => 'Default title',
'alt' => 'Default alt',
'select' => 400,
'boolean' => TRUE,
'decimal' => 66.66,
'number' => 30,
];
foreach ($expected as $key => $value) {
$this->assertSame($value, $form['test_settings'][$key]['#default_value']);
}
// Test definition without value.
$this->assertArrayNotHasKey('#default_value', $form['test_svg']['size']);
$default_settings = [
'test_settings' => [
'width' => 100,
'height' => 110,
'title' => 'Test',
],
];
// Test the set/get of default values as 'saved_values'.
$form_state->expects($this->once())
->method('setValue')
->with('saved_values', $default_settings['test_settings']);
$form_state->expects($this->once())
->method('getValue')
->with('saved_values')
->willReturn($default_settings['test_settings']);
$this->pluginManagerIconPack
->getExtractorPluginForms($form, $form_state, $default_settings, [
'test_settings' => '',
]);
$this->assertSame($default_settings['test_settings']['width'], $form['test_settings']['width']['#default_value']);
$this->assertSame($default_settings['test_settings']['height'], $form['test_settings']['height']['#default_value']);
$this->assertSame($default_settings['test_settings']['title'], $form['test_settings']['title']['#default_value']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.