You are here

public function ReferenceWidgetTest::testPrepareElementValuesForValidation in Select (or other) 8

Same name and namespace in other branches
  1. 8.3 Tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::testPrepareElementValuesForValidation()
  2. 4.x tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::testPrepareElementValuesForValidation()

Tests preparation for EntityAutocomplete::validateEntityAutocomplete.

File

tests/src/Unit/ReferenceWidgetTest.php, line 177

Class

ReferenceWidgetTest
Tests the form element implementation.

Namespace

Drupal\Tests\select_or_other\Unit

Code

public function testPrepareElementValuesForValidation() {
  $method = new ReflectionMethod($this
    ->getTestedClassName(), 'prepareElementValuesForValidation');
  $method
    ->setAccessible(TRUE);
  foreach ([
    FALSE,
    TRUE,
  ] as $tags) {
    $element = $original_element = [
      '#tags' => $tags,
      '#value' => [
        'Some value',
        'Another value',
      ],
    ];
    $method
      ->invokeArgs(NULL, [
      &$element,
    ]);
    if ($tags) {
      $this
        ->assertTrue(is_string($element['#value']));
    }
    else {
      $this
        ->assertArrayEquals($original_element, $element);
    }
  }
}