function NestedArrayUnitTest::testUnsetValue

Tests unsetting nested array values.

File

drupal/core/tests/Drupal/Tests/Core/NestedArrayUnitTest.php, line 96
Contains \Drupal\Core\NestedArrayUnitTest.

Class

NestedArrayUnitTest
Tests the NestedArray helper class.

Namespace

Drupal\Tests\Core

Code

function testUnsetValue() {

  // 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
    ->assertSame($key_existed, FALSE, '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
    ->assertSame($key_existed, TRUE, 'Existing key was found.');
}