Namespace
Drupal\Tests\entity_clone\Functional
File
-
tests/src/Functional/EntityCloneParagraphTest.php
View source
<?php
namespace Drupal\Tests\entity_clone\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\node\Functional\NodeTestBase;
class EntityCloneParagraphTest extends NodeTestBase {
use StringTranslationTrait;
protected static $modules = [
'entity_clone',
'paragraphs_demo',
];
protected $defaultTheme = 'claro';
protected $strictConfigSchema = FALSE;
protected $profile = 'standard';
protected $permissions = [
'clone node entity',
'bypass node access',
];
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->adminUser);
}
public function testParagraphClone() {
$node_title = 'Welcome to the Paragraphs Demo module!';
$nodes = \Drupal::entityTypeManager()->getStorage('node')
->loadByProperties([
'title' => $node_title,
]);
$node = reset($nodes);
$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());
}
}
Classes