function ContentEntitySourceContentModerationTest::testNonModeratedContentTranslations in Translation Management Tool 8
Test the non-moderated workflow with translatable nodes.
File
- sources/
content/ tests/ src/ Functional/ ContentEntitySourceContentModerationTest.php, line 515
Class
- ContentEntitySourceContentModerationTest
- Tests content entity source integration with content moderation.
Namespace
Drupal\Tests\tmgmt_content\FunctionalCode
function testNonModeratedContentTranslations() {
$this
->loginAsTranslator([
'translate any entity',
'create content translations',
'administer nodes',
'bypass node access',
]);
// Create an unpublished node in English.
$title = 'Non-moderated node';
$node = $this
->createNode([
'title' => $title,
'type' => 'page',
'langcode' => 'en',
'status' => FALSE,
'uid' => $this->translator_user
->id(),
]);
// Go to content overview and translate the unpublished node.
$this
->drupalGet('admin/tmgmt/sources');
$this
->assertLink($title);
$edit = [
'items[' . $node
->id() . ']' => $node
->id(),
];
$this
->drupalPostForm(NULL, $edit, 'Request translation');
$this
->assertText('One job needs to be checked out.');
$this
->assertText($title . ' (English to ?, Unprocessed)');
$edit = [
'target_language' => 'de',
];
$this
->drupalPostForm(NULL, $edit, 'Submit to provider');
$this
->assertText(t('The translation of @title to German is finished and can now be reviewed.', [
'@title' => $title,
]));
// Assert a draft label on the jobs overview page.
$this
->clickLink('reviewed');
$this
->assertText('Job item ' . $title);
// No moderation form element is displayed for non-moderated entities.
$this
->assertNoText('Current source state');
$this
->assertText('Translation publish status');
// The source node is not published so translation inherits the state.
$this
->assertNoFieldChecked('edit-status-published');
// Publish the translation.
$translation_title = 'de(de-ch): [Published] ' . $title;
$edit = [
'title|0|value[translation]' => $translation_title,
'status[published]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText(t('The translation for @title has been saved successfully.', [
'@title' => $title,
]));
$this
->clickLink('Review');
// The published field is preselected now.
$this
->assertFieldChecked('edit-status-published');
// Save the translation as completed and assert the published translation.
$this
->drupalPostForm(NULL, [], 'Save as completed');
$this
->assertText('Validation completed successfully.');
$this
->assertText(t('The translation for @title has been accepted as @translation_title.', [
'@title' => $title,
'@translation_title' => $translation_title,
]));
$this
->clickLink($translation_title);
$this
->assertUrl('de/node/' . $node
->id());
$this
->assertText($translation_title);
$this
->clickLink('Revisions');
$this
->assertText("Created by translation job {$title}.");
// There is one translation revision.
$this
->assertNodeTranslationsRevisionsCount($node
->id(), 'de', 1);
// Create an unpublished Spanish translation.
$edit = [
'target_language' => 'es',
'items[' . $node
->id() . ']' => $node
->id(),
];
$this
->drupalPostForm('admin/tmgmt/sources', $edit, 'Request translation');
$this
->drupalPostForm(NULL, [], 'Submit to provider');
$this
->assertText(t('The translation of @title to Spanish is finished and can now be reviewed.', [
'@title' => $title,
]));
$this
->clickLink('reviewed');
$this
->drupalPostForm(NULL, [], 'Save as completed');
// Spanish translation is unpublished.
$this
->assertText(t('The translation for @title has been accepted as es: @title', [
'@title' => $title,
]));
$this
->drupalLogout();
// The spanish translation is not published.
$this
->drupalGet('es/node/' . $node
->id());
$this
->assertResponse(403);
// The source is still unpublished.
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(403);
// The german translation is published.
$this
->drupalGet('de/node/' . $node
->id());
$this
->assertResponse(200);
}