You are here

function TMGMTEntitySourceUITestCase::testNodeTranslateTabSingleCheckout in Translation Management Tool 7

Test the translate tab for a single checkout.

File

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

Class

TMGMTEntitySourceUITestCase
Basic Node Source tests.

Code

function testNodeTranslateTabSingleCheckout() {
  $this
    ->loginAsTranslator(array(
    'translate node entities',
  ));

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

  // Create a nodes that will not be translated to test the missing
  // translation filter.
  $node_not_translated = $this
    ->createNode('page', 'en');
  $node_german = $this
    ->createNode('page', 'de');

  // Go to the translate tab.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->clickLink('Translate');

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

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

  // Verify that we are on the translate tab.
  $this
    ->assertText(t('One job needs to be checked out.'));
  $this
    ->assertText($node->title);

  // Submit.
  $this
    ->drupalPost(NULL, array(), t('Submit to translator'));

  // Make sure that we're back on the translate tab.
  $this
    ->assertEqual(url('node/' . $node->nid . '/translate', array(
    'absolute' => TRUE,
  )), $this
    ->getUrl());
  $this
    ->assertText(t('Test translation created.'));
  $this
    ->assertText(t('The translation of @title to @language is finished and can now be reviewed.', array(
    '@title' => $node->title,
    '@language' => t('German'),
  )));

  // Verify that the pending translation is shown.
  $this
    ->clickLink(t('Needs review'));
  $this
    ->drupalPost(NULL, array(), t('Save as completed'));
  $this
    ->assertText(t('The translation for @title has been accepted.', array(
    '@title' => $node->title,
  )));

  // German node should now be listed and be clickable.
  // @todo Improve detection of the link, e.g. use xpath on the table or the
  // title module to get a better title.
  $this
    ->clickLink('view', 1);
  $this
    ->assertText('de_' . $node->body['en'][0]['value']);

  // Test that the destination query argument does not break the redirect
  // and we are redirected back to the correct page.
  $this
    ->drupalGet('node/' . $node->nid . '/translate', array(
    'query' => array(
      'destination' => 'node',
    ),
  ));

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

  // Verify that we are on the checkout page.
  $this
    ->assertText(t('One job needs to be checked out.'));
  $this
    ->assertText($node->title);
  $this
    ->drupalPost(NULL, array(), t('Submit to translator'));

  // Make sure that we're back on the originally defined destination URL.
  $this
    ->assertEqual(url('node', array(
    'absolute' => TRUE,
  )), $this
    ->getUrl());

  // Test the missing translation filter.
  $this
    ->drupalGet('admin/tmgmt/sources');
  $this
    ->assertText($node->title);
  $this
    ->assertText($node_not_translated->title);
  $this
    ->drupalPost(NULL, array(
    'search[target_language]' => 'de',
    'search[target_status]' => 'untranslated',
  ), t('Search'));
  $this
    ->assertNoText($node->title);
  $this
    ->assertNoText($node_german->title);
  $this
    ->assertText($node_not_translated->title);

  // Update the the translate flag of the translated node and test if it is
  // listed among sources with missing translation.
  db_update('entity_translation')
    ->fields(array(
    'translate' => 1,
  ))
    ->condition('entity_type', 'node')
    ->condition('entity_id', $node->nid)
    ->execute();
  $this
    ->drupalPost(NULL, array(
    'search[target_language]' => 'de',
    'search[target_status]' => 'outdated',
  ), t('Search'));
  $this
    ->assertText($node->title);
  $this
    ->assertNoText($node_german->title);
  $this
    ->assertNoText($node_not_translated->title);
  $this
    ->drupalPost(NULL, array(
    'search[target_language]' => 'de',
    'search[target_status]' => 'untranslated_or_outdated',
  ), t('Search'));
  $this
    ->assertText($node->title);
  $this
    ->assertNoText($node_german->title);
  $this
    ->assertText($node_not_translated->title);
}