1 locale.test LocaleCommentLanguageFunctionalTest::testCommentLanguage()

Test that comment language is properly set.

File

core/modules/locale/tests/locale.test, line 2668
Tests for locale.module.

Class

LocaleCommentLanguageFunctionalTest
Functional tests for comment language.

Code

function testCommentLanguage() {
  backdrop_static_reset('language_list');

  // Create two nodes, one for english and one for french, and comment each
  // node using both english and french as content language by changing URL
  // language prefixes. Meanwhile interface language is always French, which
  // is the user language preference. This way we can ensure that node
  // language and interface language do not influence comment language, as
  // only content language has to.
  foreach (language_list() as $node_langcode => $node_language) {
    $langcode_none = LANGUAGE_NONE;

    // Create "Post" content.
    $title = $this->randomName();
    $edit = array(
      "title" => $title,
      "body[$langcode_none][0][value]" => $this->randomName(),
      "langcode" => $node_langcode,
    );
    $this->backdropPost("node/add/post", $edit, t('Save'));
    $node = $this->backdropGetNodeByTitle($title);

    $prefixes = locale_language_negotiation_url_prefixes();
    foreach (language_list() as $langcode => $language) {
      // Post a comment with content language $langcode.
      $prefix = empty($prefixes[$langcode]) ? '' : $prefixes[$langcode] . '/';
      $edit = array("comment_body[$langcode_none][0][value]" => $this->randomName());
      $this->backdropPost("{$prefix}node/{$node->nid}", $edit, t('Save'));

      // Check that comment language matches the current content language.
      $comment = db_select('comment', 'c')
        ->fields('c')
        ->condition('nid', $node->nid)
        ->orderBy('cid', 'DESC')
        ->execute()
        ->fetchObject();
      $args = array('%node_language' => $node_langcode, '%comment_language' => $comment->langcode, '%langcode' => $langcode);
      $this->assertEqual($comment->langcode, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
    }
  }
}