function NodeTypeInitialLanguageTest::testLanguageFieldVisibility
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php \Drupal\Tests\node\Functional\NodeTypeInitialLanguageTest::testLanguageFieldVisibility()
- 10 core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php \Drupal\Tests\node\Functional\NodeTypeInitialLanguageTest::testLanguageFieldVisibility()
- 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 104
Class
- NodeTypeInitialLanguageTest
- Tests node type initial language settings.
Namespace
Drupal\Tests\node\FunctionalCode
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->drupalPostForm('node/add/article', $edit, t('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());
$language_field = $this->xpath('//div[@id=:id]/div', [
':id' => 'field-language-display',
]);
$this->assertTrue(empty($language_field), 'Language field value is not shown by default on node page.');
// Configures Language field formatter and check if it is saved.
$edit = [
'fields[langcode][type]' => 'language',
'fields[langcode][region]' => 'content',
];
$this->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));
$this->drupalGet('admin/structure/types/manage/article/display');
$this->assertOptionSelected('edit-fields-langcode-type', 'language', 'Language field has been set to visible.');
// Loads node page and check if Language field is shown.
$this->drupalGet('node/' . $node->id());
$language_field = $this->xpath('//div[@id=:id]/div', [
':id' => 'field-language-display',
]);
$this->assertFalse(empty($language_field), 'Language field value is shown on node page.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.