public function FormBaseTest::testSetElementArray in Form Builder 7.2
@covers \Drupal\form_builder\FormBase::setElementArray @covers \Drupal\form_builder\FormBase::getElement @covers \Drupal\form_builder\FormBase::getElementArray @covers \Drupal\form_builder\FormBase::getFormArray @covers \Drupal\form_builder\FormBase::addDefaults
File
- tests/
FormBaseTest.php, line 48
Class
Namespace
Drupal\form_builderCode
public function testSetElementArray() {
$form = $this
->emptyForm();
$a['#form_builder']['element_id'] = 'A';
$a['#key'] = 'a';
$a['#type'] = 'textfield';
$this
->assertEqual('A', $form
->setElementArray($a));
$rform = $form
->getFormArray();
$this
->assertArrayHasKey('a', $rform);
$a['#key'] = 'x';
$this
->assertEqual('A', $form
->setElementArray($a));
$rform = $form
->getFormArray();
$this
->assertArrayNotHasKey('a', $rform);
$this
->assertArrayHasKey('x', $rform);
$b['#key'] = 'b';
$b['#type'] = 'textfield';
$b['#form_builder'] = array(
'element_id' => 'B',
'parent_id' => 'A',
);
$this
->assertEqual('B', $form
->setElementArray($b));
$this
->assertArrayNotHasKey('b', $form
->getFormArray());
$this
->assertArrayHasKey('b', $form
->getElementArray('A'));
$b['#form_builder']['parent_id'] = 'NON EXISTING';
$this
->assertFalse($form
->setElementArray($b));
$this
->assertArrayHasKey('b', $form
->getElementArray('A'));
$b['#form_builder']['parent_id'] = FORM_BUILDER_ROOT;
$this
->assertEqual('B', $form
->setElementArray($b));
$this
->assertArrayHasKey('b', $form
->getFormArray());
$this
->assertArrayNotHasKey('b', $form
->getElementArray('A'));
}