You are here

function TMGMTEntitySourceUITestCase::dtestCommentTranslateTab in Translation Management Tool 7

Test translating comments.

@todo: Disabled pending resolution of http://drupal.org/node/1760270.

File

sources/entity/ui/tmgmt_entity_ui.test, line 217

Class

TMGMTEntitySourceUITestCase
Basic Node Source tests.

Code

function dtestCommentTranslateTab() {

  // Login as admin to be able to submit config page.
  $this
    ->loginAsAdmin(array(
    'administer entity translation',
  ));

  // Enable comment translation.
  $edit = array(
    'entity_translation_entity_types[comment]' => TRUE,
  );
  $this
    ->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration'));

  // Change comment_body field to be translatable.
  $comment_body = field_info_field('comment_body');
  $comment_body['translatable'] = TRUE;
  field_update_field($comment_body);

  // Create a user that is allowed to translate comments.
  $permissions = array(
    'translate comment entities',
    'create translation jobs',
    'submit translation jobs',
    'accept translation jobs',
    'post comments',
    'skip comment approval',
    'edit own comments',
    'access comments',
  );
  $entity_translation_permissions = entity_translation_permission();

  // The new translation edit form of entity_translation requires a new
  // permission that does not yet exist in older versions. Add it
  // conditionally.
  if (isset($entity_translation_permissions['edit original values'])) {
    $permissions[] = 'edit original values';
  }
  $this
    ->loginAsTranslator($permissions, TRUE);

  // Create an english source term.
  $node = $this
    ->createNode('article', 'en');

  // Add a comment.
  $this
    ->drupalGet('node/' . $node->nid);
  $edit = array(
    'subject' => $this
      ->randomName(),
    'comment_body[en][0][value]' => $this
      ->randomName(),
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertText(t('Your comment has been posted.'));

  // Go to the translate tab.
  $this
    ->clickLink('edit');
  $this
    ->assertTrue(preg_match('|comment/(\\d+)/edit$|', $this
    ->getUrl(), $matches), 'Comment found');
  $comment = comment_load($matches[1]);
  $this
    ->clickLink('Translate');

  // Assert some basic strings on that page.
  $this
    ->assertText(t('Translations of @title', array(
    '@title' => $comment->subject,
  )));
  $this
    ->assertText(t('Pending Translations'));

  // Request a translation for german.
  $edit = array(
    'languages[de]' => TRUE,
    'languages[es]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Request translation'));

  // Verify that we are on the translate tab.
  $this
    ->assertText(t('2 jobs need to be checked out.'));

  // Submit all jobs.
  $this
    ->assertText($comment->subject);
  $this
    ->drupalPost(NULL, array(), t('Submit to translator and continue'));
  $this
    ->assertText($comment->subject);
  $this
    ->drupalPost(NULL, array(), t('Submit to translator'));

  // Make sure that we're back on the translate tab.
  $this
    ->assertEqual(url('comment/' . $comment->cid . '/translate', array(
    'absolute' => TRUE,
  )), $this
    ->getUrl());
  $this
    ->assertText(t('Test translation created.'));
  $this
    ->assertNoText(t('The translation of @title to @language is finished and can now be reviewed.', array(
    '@title' => $comment->subject,
    '@language' => t('Spanish'),
  )));
  $this
    ->assertText(t('The translation for @title has been accepted.', array(
    '@title' => $comment->subject,
  )));

  // @todo Use links on translate tab.
  $this
    ->drupalGet('de/comment/' . $comment->cid);
  $this
    ->assertText('de_' . $comment->comment_body['en'][0]['value']);

  // @todo Use links on translate tab.
  $this
    ->drupalGet('es/node/' . $comment->cid);
  $this
    ->assertText('es_' . $comment->comment_body['en'][0]['value']);
}