You are here

public function BreadcrumbExtraFieldTest::testDisplayVisivility in Breadcrumb Extra Field 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/BreadcrumbExtraFieldTest.php \Drupal\Tests\breadcrumb_extra_field\Functional\BreadcrumbExtraFieldTest::testDisplayVisivility()

Tests display visibility.

File

tests/src/Functional/BreadcrumbExtraFieldTest.php, line 90

Class

BreadcrumbExtraFieldTest
Tests for breadcrumb extra field.

Namespace

Drupal\Tests\breadcrumb_extra_field\Functional

Code

public function testDisplayVisivility() {

  // Create a node.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->drupalGet('node/' . $node
    ->id());

  // Check visibility before everything.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//article[contains(@class, "node--type-article") and contains(.//nav, "Breadcrumb")]');
  $account = $this
    ->drupalCreateUser([
    'administer breadcrumb extra field',
  ], NULL, TRUE);
  $this
    ->drupalLogin($account);

  // Enable to articles.
  $this
    ->drupalGet('admin/config/system/breadcrumb-extra-field');
  $this
    ->submitForm([
    'Article' => TRUE,
  ], 'Save configuration');

  // Clear cache required.
  $this
    ->resetAll();
  $this
    ->drupalLogout();

  // Check visibility after module configuration but before display
  // configuration.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//article[contains(@class, "node--type-article") and contains(.//nav, "Breadcrumb")]');

  // Make breadcrumb visible.
  $display = \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'article', 'default');
  $display
    ->setComponent('breadcrumb', [
    'region' => 'content',
  ]);
  $display
    ->save();

  // Check visibility.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->elementExists('xpath', '//article[contains(@class, "node--type-article") and contains(.//nav, "Breadcrumb")]');
}