Creates a translation for a basic page in the specified language.
\Drupal\Core\Entity\EntityInterface $node: The basic page to create the translation for.
$title: The title of a basic page in the specified language.
$body: The body of a basic page in the specified language.
$langcode: (optional) Language code.
Translation object.
function createTranslation(EntityInterface $node, $title, $body, $langcode) {
$this
->drupalGet('node/add/page', array(
'query' => array(
'translation' => $node->nid,
'target' => $langcode,
),
));
$field_langcode = Language::LANGCODE_NOT_SPECIFIED;
$body_key = "body[{$field_langcode}][0][value]";
$this
->assertFieldByXPath('//input[@id="edit-title"]', $node
->label(), "Original title value correctly populated.");
$this
->assertFieldByXPath("//textarea[@name='{$body_key}']", $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Original body value correctly populated.");
$edit = array();
$edit["title"] = $title;
$edit[$body_key] = $body;
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw(t('Basic page %title has been created.', array(
'%title' => $title,
)), 'Translation created.');
// Check to make sure that translation was successful.
$translation = $this
->drupalGetNodeByTitle($title);
$this
->assertTrue($translation, 'Node found in database.');
$this
->assertTrue($translation->tnid == $node->nid, 'Translation set id correctly stored.');
return $translation;
}