You are here

protected function EntityReferenceSelectionAccessTest::assertReferenceable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php \Drupal\system\Tests\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.

3 calls to EntityReferenceSelectionAccessTest::assertReferenceable()
EntityReferenceSelectionAccessTest::testCommentHandler in core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Test the comment-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testNodeHandler in core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Test the node-specific overrides of the entity handler.
EntityReferenceSelectionAccessTest::testUserHandler in core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Test the user-specific overrides of the entity handler.

File

core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php, line 50
Contains \Drupal\system\Tests\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest.

Class

EntityReferenceSelectionAccessTest
Tests for the base handlers provided by Entity Reference.

Namespace

Drupal\system\Tests\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(array(
        $handler,
        'getReferenceableEntities',
      ), $arguments);
      $this
        ->assertEqual($result, $test['result'], format_string('Valid result set returned by @handler.', array(
        '@handler' => $handler_name,
      )));
      $result = call_user_func_array(array(
        $handler,
        'countReferenceableEntities',
      ), $arguments);
      if (!empty($test['result'])) {
        $bundle = key($test['result']);
        $count = count($test['result'][$bundle]);
      }
      else {
        $count = 0;
      }
      $this
        ->assertEqual($result, $count, format_string('Valid count returned by @handler.', array(
        '@handler' => $handler_name,
      )));
    }
  }
}