function PageContextTest::testBuildStatusBadge

Tests the status badge for published and unpublished entities.

File

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

Class

PageContextTest
Tests the PageContext Top Bar item build output.

Namespace

Drupal\Tests\navigation\Unit

Code

public function testBuildStatusBadge() : void {
  $entity = $this->prophesize(ContentEntityInterface::class);
  $entity->willImplement(EntityPublishedInterface::class);
  $entity->isPublished()
    ->willReturn(TRUE);
  $entity->label()
    ->willReturn('Published Title');
  $route_helper = $this->prophesize(EntityRouteHelper::class);
  $route_helper->getContentEntityFromRoute()
    ->willReturn($entity->reveal());
  $entity_repository = $this->prophesize(EntityRepositoryInterface::class)
    ->reveal();
  $published_plugin = new PageContext([], 'page_context', [], $route_helper->reveal(), $entity_repository, NULL);
  $build = $published_plugin->build();
  $this->assertSame('Published Title', $build[0]['#slots']['content']);
  $this->assertSame('navigation:badge', $build[1]['#component']);
  $this->assertSame('Published', $build[1]['#slots']['label']);
  $this->assertSame('success', $build[1]['#props']['status']);
  // Now assert the Unpublished path.
  $entity->isPublished()
    ->willReturn(FALSE);
  $entity->label()
    ->willReturn('Unpublished Title');
  $route_helper->getContentEntityFromRoute()
    ->willReturn($entity->reveal());
  $plugin = new PageContext([], 'page_context', [], $route_helper->reveal(), $entity_repository, NULL);
  $build = $plugin->build();
  $this->assertSame('Unpublished Title', $build[0]['#slots']['content']);
  $this->assertSame('Unpublished', $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.