function CommentLanguageTest::setUp

Same name in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()
  2. 10 core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()
  3. 11.x core/modules/comment/tests/src/Functional/CommentLanguageTest.php \Drupal\Tests\comment\Functional\CommentLanguageTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/comment/tests/src/Functional/CommentLanguageTest.php, line 42

Class

CommentLanguageTest
Tests for comment language.

Namespace

Drupal\Tests\comment\Functional

Code

protected function setUp() {
    parent::setUp();
    $this->drupalCreateContentType([
        'type' => 'article',
        'name' => 'Article',
    ]);
    // Create and log in user.
    $admin_user = $this->drupalCreateUser([
        'administer site configuration',
        'administer languages',
        'access administration pages',
        'administer content types',
        'administer comments',
        'create article content',
        'access comments',
        'post comments',
        'skip comment approval',
    ]);
    $this->drupalLogin($admin_user);
    // Add language.
    $edit = [
        'predefined_langcode' => 'fr',
    ];
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
    // Set "Article" content type to use multilingual support.
    $edit = [
        'language_configuration[language_alterable]' => TRUE,
    ];
    $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
    // Enable content language negotiation UI.
    \Drupal::state()->set('language_test.content_language_type', TRUE);
    // Set interface language detection to user and content language detection
    // to URL. Disable inheritance from interface language to ensure content
    // language will fall back to the default language if no URL language can be
    // detected.
    $edit = [
        'language_interface[enabled][language-user]' => TRUE,
        'language_content[enabled][language-url]' => TRUE,
        'language_content[enabled][language-interface]' => FALSE,
    ];
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
    // Change user language preference, this way interface language is always
    // French no matter what path prefix the URLs have.
    $edit = [
        'preferred_langcode' => 'fr',
    ];
    $this->drupalPostForm("user/" . $admin_user->id() . "/edit", $edit, t('Save'));
    // Create comment field on article.
    $this->addDefaultCommentField('node', 'article');
    // Make comment body translatable.
    $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
    $field_storage->setTranslatable(TRUE);
    $field_storage->save();
    $this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.');
}

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