1.20.x common.test | CommonBackdropArrayUnitTest::testGet() |
Tests getting nested array values.
File
- modules/
simpletest/ tests/ common.test, line 2998 - Tests for common.inc functionality.
Class
- CommonBackdropArrayUnitTest
- Tests the various backdrop_array_* helper functions.
Code
function testGet() {
// Verify getting a value of a nested element.
$value = backdrop_array_get_nested_value($this->form, $this->parents);
$this->assertEqual($value['#value'], 'Nested element', 'Nested element value found.');
// Verify changing a value of a nested element by reference.
$value = &backdrop_array_get_nested_value($this->form, $this->parents);
$value['#value'] = 'New value';
$value = backdrop_array_get_nested_value($this->form, $this->parents);
$this->assertEqual($value['#value'], 'New value', 'Nested element value was changed by reference.');
$this->assertEqual($this->form['fieldset']['element']['#value'], 'New value', 'Nested element value was changed by reference.');
// Verify that an existing key is reported back.
$key_exists = NULL;
backdrop_array_get_nested_value($this->form, $this->parents, $key_exists);
$this->assertIdentical($key_exists, TRUE, 'Existing key found.');
// Verify that a non-existing key is reported back and throws no errors.
$key_exists = NULL;
$parents = $this->parents;
$parents[] = 'foo';
backdrop_array_get_nested_value($this->form, $parents, $key_exists);
$this->assertIdentical($key_exists, FALSE, 'Non-existing key not found.');
}