NodeViewLanguageTest.php

Same filename in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeViewLanguageTest.php
  2. 8.9.x core/modules/node/tests/src/Functional/NodeViewLanguageTest.php
  3. 10 core/modules/node/tests/src/Functional/NodeViewLanguageTest.php

Namespace

Drupal\Tests\node\Functional

File

core/modules/node/tests/src/Functional/NodeViewLanguageTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\node\Functional;

use Drupal\language\Entity\ConfigurableLanguage;

/**
 * Tests the node language extra field display.
 *
 * @group node
 */
class NodeViewLanguageTest extends NodeTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
        'datetime',
        'language',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests the language extra field display.
     */
    public function testViewLanguage() : void {
        // Add Spanish language.
        ConfigurableLanguage::createFromLangcode('es')->save();
        // Set language field visible.
        \Drupal::service('entity_display.repository')->getViewDisplay('node', 'page', 'full')
            ->setComponent('langcode')
            ->save();
        // Create a node in Spanish.
        $node = $this->drupalCreateNode([
            'langcode' => 'es',
        ]);
        $this->drupalGet($node->toUrl());
        $this->assertSession()
            ->pageTextContains('Spanish');
    }

}

Classes

Title Deprecated Summary
NodeViewLanguageTest Tests the node language extra field display.

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