Test the non-moderated workflow with translatable nodes.
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
->assertSession()
->linkExists($title);
$edit = [
'items[' . $node
->id() . ']' => $node
->id(),
];
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('One job needs to be checked out.');
$this
->assertSession()
->pageTextContains($title . ' (English to ?, Unprocessed)');
$edit = [
'target_language' => 'de',
];
$this
->submitForm($edit, 'Submit to provider');
$this
->assertSession()
->pageTextContains(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
->assertSession()
->pageTextContains('Job item ' . $title);
// No moderation form element is displayed for non-moderated entities.
$this
->assertSession()
->pageTextNotContains('Current source state');
$this
->assertSession()
->pageTextContains('Translation publish status');
// The source node is not published so translation inherits the state.
$this
->assertSession()
->checkboxNotChecked('edit-status-published');
// Publish the translation.
$translation_title = 'de(de-ch): [Published] ' . $title;
$edit = [
'title|0|value[translation]' => $translation_title,
'status[published]' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(t('The translation for @title has been saved successfully.', [
'@title' => $title,
]));
$this
->clickLink('Review');
// The published field is preselected now.
$this
->assertSession()
->checkboxChecked('edit-status-published');
// Save the translation as completed and assert the published translation.
$this
->submitForm([], 'Save as completed');
$this
->assertSession()
->pageTextContains('Validation completed successfully.');
$this
->assertSession()
->pageTextContains(t('The translation for @title has been accepted as @translation_title.', [
'@title' => $title,
'@translation_title' => $translation_title,
]));
$this
->clickLink($translation_title);
$this
->assertSession()
->addressEquals('de/node/' . $node
->id());
$this
->assertSession()
->pageTextContains($translation_title);
$this
->clickLink('Revisions');
$this
->assertSession()
->pageTextContains("Created by translation job {$title}.");
// There is one translation revision.
$this
->assertNodeTranslationsRevisionsCount($node
->id(), 'de', 1);
// Create an unpublished Spanish translation.
$this
->drupalGet('admin/tmgmt/sources');
$edit = [
'target_language' => 'es',
'items[' . $node
->id() . ']' => $node
->id(),
];
$this
->submitForm($edit, 'Request translation');
$this
->submitForm([], 'Submit to provider');
$this
->assertSession()
->pageTextContains(t('The translation of @title to Spanish is finished and can now be reviewed.', [
'@title' => $title,
]));
$this
->clickLink('reviewed');
$this
->submitForm([], 'Save as completed');
// Spanish translation is unpublished.
$this
->assertSession()
->pageTextContains(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
->assertSession()
->statusCodeEquals(403);
// The source is still unpublished.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->statusCodeEquals(403);
// The german translation is published.
$this
->drupalGet('de/node/' . $node
->id());
$this
->assertSession()
->statusCodeEquals(200);
}