function NodeFieldMultilingualTest::testMultilingualNodeForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeFieldMultilingualTest.php \Drupal\node\Tests\NodeFieldMultilingualTest::testMultilingualNodeForm()
Tests whether field languages are correctly set through the node form.
File
- core/
modules/ node/ src/ Tests/ NodeFieldMultilingualTest.php, line 63 - Contains \Drupal\node\Tests\NodeFieldMultilingualTest.
Class
- NodeFieldMultilingualTest
- Tests multilingual support for fields.
Namespace
Drupal\node\TestsCode
function testMultilingualNodeForm() {
// Create "Basic page" content.
$langcode = language_get_default_langcode('node', 'page');
$title_key = 'title[0][value]';
$title_value = $this
->randomMachineName(8);
$body_key = 'body[0][value]';
$body_value = $this
->randomMachineName(16);
// Create node to edit.
$edit = array();
$edit[$title_key] = $title_value;
$edit[$body_key] = $body_value;
$this
->drupalPostForm('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
$node = $this
->drupalGetNodeByTitle($edit[$title_key]);
$this
->assertTrue($node, 'Node found in database.');
$this
->assertTrue($node
->language()
->getId() == $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
->randomMachineName(8),
'langcode[0][value]' => $langcode,
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit[$title_key], TRUE);
$this
->assertTrue($node, 'Node found in database.');
$this
->assertTrue($node
->language()
->getId() == $langcode && $node->body->value == $body_value, 'Field language correctly changed.');
// Enable content language URL detection.
$this->container
->get('language_negotiator')
->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(
LanguageNegotiationUrl::METHOD_ID => 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');
}