function NavigationTopBarPageContextTest::testPageContextTopBarItemNode

Same name and namespace in other branches
  1. 11.x core/modules/navigation/tests/src/Functional/NavigationTopBarPageContextTest.php \Drupal\Tests\navigation\Functional\NavigationTopBarPageContextTest::testPageContextTopBarItemNode()

Tests the PageContext top bar item output for a published node.

File

core/modules/navigation/tests/src/Functional/NavigationTopBarPageContextTest.php, line 66

Class

NavigationTopBarPageContextTest
Tests the PageContext top bar item functionality.

Namespace

Drupal\Tests\navigation\Functional

Code

public function testPageContextTopBarItemNode() : void {
  // Create a published node entity.
  $node = $this->createNode([
    'type' => 'article',
    'title' => 'No easy twist on the bow',
    'status' => 1,
    'uid' => $this->adminUser
      ->id(),
  ]);
  $test_page_url = Url::fromRoute('test_page_test.test_page');
  $this->drupalGet($test_page_url);
  // Ensure the top bar item is not present.
  $this->assertSession()
    ->elementNotExists('css', '.top-bar .top-bar__context .toolbar-title');
  // Test the PageContext output for the published node.
  $this->drupalGet($node->toUrl());
  // Ensure the top bar exists and is valid.
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-title', 'No easy twist on the bow');
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-badge', 'Published');
  $this->drupalGet($node->toUrl('edit-form'));
  // Ensure the top bar exists and is valid.
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-title', 'No easy twist on the bow');
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-badge', 'Published');
  // Unpublish the node.
  $node->setUnpublished();
  $node->save();
  // Test the PageContext output for the unpublished node.
  $this->drupalGet($node->toUrl());
  // Ensure the top bar exists and is valid.
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-title', 'No easy twist on the bow');
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-badge', 'Unpublished');
  $this->drupalGet($node->toUrl('edit-form'));
  // Ensure the top bar exists and is valid.
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-title', 'No easy twist on the bow');
  $this->assertSession()
    ->elementTextEquals('css', '.top-bar .top-bar__context .toolbar-badge', 'Unpublished');
}

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