You are here

public function ModerationInformationTest::testGetWorkflowForEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php \Drupal\Tests\content_moderation\Unit\ModerationInformationTest::testGetWorkflowForEntity()

@dataProvider providerWorkflow @covers ::getWorkflowForEntity

File

core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php, line 109

Class

ModerationInformationTest
@coversDefaultClass \Drupal\content_moderation\ModerationInformation @group content_moderation

Namespace

Drupal\Tests\content_moderation\Unit

Code

public function testGetWorkflowForEntity($workflow) {
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  if ($workflow) {
    $workflow_entity = $this
      ->prophesize(WorkflowInterface::class)
      ->reveal();
    $workflow_storage = $this
      ->prophesize(EntityStorageInterface::class);
    $workflow_storage
      ->load('workflow')
      ->willReturn($workflow_entity)
      ->shouldBeCalled();
    $entity_type_manager
      ->getStorage('workflow')
      ->willReturn($workflow_storage
      ->reveal());
  }
  else {
    $workflow_entity = NULL;
  }
  $moderation_information = new ModerationInformation($entity_type_manager
    ->reveal(), $this
    ->setupModerationBundleInfo('test_bundle', $workflow));
  $entity = $this
    ->prophesize(ContentEntityInterface::class);
  $entity
    ->getEntityTypeId()
    ->willReturn('test_entity_type');
  $entity
    ->bundle()
    ->willReturn('test_bundle');
  $this
    ->assertEquals($workflow_entity, $moderation_information
    ->getWorkflowForEntity($entity
    ->reveal()));
}