View source
<?php
class TMGMTEntitySourceUITestCase extends TMGMTEntityTestCaseUtility {
static function getInfo() {
return array(
'name' => '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);
$edit = array(
'language[enabled][locale-url]' => TRUE,
'language_content[enabled][locale-interface]' => TRUE,
);
$this
->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
$edit = array(
'blocks[system_main][region]' => 'content',
);
$this
->drupalPost('admin/structure/block', $edit, t('Save blocks'));
}
function testNodeTranslateTabSingleCheckout() {
$this
->loginAsTranslator(array(
'translate node entities',
));
$node = $this
->createNode('page', 'en');
$node_not_translated = $this
->createNode('page', 'en');
$node_german = $this
->createNode('page', 'de');
$this
->drupalGet('node/' . $node->nid);
$this
->clickLink('Translate');
$this
->assertText(t('Translations of @title', array(
'@title' => $node->title,
)));
$this
->assertText(t('Pending Translations'));
$edit = array(
'languages[de]' => TRUE,
);
$this
->drupalPost(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText($node->title);
$this
->drupalPost(NULL, array(), t('Submit to translator'));
$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'),
)));
$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,
)));
$this
->clickLink('view', 1);
$this
->assertText('de_' . $node->body['en'][0]['value']);
$this
->drupalGet('node/' . $node->nid . '/translate', array(
'query' => array(
'destination' => 'node',
),
));
$edit = array(
'languages[es]' => TRUE,
);
$this
->drupalPost(NULL, $edit, t('Request translation'));
$this
->assertText(t('One job needs to be checked out.'));
$this
->assertText($node->title);
$this
->drupalPost(NULL, array(), t('Submit to translator'));
$this
->assertEqual(url('node', array(
'absolute' => TRUE,
)), $this
->getUrl());
$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);
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);
}
function testNodeTranslateTabMultipeCheckout() {
$default_translator = tmgmt_translator_load('test_translator');
$default_translator->settings = array(
'auto_accept' => TRUE,
);
$default_translator
->save();
$this
->loginAsTranslator(array(
'translate node entities',
));
$node = $this
->createNode('page', 'en');
$this
->drupalGet('node/' . $node->nid);
$this
->clickLink('Translate');
$this
->assertText(t('Translations of @title', array(
'@title' => $node->title,
)));
$this
->assertText(t('Pending Translations'));
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
);
$this
->drupalPost(NULL, $edit, t('Request translation'));
$this
->assertText(t('2 jobs need to be checked out.'));
$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'));
$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,
)));
$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']);
}
function dtestCommentTranslateTab() {
$this
->loginAsAdmin(array(
'administer entity translation',
));
$edit = array(
'entity_translation_entity_types[comment]' => TRUE,
);
$this
->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration'));
$comment_body = field_info_field('comment_body');
$comment_body['translatable'] = TRUE;
field_update_field($comment_body);
$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();
if (isset($entity_translation_permissions['edit original values'])) {
$permissions[] = 'edit original values';
}
$this
->loginAsTranslator($permissions, TRUE);
$node = $this
->createNode('article', 'en');
$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.'));
$this
->clickLink('edit');
$this
->assertTrue(preg_match('|comment/(\\d+)/edit$|', $this
->getUrl(), $matches), 'Comment found');
$comment = comment_load($matches[1]);
$this
->clickLink('Translate');
$this
->assertText(t('Translations of @title', array(
'@title' => $comment->subject,
)));
$this
->assertText(t('Pending Translations'));
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
);
$this
->drupalPost(NULL, $edit, t('Request translation'));
$this
->assertText(t('2 jobs need to be checked out.'));
$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'));
$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,
)));
$this
->drupalGet('de/comment/' . $comment->cid);
$this
->assertText('de_' . $comment->comment_body['en'][0]['value']);
$this
->drupalGet('es/node/' . $comment->cid);
$this
->assertText('es_' . $comment->comment_body['en'][0]['value']);
}
function testCart() {
$this
->loginAsTranslator(array(
'translate node entities',
));
$nodes = array();
for ($i = 0; $i < 4; $i++) {
$nodes[$i] = $this
->createNode('page');
}
$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);
$this
->drupalGet('node/' . $nodes[3]->nid . '/translate');
$this
->assertRaw(t('There are @count items in the <a href="@url">translation cart</a>.', 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 <a href="@url">cart</a>.', array(
'@count' => 1,
'@url' => url('admin/tmgmt/cart'),
)));
$this
->assertRaw(t('There are @count items in the <a href="@url">translation cart</a> including the current item.', array(
'@count' => 3,
'@url' => url('admin/tmgmt/cart'),
)));
}
}