'Entity Source UI tests',
'description' => 'Tests the user interface for entity translation sources.',
'group' => 'Translation Management',
'dependencies' => array('entity_translation'),
);
}
function setUp() {
parent::setUp(array('tmgmt_entity_ui', 'block', 'comment'));
variable_set('language_content_type_page', ENTITY_TRANSLATION_ENABLED);
variable_set('language_content_type_article', ENTITY_TRANSLATION_ENABLED);
$this->loginAsAdmin(array(
'create translation jobs',
'submit translation jobs',
'accept translation jobs',
'administer blocks',
'administer entity translation',
'toggle field translatability',
));
$this->setEnvironment('de');
$this->setEnvironment('fr');
$this->setEnvironment('es');
$this->setEnvironment('el');
$this->createNodeType('page', st('Page'), ENTITY_TRANSLATION_ENABLED);
$this->createNodeType('article', st('Article'), ENTITY_TRANSLATION_ENABLED);
// Enable path locale detection.
$edit = array(
'language[enabled][locale-url]' => TRUE,
'language_content[enabled][locale-interface]' => TRUE,
);
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
// @todo Re-enable this when switching to testing profile.
// Enable the main page content block for hook_page_alter() to work.
$edit = array(
'blocks[system_main][region]' => 'content',
);
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
}
/**
* Test the translate tab for a single checkout.
*/
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);
}
/**
* Test the translate tab for a single checkout.
*/
function testNodeTranslateTabMultipeCheckout() {
// Allow auto-accept.
$default_translator = tmgmt_translator_load('test_translator');
$default_translator->settings = array(
'auto_accept' => TRUE,
);
$default_translator->save();
$this->loginAsTranslator(array('translate node entities'));
// Create an english source node.
$node = $this->createNode('page', 'en');
// 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,
'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($node->title);
$this->drupalPost(NULL, array(), t('Submit to translator and continue'));
$this->assertText($node->title);
$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->assertNoText(t('The translation of @title to @language is finished and can now be reviewed.', array('@title' => $node->title, '@language' => t('Spanish'))));
$this->assertText(t('The translation for @title has been accepted.', array('@title' => $node->title)));
// Translated nodes should now be listed and be clickable.
// @todo Use links on translate tab.
$this->drupalGet('de/node/' . $node->nid);
$this->assertText('de_' . $node->body['en'][0]['value']);
$this->drupalGet('es/node/' . $node->nid);
$this->assertText('es_' . $node->body['en'][0]['value']);
}
/**
* Test translating comments.
*
* @todo: Disabled pending resolution of http://drupal.org/node/1760270.
*/
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']);
}
/**
* Test the entity source specific cart functionality.
*/
function testCart() {
$this->loginAsTranslator(array('translate node entities'));
$nodes = array();
for ($i = 0; $i < 4; $i++) {
$nodes[$i] = $this->createNode('page');
}
// Test the source overview.
$this->drupalGet('admin/tmgmt/sources/entity');
$this->drupalPost('admin/tmgmt/sources/entity', array(
'items[' . $nodes[1]->nid . ']' => TRUE,
'items[' . $nodes[2]->nid . ']' => TRUE,
), t('Add to cart'));
$this->drupalGet('admin/tmgmt/cart');
$this->assertText($nodes[1]->title);
$this->assertText($nodes[2]->title);
// Test the translate tab.
$this->drupalGet('node/' . $nodes[3]->nid . '/translate');
$this->assertRaw(t('There are @count items in the translation cart.',
array('@count' => 2, '@url' => url('admin/tmgmt/cart'))));
$this->drupalPost(NULL, array(), t('Add to cart'));
$this->assertRaw(t('@count content source was added into the cart.', array('@count' => 1, '@url' => url('admin/tmgmt/cart'))));
$this->assertRaw(t('There are @count items in the translation cart including the current item.',
array('@count' => 3, '@url' => url('admin/tmgmt/cart'))));
}
}