You are here

protected function CommentLanguageTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Tests/CommentLanguageTest.php \Drupal\comment\Tests\CommentLanguageTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides WebTestBase::setUp

File

core/modules/comment/src/Tests/CommentLanguageTest.php, line 35
Contains \Drupal\comment\Tests\CommentLanguageTest.

Class

CommentLanguageTest
Tests for comment language.

Namespace

Drupal\comment\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalCreateContentType(array(
    'type' => 'article',
    'name' => 'Article',
  ));

  // Create and login user.
  $admin_user = $this
    ->drupalCreateUser(array(
    '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 = array(
    'predefined_langcode' => 'fr',
  );
  $this
    ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

  // Set "Article" content type to use multilingual support.
  $edit = array(
    '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 = array(
    '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 = array(
    '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.');
}