LocaleCommentLanguageFunctionalTest::testCommentLanguage

7 locale.test LocaleCommentLanguageFunctionalTest::testCommentLanguage()
8 locale.test LocaleCommentLanguageFunctionalTest::testCommentLanguage()

Test that comment language is properly set.

File

modules/locale/locale.test, line 2756
Tests for locale.module.

Code

function testCommentLanguage() {
  drupal_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) {
    $language_none = LANGUAGE_NONE;

    // Create "Article" content.
    $title = $this->randomName();
    $edit = array(
      "title" => $title, 
      "body[$language_none][0][value]" => $this->randomName(), 
      "language" => $node_langcode,
    );
    $this->drupalPost("node/add/article", $edit, t('Save'));
    $node = $this->drupalGetNodeByTitle($title);

    foreach (language_list() as $langcode => $language) {
      // Post a comment with content language $langcode.
      $prefix = empty($language->prefix) ? '' : $language->prefix . '/';
      $edit = array("comment_body[$language_none][0][value]" => $this->randomName());
      $this->drupalPost("{$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->language,
        '%langcode' => $langcode,
      );
      $this->assertEqual($comment->language, $langcode, t('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
    }
  }
}
Login or register to post comments