function LayoutBuilderDefaultValuesTest::assertNodeWithDefaultValues

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::assertNodeWithDefaultValues()
  2. 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::assertNodeWithDefaultValues()

Test for expected text on node 2.

1 call to LayoutBuilderDefaultValuesTest::assertNodeWithDefaultValues()
LayoutBuilderDefaultValuesTest::testDefaultValues in core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php
Tests display of default field values.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php, line 168

Class

LayoutBuilderDefaultValuesTest
Tests rendering default field values in Layout Builder.

Namespace

Drupal\Tests\layout_builder\Functional

Code

protected function assertNodeWithDefaultValues() : void {
    // Switch theme to starterkit_theme so that layout builder components will
    // have block classes.
    
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = $this->container
        ->get('theme_installer');
    $theme_installer->install([
        'starterkit_theme',
    ]);
    $this->config('system.theme')
        ->set('default', 'starterkit_theme')
        ->save();
    $this->drupalGet('node/2');
    $assert_session = $this->assertSession();
    // String field with no default should not render.
    $assert_session->pageTextNotContains('field_string_no_default');
    // String with default value should render with default value.
    $assert_session->pageTextContains('field_string');
    $assert_session->pageTextContains('This is my default value');
    // String field with callback should render value from callback.
    $assert_session->pageTextContains('field_string_with_callback');
    $assert_session->pageTextContains('This is from my default value callback');
    // String field with "late" default should not render.
    $assert_session->pageTextNotContains('field_string_late_default');
    $assert_session->pageTextNotContains('Too late!');
    // Image field with default should render default value.
    $assert_session->pageTextContains('field_image_storage_default');
    $assert_session->responseContains('My storage default alt text');
    $assert_session->responseContains('test-file-1');
    $assert_session->pageTextContains('field_image_instance_default');
    $assert_session->responseContains('My instance default alt text');
    $assert_session->responseContains('test-file-1');
    $assert_session->pageTextContains('field_image_both_defaults');
    $assert_session->responseContains('My instance default alt text');
    $assert_session->responseContains('test-file-2');
    // Image field with no default should not render.
    $assert_session->pageTextNotContains('field_image_no_default');
    // Confirm that there is no DOM element for the field_image_with_no_default
    // field block.
    $assert_session->elementNotExists('css', '.block-field-blocknodetest-node-typefield-image-no-default');
}

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