View source
<?php
namespace Drupal\Tests\layout_builder_operation_link\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class OperationLinkTest extends BrowserTestBase {
use TaxonomyTestTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'layout_builder_operation_link',
'node',
'taxonomy',
];
public function testOperationLink() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$auth_user = $this
->drupalCreateUser([
'access administration pages',
'access content overview',
'access taxonomy overview',
'administer taxonomy',
'bypass node access',
]);
$layout_user = $this
->drupalCreateUser([
'access administration pages',
'access content overview',
'access taxonomy overview',
'administer taxonomy',
'administer node display',
'administer node fields',
'administer taxonomy_term display',
'administer taxonomy_term fields',
'bypass node access',
'configure any layout',
]);
$this
->drupalLogin($layout_user);
$this
->createContentType([
'type' => 'page',
]);
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$this
->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$this
->createNode([
'type' => 'page',
]);
$this
->createNode([
'type' => 'bundle_with_section_field',
]);
$vocabulary = $this
->createVocabulary();
$vocabulary_with_section_field = $this
->createVocabulary();
$this
->createTerm($vocabulary);
$this
->createTerm($vocabulary_with_section_field);
$vocabulary_id = $vocabulary
->id();
$vocabulary_with_section_field_id = $vocabulary_with_section_field
->id();
$this
->drupalGet("admin/structure/taxonomy/manage/{$vocabulary_with_section_field_id}/overview/display");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$this
->drupalGet('/admin/content');
$assert_session
->elementNotExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "node/1/layout")]');
$assert_session
->elementExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "node/2/layout")]');
$this
->drupalGet("admin/structure/taxonomy/manage/{$vocabulary_id}/overview/");
$assert_session
->elementNotExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "term/1/layout")]');
$this
->drupalGet("admin/structure/taxonomy/manage/{$vocabulary_with_section_field_id}/overview/");
$assert_session
->elementExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "term/2/layout")]');
$this
->drupalLogin($auth_user);
$this
->drupalGet('/admin/content');
$assert_session
->elementNotExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "node/2/layout")]');
$this
->drupalGet("admin/structure/taxonomy/manage/{$vocabulary_id}/overview/");
$assert_session
->elementNotExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "term/1/layout")]');
$this
->drupalGet("admin/structure/taxonomy/manage/{$vocabulary_with_section_field_id}/overview/");
$assert_session
->elementNotExists('xpath', '//table//ul[contains(@class, "dropbutton")]//a[contains(@href, "term/2/layout")]');
}
}