function FilterEntityReferenceTest::testViewEntityReferenceAsSelectList

Tests that results are successfully filtered by the select list widget.

File

core/modules/views/tests/src/Kernel/Handler/FilterEntityReferenceTest.php, line 154

Class

FilterEntityReferenceTest
Tests the core Drupal\views\Plugin\views\filter\EntityReference handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testViewEntityReferenceAsSelectList() : void {
  $view = Views::getView('test_filter_entity_reference');
  $view->setDisplay();
  $view->preExecute([]);
  $view->setExposedInput([
    'field_test_target_id' => [
      $this->targetNodes[0]
        ->id(),
    ],
  ]);
  $this->executeView($view);
  // Expect to have only Page 0, with Article 0 referenced.
  $expected = [
    [
      'title' => 'Page 0',
    ],
  ];
  $this->assertIdenticalResultset($view, $expected, [
    'title' => 'title',
  ]);
  // Change to both Article 0 and Article 3.
  $view = Views::getView('test_filter_entity_reference');
  $view->setDisplay();
  $view->setExposedInput([
    'field_test_target_id' => [
      $this->targetNodes[0]
        ->id(),
      $this->targetNodes[3]
        ->id(),
    ],
  ]);
  $this->executeView($view);
  // Expect to have Page 0 and 1, with Article 0 and 3 referenced.
  $expected = [
    [
      'title' => 'Page 0',
    ],
    [
      'title' => 'Page 1',
    ],
  ];
  $this->assertIdenticalResultset($view, $expected, [
    'title' => 'title',
  ]);
}

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