You are here

protected function EntityReferenceSelectionAccessTest::assertReferenceable in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\Tests\system\Functional\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest::assertReferenceable()
  2. 9 core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\Tests\system\Functional\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/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the comment-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testMediaHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the selection handler for the media entity type.
EntityReferenceSelectionAccessTest::testNodeHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the node-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testTermHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the term-specific overrides of the selection handler.
EntityReferenceSelectionAccessTest::testUserHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the user-specific overrides of the entity handler.

File

core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php, line 97

Class

EntityReferenceSelectionAccessTest
Tests for the base handlers provided by Entity Reference.

Namespace

Drupal\Tests\system\Functional\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, new FormattableMarkup('Valid result set returned by @handler.', [
        '@handler' => $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, new FormattableMarkup('Valid count returned by @handler.', [
        '@handler' => $handler_name,
      ]));
    }
  }
}