function PageContextTest::testBuildContentModerationNoPending

Tests content moderation build output with no pending revisions.

File

core/modules/navigation/tests/src/Unit/PageContextTest.php, line 170

Class

PageContextTest
Tests the PageContext Top Bar item build output.

Namespace

Drupal\Tests\navigation\Unit

Code

public function testBuildContentModerationNoPending() : void {
  // Mock moderated content entity with state 'draft'.
  $entity = $this->prophesize(ContentEntityInterface::class);
  $entity->get('moderation_state')
    ->willReturn((object) [
    'value' => 'draft',
  ]);
  $entity->isDefaultRevision()
    ->willReturn(TRUE);
  $entity->getEntityTypeId()
    ->willReturn('node');
  $entity->id()
    ->willReturn('1');
  $entity->label()
    ->willReturn('Example Title');
  // Workflow chain: workflow -> type plugin -> state('draft')->label() => 'Draft'.
  $state = $this->prophesize(StateInterface::class);
  $state->label()
    ->willReturn('Draft');
  $type = $this->prophesize(WorkflowTypeInterface::class);
  $type->getState('draft')
    ->willReturn($state->reveal());
  $workflow = $this->prophesize(WorkflowInterface::class);
  $workflow->getTypePlugin()
    ->willReturn($type->reveal());
  $moderation = $this->prophesize(ModerationInformationInterface::class);
  $moderation->isModeratedEntity($entity->reveal())
    ->willReturn(TRUE);
  $moderation->getWorkflowForEntity($entity->reveal())
    ->willReturn($workflow->reveal());
  $moderation->hasPendingRevision($entity->reveal())
    ->willReturn(FALSE);
  $route_helper = $this->prophesize(EntityRouteHelper::class);
  $route_helper->getContentEntityFromRoute()
    ->willReturn($entity->reveal());
  $entity_repository = $this->prophesize(EntityRepositoryInterface::class)
    ->reveal();
  $plugin = new PageContext([], 'page_context', [], $route_helper->reveal(), $entity_repository, $moderation->reveal());
  $build = $plugin->build();
  // Title component.
  $this->assertSame('Example Title', $build[0]['#slots']['content']);
  // Badge component with label Draft, default status info (not published interface).
  $this->assertSame('navigation:badge', $build[1]['#component']);
  $this->assertSame('Draft', $build[1]['#slots']['label']);
  $this->assertSame('info', $build[1]['#props']['status']);
}

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