View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Language\LanguageInterface;
class NodeTypeInitialLanguageTest extends NodeTestBase {
protected static $modules = [
'language',
'field_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
'administer node form display',
'administer node display',
'administer languages',
]);
$this
->drupalLogin($web_user);
}
public function testNodeTypeInitialLanguageDefaults() {
$this
->drupalGet('admin/structure/types/manage/article');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-language-configuration-langcode', LanguageInterface::LANGCODE_SITE_DEFAULT)
->isSelected());
$this
->assertSession()
->checkboxNotChecked('edit-language-configuration-language-alterable');
$this
->drupalGet('admin/structure/types/manage/article/fields');
$this
->assertSession()
->elementNotExists('xpath', '//*[@id="field-overview"]/*[@id="language"]');
$this
->drupalGet('node/add/article');
$this
->assertSession()
->fieldNotExists('langcode');
$edit = [
'predefined_langcode' => 'hu',
];
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$edit = [
'site_default_language' => 'hu',
];
$this
->drupalGet('admin/config/regional/language');
$this
->submitForm($edit, 'Save configuration');
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$this
->drupalGet('admin/structure/types/manage/article');
$this
->submitForm($edit, 'Save content type');
$this
->drupalGet('node/add/article');
$this
->assertSession()
->fieldExists('langcode[0][value]');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-langcode-0-value', 'hu')
->isSelected());
$this
->drupalGet('admin/structure/types/manage/article/form-display');
$this
->assertSession()
->elementExists('xpath', '//*[@id="langcode"]');
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertSession()
->elementExists('xpath', '//*[@id="langcode"]');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-fields-langcode-region', 'hidden')
->isSelected());
$edit = [
'language_configuration[langcode]' => 'en',
];
$this
->drupalGet('admin/structure/types/manage/article');
$this
->submitForm($edit, 'Save content type');
$this
->drupalGet('node/add/article');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-langcode-0-value', 'en')
->isSelected());
}
public function testLanguageFieldVisibility() {
$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.');
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->elementNotExists('xpath', '//div[@id="field-language-display"]/div');
$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());
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->elementExists('xpath', '//div[@id="field-language-display"]/div');
}
}