function ViewSelectionEntityReferenceTest::testSelectionPlugin

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Entity/ViewSelectionEntityReferenceTest.php \Drupal\Tests\views\Kernel\Entity\ViewSelectionEntityReferenceTest::testSelectionPlugin()
  2. 10 core/modules/views/tests/src/Kernel/Entity/ViewSelectionEntityReferenceTest.php \Drupal\Tests\views\Kernel\Entity\ViewSelectionEntityReferenceTest::testSelectionPlugin()

Tests the ViewSelection plugin.

File

core/modules/views/tests/src/Kernel/Entity/ViewSelectionEntityReferenceTest.php, line 41

Class

ViewSelectionEntityReferenceTest
Tests the ViewSelection EntityReferenceSelection plugin.

Namespace

Drupal\Tests\views\Kernel\Entity

Code

public function testSelectionPlugin() : void {
    for ($i = 1; $i <= 5; $i++) {
        $entity = EntityTest::create([
            'name' => 'Test entity ' . $i,
        ]);
        $entity->save();
    }
    $selection_options = [
        'target_type' => 'entity_test',
        'handler' => 'views',
        'view' => [
            'view_name' => 'test_display_entity_reference',
            'display_name' => 'entity_reference_1',
        ],
    ];
    $handler = $this->container
        ->get('plugin.manager.entity_reference_selection')
        ->getInstance($selection_options);
    $state = \Drupal::state();
    $this->assertNull($state->get('views_test_config.views_post_render_called'));
    $state->set('views_test_config.views_post_render_cache_tag', TRUE);
    $result = $handler->getReferenceableEntities();
    $this->assertCount(5, $result['entity_test']);
    $this->assertTrue($state->get('views_test_config.views_post_render_called'));
}

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