function EntityReferenceSelectionAccessTest::assertReferenceable

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\Tests\system\Functional\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest::assertReferenceable()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\Tests\system\Functional\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest::assertReferenceable()
  3. 10 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest::assertReferenceable()

Checks that a selection plugin returns the expected results.

@internal

Parameters

array $selection_options: An array of options as required by entity reference selection plugins.

array $tests: An array of tests to run.

string $handler_name: The name of the entity type selection handler being tested.

5 calls to EntityReferenceSelectionAccessTest::assertReferenceable()
EntityReferenceSelectionAccessTest::testCommentHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the comment-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testMediaHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the selection handler for the media entity type.
EntityReferenceSelectionAccessTest::testNodeHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the node-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testTermHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the term-specific overrides of the selection handler.
EntityReferenceSelectionAccessTest::testUserHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the user-specific overrides of the entity handler.

File

core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php, line 98

Class

EntityReferenceSelectionAccessTest
Tests for the base handlers provided by Entity Reference.

Namespace

Drupal\Tests\system\Kernel\Entity\EntityReferenceSelection

Code

protected function assertReferenceable(array $selection_options, array $tests, string $handler_name) : void {
    $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getInstance($selection_options);
    foreach ($tests as $test) {
        foreach ($test['arguments'] as $arguments) {
            $result = call_user_func_array([
                $handler,
                'getReferenceableEntities',
            ], $arguments);
            $this->assertEquals($test['result'], $result, "Valid result set returned by {$handler_name}.");
            $result = call_user_func_array([
                $handler,
                'countReferenceableEntities',
            ], $arguments);
            if (!empty($test['result'])) {
                $bundle = key($test['result']);
                $count = count($test['result'][$bundle]);
            }
            else {
                $count = 0;
            }
            $this->assertEquals($count, $result, "Valid count returned by {$handler_name}.");
        }
    }
}

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