function ModerationInformationTest::testGetWorkflowForEntity

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php \Drupal\Tests\content_moderation\Unit\ModerationInformationTest::testGetWorkflowForEntity()
  2. 10 core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php \Drupal\Tests\content_moderation\Unit\ModerationInformationTest::testGetWorkflowForEntity()
  3. 11.x 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 106

Class

ModerationInformationTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21content_moderation%21src%21ModerationInformation.php/class/ModerationInformation/8.9.x" title="General service for moderation-related questions about Entity API." class="local">\Drupal\content_moderation\ModerationInformation</a> @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()));
}

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