View source
<?php
namespace Drupal\Tests\breadcrumb_extra_field\Functional;
use Drupal\Tests\BrowserTestBase;
class BreadcrumbExtraFieldTest extends BrowserTestBase {
protected $defaultTheme = 'classy';
protected static $modules = [
'field',
'field_ui',
'node',
'breadcrumb_extra_field',
];
public function setUp() {
parent::setUp();
$type = $this->container
->get('entity_type.manager')
->getStorage('node_type')
->create([
'type' => 'article',
'name' => 'Article',
]);
$type
->save();
$this->container
->get('router.builder')
->rebuild();
}
public function testAdminUi() {
$account = $this
->drupalCreateUser();
$this
->drupalLogin($account);
$this
->drupalGet('admin/config/system/breadcrumb-extra-field');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogout();
$account = $this
->drupalCreateUser([
'administer breadcrumb extra field',
], NULL, TRUE);
$this
->drupalLogin($account);
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->elementNotExists('xpath', '//tr[@data-drupal-selector="edit-fields-breadcrumb"]');
$this
->drupalGet('admin/config/system/breadcrumb-extra-field');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldExists('Article');
$this
->submitForm([
'Article' => TRUE,
], 'Save configuration');
$this
->resetAll();
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->elementExists('xpath', '//tr[@data-drupal-selector="edit-fields-breadcrumb"]');
$this
->assertSession()
->elementTextContains('css', '.entity-view-display-edit-form', 'Breadcrumb');
}
public function testDisplayVisivility() {
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalGet('node/' . $node
->id());
$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);
$this
->drupalGet('admin/config/system/breadcrumb-extra-field');
$this
->submitForm([
'Article' => TRUE,
], 'Save configuration');
$this
->resetAll();
$this
->drupalLogout();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->elementNotExists('xpath', '//article[contains(@class, "node--type-article") and contains(.//nav, "Breadcrumb")]');
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', 'article', 'default');
$display
->setComponent('breadcrumb', [
'region' => 'content',
]);
$display
->save();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->elementExists('xpath', '//article[contains(@class, "node--type-article") and contains(.//nav, "Breadcrumb")]');
}
}