1 common.test CommonBackdropArrayUnitTest::testUnset()

Tests unsetting nested array values.

File

core/modules/simpletest/tests/common.test, line 3133
Tests for common.inc functionality.

Class

CommonBackdropArrayUnitTest
Tests the various backdrop_array_* helper functions.

Code

function testUnset() {
  // 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';
  backdrop_array_unset_nested_value($this->form, $parents, $key_existed);
  $this->assertTrue(isset($this->form['fieldset']['element']['#value']), 'Outermost nested element key still exists.');
  $this->assertIdentical($key_existed, FALSE, 'Non-existing key not found.');

  // Verify unsetting a nested element.
  $key_existed = NULL;
  backdrop_array_unset_nested_value($this->form, $this->parents, $key_existed);
  $this->assertFalse(isset($this->form['fieldset']['element']), 'Removed nested element not found.');
  $this->assertIdentical($key_existed, TRUE, 'Existing key was found.');
}