function NodeTypeInitialLanguageTest::testLanguageFieldVisibility

Same name in other branches
  1. 8.9.x core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php \Drupal\Tests\node\Functional\NodeTypeInitialLanguageTest::testLanguageFieldVisibility()
  2. 10 core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php \Drupal\Tests\node\Functional\NodeTypeInitialLanguageTest::testLanguageFieldVisibility()
  3. 11.x core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php \Drupal\Tests\node\Functional\NodeTypeInitialLanguageTest::testLanguageFieldVisibility()

Tests language field visibility features.

File

core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php, line 112

Class

NodeTypeInitialLanguageTest
Tests node type initial language settings.

Namespace

Drupal\Tests\node\Functional

Code

public function testLanguageFieldVisibility() {
    // Creates a node to test Language field visibility feature.
    $edit = [
        'title[0][value]' => $this->randomMachineName(8),
        'body[0][value]' => $this->randomMachineName(16),
    ];
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, 'Save');
    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->assertNotEmpty($node, 'Node found in database.');
    // Loads node page and check if Language field is hidden by default.
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->elementNotExists('xpath', '//div[@id="field-language-display"]/div');
    // Configures Language field formatter and check if it is saved.
    $edit = [
        'fields[langcode][type]' => 'language',
        'fields[langcode][region]' => 'content',
    ];
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->submitForm($edit, 'Save');
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertTrue($this->assertSession()
        ->optionExists('edit-fields-langcode-type', 'language')
        ->isSelected());
    // Loads node page and check if Language field is shown.
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->elementExists('xpath', '//div[@id="field-language-display"]/div');
}

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