Same name in other branches
- 2.x tests/src/Functional/EntityCloneParagraphTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneParagraphTest::testParagraphClone()
Tests cloning of paragraph entities.
Fichier
-
tests/
src/ Functional/ EntityCloneParagraphTest.php, line 77
Classe
- EntityCloneParagraphTest
- Create a content with a paragraph and test a clone.
Namespace
Drupal\Tests\entity_clone\FunctionalCode
public function testParagraphClone() {
// Use node title from paragraphs_demo_install().
$node_title = 'Welcome to the Paragraphs Demo module!';
$nodes = \Drupal::entityTypeManager()->getStorage('node')
->loadByProperties([
'title' => $node_title,
]);
$node = reset($nodes);
// Clone all paragraphs except the shared library paragraph.
$clone_options = [
'recursive[node.paragraphed_content_demo.field_paragraphs_demo][references][1][clone]' => 1,
'recursive[node.paragraphed_content_demo.field_paragraphs_demo][references][2][clone]' => 1,
'recursive[node.paragraphed_content_demo.field_paragraphs_demo][references][3][clone]' => 1,
'recursive[node.paragraphed_content_demo.field_paragraphs_demo][references][5][clone]' => 1,
'recursive[node.paragraphed_content_demo.field_paragraphs_demo][references][5][children][recursive][paragraph.nested_paragraph.field_paragraphs_demo][references][4][clone]' => 1,
];
$this->drupalGet('entity_clone/node/' . $node->id());
$this->submitForm($clone_options, $this->t('Clone'));
$clones = \Drupal::entityTypeManager()->getStorage('node')
->loadByProperties([
'title' => $node_title . ' - Cloned',
]);
$clone = reset($clones);
$original_paragraph = $node->get('field_paragraphs_demo')
->first()
->get('entity')
->getTarget()
->getValue();
$cloned_paragraph = $clone->get('field_paragraphs_demo')
->first()
->get('entity')
->getTarget()
->getValue();
$this->assertNotEquals($original_paragraph->getParentEntity()
->id(), $cloned_paragraph->getParentEntity()
->id());
}