function NestedArrayTest::testSetValueForce

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testSetValueForce()
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testSetValueForce()
  3. 10 core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php \Drupal\Tests\Component\Utility\NestedArrayTest::testSetValueForce()

Tests force-setting values.

@covers ::setValue

File

core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php, line 101

Class

NestedArrayTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Utility%21NestedArray.php/class/NestedArray/11.x" title="Provides helpers to perform operations on nested arrays and array keys of variable depth." class="local">\Drupal\Component\Utility\NestedArray</a> @group Utility

Namespace

Drupal\Tests\Component\Utility

Code

public function testSetValueForce() : void {
    $new_value = [
        'one',
    ];
    $this->form['details']['non-array-parent'] = 'string';
    $parents = [
        'details',
        'non-array-parent',
        'child',
    ];
    NestedArray::setValue($this->form, $parents, $new_value, TRUE);
    $this->assertSame($new_value, $this->form['details']['non-array-parent']['child'], 'The nested element was not forced to the new value.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.