class LayoutBuilderThemeSuggestionsTest
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderThemeSuggestionsTest
- 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderThemeSuggestionsTest
- 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderThemeSuggestionsTest
Tests template suggestions.
@group layout_builder
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\layout_builder\Functional\LayoutBuilderThemeSuggestionsTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of LayoutBuilderThemeSuggestionsTest
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderThemeSuggestionsTest.php, line 13
Namespace
Drupal\Tests\layout_builder\FunctionalView source
class LayoutBuilderThemeSuggestionsTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'layout_builder',
'node',
'layout_builder_theme_suggestions_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')->enableLayoutBuilder()
->setOverridable()
->save();
$this->createNode([
'type' => 'bundle_with_section_field',
'title' => 'A node title',
'body' => [
[
'value' => 'This is content that the template should not render',
],
],
]);
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
]));
}
/**
* Tests alterations of the layout list via preprocess functions.
*/
public function testLayoutListSuggestion() {
$page = $this->getSession()
->getPage();
$assert_session = $this->assertSession();
$this->drupalGet('node/1/layout');
$page->clickLink('Add section');
$assert_session->pageTextContains('layout_builder_theme_suggestions_test_preprocess_item_list__layouts');
}
/**
* Tests that of view mode specific field templates are suggested.
*/
public function testFieldBlockViewModeTemplates() {
$assert_session = $this->assertSession();
$this->drupalGet('node/1');
// Confirm that content is displayed by layout builder.
$assert_session->elementExists('css', '.block-layout-builder');
// Text that only appears in the view mode specific template.
$assert_session->pageTextContains('I am a field template for a specific view mode!');
// The content of the body field should not be visible because it is
// displayed via a template that does not render it.
$assert_session->pageTextNotContains('This is content that the template should not render');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.