Skip to content
Snippets Groups Projects
Commit cc8ff21b authored by Michael Lee's avatar Michael Lee
Browse files

Installing drupal/entity_clone (1.0.0-beta7)

parent f708cde5
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ class EntityCloneEntityViewModeTest extends BrowserTestBase { ...@@ -17,7 +17,7 @@ class EntityCloneEntityViewModeTest extends BrowserTestBase {
* *
* @var array * @var array
*/ */
public static $modules = ['entity_clone']; public static $modules = ['entity_clone', 'field_ui'];
/** /**
* Theme to enable by default * Theme to enable by default
...@@ -32,6 +32,7 @@ class EntityCloneEntityViewModeTest extends BrowserTestBase { ...@@ -32,6 +32,7 @@ class EntityCloneEntityViewModeTest extends BrowserTestBase {
*/ */
protected $permissions = [ protected $permissions = [
'clone entity_view_mode entity', 'clone entity_view_mode entity',
'administer display modes',
]; ];
/** /**
......
<?php
namespace Drupal\Tests\entity_clone\Functional;
use Drupal\Tests\node\Functional\NodeTestBase;
/**
* Create a content with a paragraph and test a clone.
*
* @group entity_clone
*/
class EntityCloneParagraphTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['entity_clone', 'paragraphs_demo'];
/**
* Theme to enable by default
* @var string
*/
protected $defaultTheme = 'classy';
/**
* 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->drupalPostForm('entity_clone/node/' . $node->id(), $clone_options, 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->assertNotEqual($original_paragraph->getParentEntity()->id(), $cloned_paragraph->getParentEntity()->id());
}
}
...@@ -32,6 +32,7 @@ class EntityCloneShortcutSetTest extends BrowserTestBase { ...@@ -32,6 +32,7 @@ class EntityCloneShortcutSetTest extends BrowserTestBase {
*/ */
protected $permissions = [ protected $permissions = [
'clone shortcut_set entity', 'clone shortcut_set entity',
'administer shortcuts',
]; ];
/** /**
......
...@@ -32,6 +32,7 @@ class EntityCloneUserTest extends BrowserTestBase { ...@@ -32,6 +32,7 @@ class EntityCloneUserTest extends BrowserTestBase {
*/ */
protected $permissions = [ protected $permissions = [
'clone user entity', 'clone user entity',
'administer users',
]; ];
/** /**
......
...@@ -17,7 +17,7 @@ class EntityCloneViewTest extends BrowserTestBase { ...@@ -17,7 +17,7 @@ class EntityCloneViewTest extends BrowserTestBase {
* *
* @var array * @var array
*/ */
public static $modules = ['entity_clone', 'views']; public static $modules = ['entity_clone', 'views', 'views_ui'];
/** /**
* Theme to enable by default * Theme to enable by default
...@@ -32,6 +32,7 @@ class EntityCloneViewTest extends BrowserTestBase { ...@@ -32,6 +32,7 @@ class EntityCloneViewTest extends BrowserTestBase {
*/ */
protected $permissions = [ protected $permissions = [
'clone view entity', 'clone view entity',
'administer views',
]; ];
/** /**
......
<?php
namespace Drupal\Tests\entity_clone\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Tests entity clone access.
*
* @group entity_clone
*/
class EntityCloneAccessTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'field',
'text',
'user',
'entity_clone',
'system',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('system', ['sequences']);
$this->installSchema('node', ['node_access']);
$this->installConfig([
'node',
'user',
'system',
'entity_clone',
]);
// Call the user module install process that creates the anonymous user
// and user 1.
$this->container->get('module_handler')->loadInclude('user', 'install');
user_install();
$node_type = NodeType::create([
'type' => 'page',
'id' => 'page',
]);
$node_type->save();
}
/**
* Tests that users need to have the correct permissions to clone an entity.
*/
public function testCloneAccess() {
$node = Node::create([
'type' => 'page',
'title' => 'My node to clone',
'status' => TRUE,
]);
$node->save();
$user_no_permissions = $this->createUser(['access content']);
$user_that_can_create = $this->createUser(['access content', 'create page content']);
$user_that_can_clone = $this->createUser(['access content', 'clone node entity']);
$user_that_can_do_both = $this->createUser(['access content', 'clone node entity', 'create page content']);
$url = $node->toUrl('clone-form');
$access_control_handler = $this->container->get('entity_type.manager')->getAccessControlHandler('node');
// The user without permissions can view the content but cannot clone.
$this->assertTrue($access_control_handler->access($node, 'view', $user_no_permissions));
$this->assertFalse($access_control_handler->access($node, 'clone', $user_no_permissions));
$this->assertFalse($url->access($user_no_permissions));
// The user that can create content, cannot clone.
$this->assertTrue($access_control_handler->createAccess('page', $user_that_can_create));
$this->assertFalse($access_control_handler->access($node, 'clone', $user_that_can_create));
$this->assertFalse($url->access($user_that_can_create));
// The user that has clone permissions, but cannot create content, cannot
// clone.
$this->assertFalse($access_control_handler->createAccess('page', $user_that_can_clone));
$this->assertFalse($access_control_handler->access($node, 'clone', $user_that_can_clone));
$this->assertFalse($url->access($user_that_can_clone));
// The user that can do both, can clone.
$this->assertTrue($access_control_handler->createAccess('page', $user_that_can_do_both));
$this->assertTrue($access_control_handler->access($node, 'clone', $user_that_can_do_both));
$this->assertTrue($url->access($user_that_can_do_both));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment