You are here

public function ListWidgetTest::testFormElement in Select (or other) 8

Same name and namespace in other branches
  1. 4.x tests/src/Unit/ListWidgetTest.php \Drupal\Tests\select_or_other\Unit\ListWidgetTest::testFormElement()

Test if formElement() adds the expected information.

File

tests/src/Unit/ListWidgetTest.php, line 61

Class

ListWidgetTest
Tests the form element implementation.

Namespace

Drupal\Tests\select_or_other\Unit

Code

public function testFormElement() {
  list($parent, $mock) = $this
    ->getBasicMocks();

  /** @var ListWidget $mock */

  /** @var WidgetBase $parent */

  /** @var \Drupal\Core\Field\FieldItemListInterface $items */
  $items = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldItemListInterface');
  $delta = NULL;
  $element = [];
  $form = [];
  $form_state = new FormState();
  $parent_result = $parent
    ->formElement($items, $delta, $element, $form, $form_state);
  $result = $mock
    ->formElement($items, $delta, $element, $form, $form_state);
  $added = array_diff_key($result, $parent_result);
  $expected = [
    '#merged_values' => TRUE,
    '#original_options' => [],
    '#other_options' => [],
  ];
  $this
    ->assertArrayEquals($expected, $added);
}