public function ButtonsElementTest::testEnsureCorrectDefaultValue in Select (or other) 8
Same name and namespace in other branches
- 4.x tests/src/Unit/ButtonsElementTest.php \Drupal\Tests\select_or_other\Unit\ButtonsElementTest::testEnsureCorrectDefaultValue()
Make sure radio buttons always have a correct default value.
File
- tests/
src/ Unit/ ButtonsElementTest.php, line 108
Class
- ButtonsElementTest
- Tests the form element implementation.
Namespace
Drupal\Tests\select_or_other\UnitCode
public function testEnsureCorrectDefaultValue() {
$element = [
'select' => [
'#type' => 'radios',
],
];
$arguments = [
&$element,
];
$ensure_correct_default_value = new ReflectionMethod('Drupal\\select_or_other\\Element\\Buttons', 'ensureCorrectDefaultValue');
$ensure_correct_default_value
->setAccessible(TRUE);
$expected = $element;
$ensure_correct_default_value
->invokeArgs(NULL, $arguments);
$this
->assertArrayEquals($expected, $element);
$element['select']['#default_value'] = 'non_array_default';
$expected = $element;
$ensure_correct_default_value
->invokeArgs(NULL, $arguments);
$this
->assertArrayEquals($expected, $element);
$element['select']['#default_value'] = [
'array_default',
];
$expected['select']['#default_value'] = 'array_default';
$ensure_correct_default_value
->invokeArgs(NULL, $arguments);
$this
->assertArrayEquals($expected, $element);
$expected['select']['#type'] = $element['select']['#type'] = 'checkboxes';
$expected['select']['#default_value'] = $element['select']['#default_value'] = [
'array_default',
];
$ensure_correct_default_value
->invokeArgs(NULL, $arguments);
$this
->assertArrayEquals($expected, $element);
}