function FormTestBase::assertFormElement

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::assertFormElement()

Asserts that the expected form structure is found in a form for a given key.

Parameters

array $expected_form: The expected form structure.

array $actual_form: The actual form.

string|null $form_key: (optional) The form key to look in. Otherwise the entire form will be compared.

File

core/tests/Drupal/Tests/Core/Form/FormTestBase.php, line 271

Class

FormTestBase
Provides a base class for testing form functionality.

Namespace

Drupal\Tests\Core\Form

Code

protected function assertFormElement(array $expected_form, array $actual_form, $form_key = NULL) {
  $expected_element = $form_key ? $expected_form[$form_key] : $expected_form;
  $actual_element = $form_key ? $actual_form[$form_key] : $actual_form;
  $this->assertSame(array_intersect_key($expected_element, $actual_element), $expected_element);
}

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