function NodeTypeInitialLanguageTest::testNodeTypeInitialLanguageDefaults

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

Tests the node type initial language defaults, and modifies them.

The default initial language must be the site's default, and the language locked option must be on.

File

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

Class

NodeTypeInitialLanguageTest
Tests node type initial language settings.

Namespace

Drupal\Tests\node\Functional

Code

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');
    // Tests if the language field cannot be rearranged on the manage fields tab.
    $this->drupalGet('admin/structure/types/manage/article/fields');
    $this->assertSession()
        ->elementNotExists('xpath', '//*[@id="field-overview"]/*[@id="language"]');
    // Verify that language is not selectable on node add page by default.
    $this->drupalGet('node/add/article');
    $this->assertSession()
        ->fieldNotExists('langcode');
    // Adds a new language and set it as default.
    $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');
    // Tests the initial language after changing the site default language.
    // First unhide the language selector.
    $edit = [
        'language_configuration[language_alterable]' => TRUE,
    ];
    $this->drupalGet('admin/structure/types/manage/article');
    $this->submitForm($edit, 'Save content type');
    $this->drupalGet('node/add/article');
    // Ensure that the language is selectable on node add page when language
    // not hidden.
    $this->assertSession()
        ->fieldExists('langcode[0][value]');
    $this->assertTrue($this->assertSession()
        ->optionExists('edit-langcode-0-value', 'hu')
        ->isSelected());
    // Tests if the language field can be rearranged on the manage form display
    // tab.
    $this->drupalGet('admin/structure/types/manage/article/form-display');
    $this->assertSession()
        ->elementExists('xpath', '//*[@id="langcode"]');
    // Tests if the language field can be rearranged on the manage display tab.
    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertSession()
        ->elementExists('xpath', '//*[@id="langcode"]');
    // Tests if the language field is hidden by default.
    $this->assertTrue($this->assertSession()
        ->optionExists('edit-fields-langcode-region', 'hidden')
        ->isSelected());
    // Changes the initial language settings.
    $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());
}

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