function NodeTitleTestBase::testNodeWithTitle0

Same name in other branches
  1. 11.x core/modules/system/tests/src/Functional/Theme/NodeTitleTestBase.php \Drupal\Tests\system\Functional\Theme\NodeTitleTestBase::testNodeWithTitle0()

Creates one node with title 0 and tests if the node title has the correct value.

File

core/modules/system/tests/src/Functional/Theme/NodeTitleTestBase.php, line 53

Class

NodeTitleTestBase
Tests node title for a theme.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testNodeWithTitle0() : void {
    $theme = $this->getTheme();
    if ($theme !== $this->defaultTheme) {
        $system_theme_config = $this->container
            ->get('config.factory')
            ->getEditable('system.theme');
        $system_theme_config->set('default', $theme)
            ->save();
        \Drupal::service('theme_installer')->install([
            $theme,
        ]);
    }
    // Create "Basic page" content with title 0.
    $settings = [
        'title' => 0,
    ];
    $node = $this->drupalCreateNode($settings);
    // Test that 0 appears as <title>.
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->titleEquals('0 | Drupal');
    // Test that 0 appears in the template <h1>.
    $this->assertSession()
        ->elementTextEquals('xpath', '//h1', '0');
}

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