function EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey()
  2. 8.9.x core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey()
  3. 10 core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php \Drupal\Tests\system\Kernel\Entity\EntityReferenceSelectionReferenceableTest::testReferenceablesWithNoLabelKey()

Tests referenceable entities with no target entity type '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.

See also

\Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities()

File

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

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) : void {
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.