3 namespace Drupal\Tests\views\Unit;
5 use Drupal\Core\Form\FormState;
6 use Drupal\Tests\UnitTestCase;
7 use Drupal\views\Plugin\views\wizard\WizardPluginBase;
10 * @coversDefaultClass \Drupal\views\Plugin\views\wizard\WizardPluginBase
14 class WizardPluginBaseTest extends UnitTestCase {
17 * @covers ::getSelected
19 * @dataProvider providerTestGetSelected
21 public function testGetSelected($expected, $element = [], $parents = [], $user_input = [], $not_rebuilding_expected = NULL) {
22 $not_rebuilding_expected = $not_rebuilding_expected ?: $expected;
23 $form_state = new FormState();
24 $form_state->setUserInput($user_input);
26 $actual = WizardPluginBase::getSelected($form_state, $parents, 'the_default_value', $element);
27 $this->assertSame($not_rebuilding_expected, $actual);
28 $this->assertSame($user_input, $form_state->getUserInput());
30 $form_state->setRebuild();
31 $actual = WizardPluginBase::getSelected($form_state, $parents, 'the_default_value', $element);
32 $this->assertSame($expected, $actual);
33 $this->assertSame($user_input, $form_state->getUserInput());
37 * Provides test data for testGetSelected().
39 public function providerTestGetSelected() {
41 // A form element with an invalid #type.
42 $data['invalid_type'] = [
45 '#type' => 'checkbox',
48 // A form element with no #options.
49 $data['no_options'] = [
55 // A valid form element with no user input.
56 $data['no_user_input'] = [
61 'option1' => 'Option 1',
65 // A valid form element with user input that doesn't correspond to it.
66 $data['mismatched_input'] = [
71 'option1' => 'Option 1',
75 ['foo' => ['foo' => 'value1']],
77 // A valid form element with a valid dynamic value that matches the default
79 $data['matching_default'] = [
84 'the_default_value' => 'Option 1',
88 ['foo' => ['bar' => 'the_default_value']],
90 // A valid form element with a valid dynamic value that does not match the
92 $data['mismatched_value'] = [
97 'option1' => 'Option 1',
101 ['foo' => ['bar' => 'option1']],