You are here

protected function EntityReferenceSelectionAccessTest::assertReferenceable in Drupal 8

Same name and namespace in other branches
  1. 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.

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
Test 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
Test the node-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testTermHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Test the term-specific overrides of the selection handler.
EntityReferenceSelectionAccessTest::testUserHandler in core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Test the user-specific overrides of the entity handler.

File

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

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, $tests, $handler_name) {
  $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
        ->assertEqual($result, $test['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
        ->assertEqual($result, $count, new FormattableMarkup('Valid count returned by @handler.', [
        '@handler' => $handler_name,
      ]));
    }
  }
}