function NestedArrayTest::testUnsetValue

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

Tests unsetting nested array values.

@covers ::unsetValue

File

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

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 testUnsetValue() : void {
    // Verify unsetting a non-existing nested element throws no errors and the
    // non-existing key is properly reported.
    $key_existed = NULL;
    $parents = $this->parents;
    $parents[] = 'foo';
    NestedArray::unsetValue($this->form, $parents, $key_existed);
    $this->assertTrue(isset($this->form['details']['element']['#value']), 'Outermost nested element key still exists.');
    $this->assertFalse($key_existed, 'Non-existing key not found.');
    // Verify unsetting a nested element.
    $key_existed = NULL;
    NestedArray::unsetValue($this->form, $this->parents, $key_existed);
    $this->assertFalse(isset($this->form['details']['element']), 'Removed nested element not found.');
    $this->assertTrue($key_existed, 'Existing key was found.');
}

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