You are here

public function AdminToolbarStateTest::testModeratedEntity in Moderation Sidebar 8

Tests state labels in admin toolbar with a moderated entity.

File

tests/src/Functional/AdminToolbarStateTest.php, line 45

Class

AdminToolbarStateTest
Contains test for the toolbar state label.

Namespace

Drupal\Tests\moderation_sidebar\Functional

Code

public function testModeratedEntity() {
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('node', 'article');
  $workflow
    ->save();
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);
  $url = $node
    ->toUrl()
    ->toString();
  $assert_session = $this
    ->assertSession();

  // Draft.
  $node
    ->set('moderation_state', 'draft');
  $node
    ->save();
  $this
    ->drupalGet($url);
  $assert_session
    ->elementExists('css', '.moderation-label-draft[data-label="Draft"]');

  // Published.
  $node
    ->set('moderation_state', 'published');
  $node
    ->save();
  $this
    ->drupalGet($url);
  $assert_session
    ->elementExists('css', '.moderation-label-published[data-label="Published"]');

  // Archived.
  $node
    ->set('moderation_state', 'archived');
  $node
    ->save();
  $this
    ->drupalGet($url);
  $assert_session
    ->elementExists('css', '.moderation-label-draft[data-label="Archived"]');
}