public function EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 109  - Contains \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest.
 
Class
- EntityReferenceSelectionReferenceableTest
 - Tests entity reference selection plugins.
 
Namespace
Drupal\Tests\system\Kernel\EntityCode
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
      ->assertTrue(empty($referenceables[$this->bundle]));
  }
  else {
    $this
      ->assertSame(count($referenceables[$this->bundle]), $count_limited);
  }
  // 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
      ->assertTrue(array_search($item, $referenceables[$this->bundle]) !== FALSE);
  }
  // Test ::countReferenceableEntities().
  $count_referenceables = $this->selectionHandler
    ->countReferenceableEntities($match, $match_operator);
  $this
    ->assertSame($count_referenceables, $count_all);
}