Performs the test run regards the node form.
bool $embedded: (Optional) Whether the embedded form should be used or not.
protected function doTestChangeWithinNodeForm($embedded = FALSE) {
$this
->assertEquals('es', $this->node
->language()
->getId(), "The node was created with langcode es.");
$this
->assertEquals('en', $this->paragraph
->language()
->getId(), "The paragraph was created with its default langcode en.");
// Use this form to add a node.
$this
->buildNodeForm($embedded);
$this
->submitNodeForm();
$langcode = $this->node
->language()
->getId();
$this
->assertEquals('es', $langcode, "The node's langcode remains unchanged to value es (after submission).");
$this
->assertEquals($langcode, $this->paragraph
->language()
->getId(), "The paragraph's langcode was inherited from its parent (after submission).");
// Switch to the form again.
$this
->buildNodeForm($embedded);
// Change the node's language from es to en.
if ($embedded) {
$this->formState
->setValue([
'embedded_entity_form',
'langcode',
], [
[
'value' => 'en',
],
]);
}
else {
$this->formState
->setValue('langcode', [
[
'value' => 'en',
],
]);
}
$this
->submitNodeForm();
$langcode = $this->node
->language()
->getId();
$this
->assertEquals('en', $langcode, "The node's langcode was updated to value en (after submission).");
$this
->assertEquals($langcode, $this->paragraph
->language()
->getId(), "The paragraph's updated langcode was inherited from its parent (after submission).");
// Rebuild the form once more and make sure
// that the langcode change does not get lost.
$this
->buildNodeForm($embedded);
// Change the node's language from en to es.
if ($embedded) {
$this->formState
->setValue([
'embedded_entity_form',
'langcode',
], [
[
'value' => 'es',
],
]);
}
else {
$this->formState
->setValue('langcode', [
[
'value' => 'es',
],
]);
}
$this
->submitNodeForm();
$langcode = $this->node
->language()
->getId();
$this
->assertEquals('es', $langcode, "The node's langcode was set to es (after rebuild and submission).");
$this
->assertEquals($langcode, $this->paragraph
->language()
->getId(), "The paragraph's langcode was inherited from its parent (after rebuild and submission).");
}