Tests whether field languages are correctly set through the node form.
function testMultilingualNodeForm() {
// Create "Basic page" content.
$langcode = language_get_default_langcode('node', 'page');
$title_key = "title";
$title_value = $this
->randomName(8);
$body_key = "body[{$langcode}][0][value]";
$body_value = $this
->randomName(16);
// Create node to edit.
$edit = array();
$edit[$title_key] = $title_value;
$edit[$body_key] = $body_value;
$this
->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
$node = $this
->drupalGetNodeByTitle($edit[$title_key])
->getNGEntity();
$this
->assertTrue($node, 'Node found in database.');
$this
->assertTrue($node
->language()->langcode == $langcode && $node->body->value == $body_value, 'Field language correctly set.');
// Change node language.
$langcode = 'it';
$this
->drupalGet("node/{$node->id()}/edit");
$edit = array(
$title_key => $this
->randomName(8),
'langcode' => $langcode,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit[$title_key], TRUE)
->getNGEntity();
$this
->assertTrue($node, 'Node found in database.');
$this
->assertTrue($node
->language()->langcode == $langcode && $node->body->value == $body_value, 'Field language correctly changed.');
// Enable content language URL detection.
language_negotiation_set(Language::TYPE_CONTENT, array(
LANGUAGE_NEGOTIATION_URL => 0,
));
// Test multilingual field language fallback logic.
$this
->drupalGet("it/node/{$node->id()}");
$this
->assertRaw($body_value, 'Body correctly displayed using Italian as requested language');
$this
->drupalGet("node/{$node->id()}");
$this
->assertRaw($body_value, 'Body correctly displayed using English as requested language');
}