Same name in other branches
  1. 8.x-1.x tests/src/Functional/EntityCloneParagraphTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneParagraphTest

Create a content with a paragraph and test a clone.

@group entity_clone

Hierarchy

  • class \Drupal\Tests\entity_clone\Functional\EntityCloneParagraphTest extends \Drupal\Tests\node\Functional\NodeTestBase uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of EntityCloneParagraphTest

File

tests/src/Functional/EntityCloneParagraphTest.php, line 13

Namespace

Drupal\Tests\entity_clone\Functional
View source
class EntityCloneParagraphTest extends NodeTestBase {
    use StringTranslationTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'entity_clone',
        'paragraphs_demo',
    ];
    
    /**
     * Theme to enable by default.
     *
     * @var string
     */
    protected $defaultTheme = 'claro';
    
    /**
     * Disable strict config schema checks in this test.
     *
     * @var bool
     */
    // @codingStandardsIgnoreStart
    protected $strictConfigSchema = FALSE;
    // @codingStandardsIgnoreEnd
    
    /**
     * Profile to install.
     *
     * @var string
     */
    protected $profile = 'standard';
    
    /**
     * Permissions to grant admin user.
     *
     * @var array
     */
    protected $permissions = [
        'clone node entity',
        'bypass node access',
    ];
    
    /**
     * A user with permission to bypass content access checks.
     *
     * @var \Drupal\user\UserInterface
     */
    protected $adminUser;
    
    /**
     * Sets the test up.
     */
    protected function setUp() : void {
        parent::setUp();
        $this->adminUser = $this->drupalCreateUser($this->permissions);
        $this->drupalLogin($this->adminUser);
    }
    
    /**
     * Tests cloning of paragraph entities.
     */
    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());
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityCloneParagraphTest::$adminUser protected property A user with permission to bypass content access checks.
EntityCloneParagraphTest::$defaultTheme protected property Theme to enable by default.
EntityCloneParagraphTest::$modules protected static property Modules to enable.
EntityCloneParagraphTest::$permissions protected property Permissions to grant admin user.
EntityCloneParagraphTest::$profile protected property Profile to install.
EntityCloneParagraphTest::$strictConfigSchema protected property
EntityCloneParagraphTest::setUp protected function Sets the test up.
EntityCloneParagraphTest::testParagraphClone public function Tests cloning of paragraph entities.