function EntityContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\EntityContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\EntityContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\EntityContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy()

Provides test data for ::testIsSatisfiedBy().

File

core/tests/Drupal/Tests/Core/Plugin/Context/EntityContextDefinitionIsSatisfiedTest.php, line 134

Class

EntityContextDefinitionIsSatisfiedTest
@coversDefaultClass \Drupal\Core\Plugin\Context\EntityContextDefinition @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function providerTestIsSatisfiedBy() {
    $data = [];
    $content = new EntityType([
        'id' => 'test_content',
    ]);
    $config = new EntityType([
        'id' => 'test_config',
    ]);
    // Entities without bundles.
    $data['content entity, matching type, no value'] = [
        TRUE,
        EntityContextDefinition::fromEntityType($content),
        EntityContextDefinition::fromEntityType($content),
    ];
    $entity = $this->prophesize(ContentEntityInterface::class)
        ->willImplement(\IteratorAggregate::class);
    $entity->getIterator()
        ->willReturn(new \ArrayIterator([]));
    $entity->getCacheContexts()
        ->willReturn([]);
    $entity->getCacheTags()
        ->willReturn([]);
    $entity->getCacheMaxAge()
        ->willReturn(0);
    $entity->getEntityTypeId()
        ->willReturn('test_content');
    $data['content entity, matching type, correct value'] = [
        TRUE,
        EntityContextDefinition::fromEntityType($content),
        EntityContextDefinition::fromEntityType($content),
        $entity->reveal(),
    ];
    $data['content entity, incorrect manual constraint'] = [
        TRUE,
        EntityContextDefinition::fromEntityType($content),
        EntityContextDefinition::fromEntityType($content)->addConstraint('EntityType', 'test_config'),
    ];
    $data['config entity, matching type, no value'] = [
        TRUE,
        EntityContextDefinition::fromEntityType($config),
        EntityContextDefinition::fromEntityType($config),
    ];
    $data['generic entity requirement, specific context'] = [
        TRUE,
        new ContextDefinition('entity'),
        EntityContextDefinition::fromEntityType($config),
    ];
    $data['specific requirement, generic entity context'] = [
        FALSE,
        EntityContextDefinition::fromEntityType($content),
        new ContextDefinition('entity'),
    ];
    return $data;
}

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