Same name in other branches
- 8.x-1.x tests/src/Functional/EntityCloneContentRecursiveCircularTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneContentRecursiveCircularTest::testContentWithTwoSameEntityReference()
Test clone++ a content entity.
File
-
tests/
src/ Functional/ EntityCloneContentRecursiveCircularTest.php, line 157
Class
- EntityCloneContentRecursiveCircularTest
- Create a content and test a clone.
Namespace
Drupal\Tests\entity_clone\FunctionalCode
public function testContentWithTwoSameEntityReference() {
$child_node1_title = $this->randomMachineName(8);
$child_node1 = Node::create([
'type' => 'test_content_type',
'title' => $child_node1_title,
]);
$child_node1->save();
$parent_node_title = $this->randomMachineName(8);
$parent_node = Node::create([
'type' => 'test_content_type',
'title' => $parent_node_title,
'test_field_reference' => $child_node1,
'test_another_field_reference' => $child_node1,
]);
$parent_node->save();
$settings = [
'node' => [
'default_value' => 0,
'disable' => 0,
'hidden' => 0,
],
];
\Drupal::service('config.factory')->getEditable('entity_clone.settings')
->set('form_settings', $settings)
->save();
$this->drupalGet('entity_clone/node/' . $parent_node->id());
$this->submitForm([], $this->t('Clone'));
$nodes = \Drupal::entityTypeManager()->getStorage('node')
->loadByProperties([
'title' => $parent_node_title . ' - Cloned',
]);
/** @var \Drupal\node\Entity\Node $parent_node_cloned */
$parent_node_cloned = reset($nodes);
$this->drupalGet('node/' . $parent_node_cloned->id());
$first_reference = $parent_node_cloned->get('test_field_reference')
->first()
->get('entity')
->getTarget()
->getValue();
$second_reference = $parent_node_cloned->get('test_another_field_reference')
->first()
->get('entity')
->getTarget()
->getValue();
$this->assertEquals($child_node1->id(), $first_reference->id(), "Entity referenced twice time is correctly reused.");
$this->assertEquals($child_node1->id(), $second_reference->id(), "Entity referenced twice time is correctly reused.");
}