You are here

public function FormStateValuesTraitTest::testSetValueForElement in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php \Drupal\Tests\Core\Form\FormStateValuesTraitTest::testSetValueForElement()
  2. 9 core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php \Drupal\Tests\Core\Form\FormStateValuesTraitTest::testSetValueForElement()

Tests that setting the value for an element adds to the values.

@covers ::setValueForElement

File

core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php, line 20

Class

FormStateValuesTraitTest
@coversDefaultClass \Drupal\Core\Form\FormStateValuesTrait

Namespace

Drupal\Tests\Core\Form

Code

public function testSetValueForElement() {
  $element = [
    '#parents' => [
      'foo',
      'bar',
    ],
  ];
  $value = $this
    ->randomMachineName();
  $form_state = new FormStateValuesTraitStub();
  $form_state
    ->setValueForElement($element, $value);
  $expected = [
    'foo' => [
      'bar' => $value,
    ],
  ];
  $this
    ->assertSame($expected, $form_state
    ->getValues());
}