You are here

public function EntityContextDefinitionIsSatisfiedTest::testIsSatisfiedByPassBundledEntity in Drupal 8

Same name and namespace in other branches
  1. 9 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 287

Class

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

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function testIsSatisfiedByPassBundledEntity($expected, $requirement_constraint) {
  $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());
}