You are here

public function EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey()
  2. 9 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey()

Tests values returned by SelectionInterface::getReferenceableEntities() when the target entity type has no 'label' key.

@dataProvider providerTestCases

Parameters

mixed $match: The input text to be checked.

string $match_operator: The matching operator.

int $limit: The limit of returning records.

int $count_limited: The expected number of limited entities to be retrieved.

array $items: Array of entity labels expected to be returned.

int $count_all: The total number (unlimited) of entities to be retrieved.

File

core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php, line 110

Class

EntityReferenceSelectionReferenceableTest
Tests entity reference selection plugins.

Namespace

Drupal\Tests\system\Kernel\Entity

Code

public function testReferenceablesWithNoLabelKey($match, $match_operator, $limit, $count_limited, array $items, $count_all) {

  // Test ::getReferenceableEntities().
  $referenceables = $this->selectionHandler
    ->getReferenceableEntities($match, $match_operator, $limit);

  // Number of returned items.
  if (empty($count_limited)) {
    $this
      ->assertArrayNotHasKey($this->bundle, $referenceables);
  }
  else {
    $this
      ->assertCount($count_limited, $referenceables[$this->bundle]);
  }

  // Test returned items.
  foreach ($items as $item) {

    // SelectionInterface::getReferenceableEntities() always return escaped
    // entity labels.
    // @see \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities()
    $item = is_string($item) ? Html::escape($item) : $item;
    $this
      ->assertContainsEquals($item, $referenceables[$this->bundle]);
  }

  // Test ::countReferenceableEntities().
  $count_referenceables = $this->selectionHandler
    ->countReferenceableEntities($match, $match_operator);
  $this
    ->assertSame($count_referenceables, $count_all);
}