function ContentTmgmtEntitySourceUiTest::testCommentTranslateTab in Translation Management Tool 8
Test translating comments.
File
- sources/
content/ tests/ src/ Functional/ ContentTmgmtEntitySourceUiTest.php, line 445
Class
- ContentTmgmtEntitySourceUiTest
- Content entity source UI tests.
Namespace
Drupal\Tests\tmgmt_content\FunctionalCode
function testCommentTranslateTab() {
// Allow auto-accept.
$default_translator = Translator::load('test_translator');
$default_translator
->setAutoAccept(TRUE)
->save();
// Add default comment type.
$this
->addDefaultCommentField('node', 'article');
// Enable comment translation.
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
$content_translation_manager = \Drupal::service('content_translation.manager');
$content_translation_manager
->setEnabled('comment', 'comment', TRUE);
// Change comment_body field to be translatable.
$comment_body = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$comment_body
->setTranslatable(TRUE)
->save();
// Create a user that is allowed to translate comments.
$permissions = array_merge($this->translator_permissions, array(
'translate comment',
'post comments',
'skip comment approval',
'edit own comments',
'access comments',
'administer comments',
'bypass node access',
));
$this
->loginAsTranslator($permissions, TRUE);
// Create an english source article.
$node = $this
->createTranslatableNode('article', 'en');
// Add a comment.
$this
->drupalGet('node/' . $node
->id());
$edit = array(
'subject[0][value]' => $this
->randomMachineName(),
'comment_body[0][value]' => $this
->randomMachineName(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('Your comment has been posted.'));
// Go to the translate tab.
$this
->clickLink('Edit');
$this
->assertNotEmpty(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
->getSubject(),
)));
$this
->assertText(t('Pending Translations'));
// Request translations.
$edit = array(
'languages[de]' => TRUE,
'languages[es]' => TRUE,
);
$this
->drupalPostForm(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
->getSubject());
$this
->drupalPostForm(NULL, array(), t('Submit to provider and continue'));
$this
->assertText($comment
->getSubject());
$this
->drupalPostForm(NULL, array(), t('Submit to provider'));
// Make sure that we're back on the translate tab.
$this
->assertUrl($comment
->toUrl('canonical', array(
'absolute' => TRUE,
))
->toString() . '/translations');
$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
->getSubject(),
'@language' => t('Spanish'),
)));
$this
->assertText(t('The translation for @title has been accepted as es: @target.', array(
'@title' => $comment
->getSubject(),
'@target' => $comment
->getSubject(),
)));
// The translated content should be in place.
$this
->clickLink('de(de-ch): ' . $comment
->getSubject());
$this
->assertText('de(de-ch): ' . $comment
->get('comment_body')->value);
$this
->drupalGet('comment/1/translations');
$this
->clickLink('es: ' . $comment
->getSubject());
$this
->drupalGet('es/node/' . $comment
->id());
$this
->assertText('es: ' . $comment
->get('comment_body')->value);
// Disable auto-accept.
$default_translator
->setAutoAccept(FALSE)
->save();
// Request translation to Italian.
$edit = [
'languages[it]' => TRUE,
];
$this
->drupalPostForm('comment/' . $comment
->id() . '/translations', $edit, 'Request translation');
$this
->drupalPostForm(NULL, [], 'Submit to provider');
$this
->clickLink('reviewed');
$this
->assertText('Translation publish status');
$this
->assertFieldChecked('edit-status-published', 'Target publish status field is checked.');
// Do not publish the Italian translation.
$edit = [
'status[published]' => FALSE,
];
$this
->drupalPostForm(NULL, $edit, 'Save as completed');
$this
->drupalGet('it/comment/' . $comment
->id());
$this
->assertText('it: ' . $comment
->getSubject());
// Original entity and other translations are not affected.
$this
->drupalGet('comment/' . $comment
->id());
$this
->assertResponse(200);
$this
->assertText($comment
->getSubject());
$this
->drupalGet('de/comment/' . $comment
->id());
$this
->assertResponse(200);
$this
->drupalLogout();
$this
->drupalGet('it/comment/' . $comment
->id());
$this
->assertResponse(403);
}