function EntityContextDefinitionIsSatisfiedTest::testIsSatisfiedByPassBundledEntity

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

@covers ::isSatisfiedBy @covers ::dataTypeMatches @covers ::getSampleValues @covers ::getConstraintObjects

@dataProvider providerTestIsSatisfiedByPassBundledEntity

File

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

Class

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

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function testIsSatisfiedByPassBundledEntity($expected, $requirement_constraint) : void {
    $entity_type = new EntityType([
        'id' => 'test_content',
    ]);
    $this->entityTypeManager
        ->getDefinitions()
        ->willReturn([
        'test_content' => $entity_type,
    ]);
    $this->entityTypeManager
        ->getDefinition('test_content')
        ->willReturn($entity_type);
    $this->entityTypeManager
        ->getStorage('test_content')
        ->shouldNotBeCalled();
    $this->entityTypeBundleInfo
        ->getBundleInfo('test_content')
        ->willReturn([
        'first_bundle' => [
            'label' => 'First bundle',
        ],
        'second_bundle' => [
            'label' => 'Second bundle',
        ],
        'third_bundle' => [
            'label' => 'Third bundle',
        ],
    ]);
    $entity = $this->prophesize(ContentEntityInterface::class)
        ->willImplement(\IteratorAggregate::class);
    $entity->getEntityTypeId()
        ->willReturn('test_content');
    $entity->getIterator()
        ->willReturn(new \ArrayIterator([]));
    $entity->getCacheContexts()
        ->willReturn([]);
    $entity->getCacheTags()
        ->willReturn([]);
    $entity->getCacheMaxAge()
        ->willReturn(0);
    $entity->bundle()
        ->willReturn('third_bundle');
    $requirement = EntityContextDefinition::fromEntityTypeId('test_content');
    if ($requirement_constraint) {
        $requirement->addConstraint('Bundle', $requirement_constraint);
    }
    $definition = EntityContextDefinition::fromEntityTypeId('test_content');
    $this->assertRequirementIsSatisfied($expected, $requirement, $definition, $entity->reveal());
}

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