clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,218 @@
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntityWithOwner;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the bulk-form list builder.
*
* @group entity
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class BulkFormEntityListBuilderTest extends BrowserTestBase {
use BlockCreationTrait;
/**
* The entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_module_test', 'user', 'entity', 'block'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* The base permissions to grant for the test user.
*
* @var string[]
*/
protected $basePermissions = [
'access entity_test_enhanced_with_owner overview',
'view any entity_test_enhanced_with_owner',
'view own unpublished entity_test_enhanced_with_owner',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
/* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $this->container->get('entity_type.manager');
$this->storage = $entity_type_manager->getStorage('entity_test_enhanced_with_owner');
$this->placeBlock('page_title_block');
$this->placeBlock('local_tasks_block');
$account = $this->drupalCreateUser($this->basePermissions);
$this->drupalLogin($account);
}
/**
* Tests that the bulk form is displayed correctly.
*/
public function testBulkForm() {
$entity = $this->storage->create([
'name' => 'Entity 1',
'type' => 'default',
]);
$collection_url = $entity->getEntityType()->getLinkTemplate('collection');
// Without any entities the bulk form should not be shown.
$this->drupalGet($collection_url);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldNotExists('Action');
$this->assertSession()->buttonNotExists('Apply to selected items');
// Create an entity and make sure that the bulk form is shown.
$entity->save();
$this->drupalGet($collection_url);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('Action');
$this->assertSession()->buttonExists('Apply to selected items');
$this->submitForm([], 'Apply to selected items');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Error message"]', 'No items selected.');
}
/**
* Test the delete action on the bulk form.
*/
public function testDeleteAction() {
$entity = $this->storage->create([
'name' => 'Entity 1',
'type' => 'default',
'user_id' => $this->loggedInUser->id(),
]);
$entity->save();
$id = $entity->id();
$this->drupalGet($entity->toUrl('collection'));
$this->assertSession()->fieldValueEquals('Action', 'entity_test_enhanced_with_owner_delete_action');
$edit = ["entities[$id]" => $id];
$this->submitForm($edit, 'Apply to selected items');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Error message"]', 'No access to execute Delete enhanced entities with owner on the enhanced entity with owner Entity 1.');
$this->assertInstanceOf(EnhancedEntityWithOwner::class, $this->storage->load($id));
$account = $this->drupalCreateUser(array_merge(
$this->basePermissions,
['delete any default entity_test_enhanced_with_owner']
));
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->submitForm($edit, 'Apply to selected items');
$this->assertSession()->elementTextContains('css', 'h1', 'Are you sure you want to delete this enhanced entity with owner?');
$this->submitForm([], 'Delete');
// The entity is deleted in the web process, but will still be in the static
// cache of the test process, so we need to clear it manually.
$this->storage->resetCache([$id]);
$this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Status message"]', 'Deleted 1 item.');
$this->assertNull($this->storage->load($id));
}
/**
* Test the publish action on the bulk form.
*/
public function testPublishAction() {
/* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */
$entity = $this->storage->create([
'name' => 'Entity 1',
'type' => 'default',
'user_id' => $this->loggedInUser->id(),
'status' => 0,
]);
$entity->save();
$id = $entity->id();
$this->drupalGet($entity->toUrl('collection'));
$edit = [
'action' => 'entity_test_enhanced_with_owner_publish_action',
"entities[$id]" => $id,
];
$this->submitForm($edit, 'Apply to selected items');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Error message"]', 'No access to execute Publish enhanced entities with owner on the enhanced entity with owner Entity 1.');
$entity = $this->storage->load($id);
$this->assertFalse($entity->isPublished());
$account = $this->drupalCreateUser(array_merge(
$this->basePermissions,
['update any default entity_test_enhanced_with_owner']
));
$entity->setOwner($account)->save();
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->submitForm($edit, 'Apply to selected items');
// The entity is deleted in the web process, but will still be in the static
// cache of the test process, so we need to clear it manually.
$this->storage->resetCache([$id]);
$this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Status message"]', 'Publish enhanced entities with owner was applied to 1 item.');
$entity = $this->storage->load($id);
$this->assertTrue($entity->isPublished());
}
/**
* Test the unpublish action on the bulk form.
*/
public function testUnpublishAction() {
/* @var \Drupal\entity_module_test\Entity\EnhancedEntityWithOwner $entity */
$entity = $this->storage->create([
'name' => 'Entity 1',
'type' => 'default',
'user_id' => $this->loggedInUser->id(),
]);
$entity->save();
$id = $entity->id();
$this->drupalGet($entity->toUrl('collection'));
$edit = [
'action' => 'entity_test_enhanced_with_owner_unpublish_action',
"entities[$id]" => $id,
];
$this->submitForm($edit, 'Apply to selected items');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Error message"]', 'No access to execute Unpublish enhanced entities with owner on the enhanced entity with owner Entity 1.');
$entity = $this->storage->load($id);
$this->assertTrue($entity->isPublished());
$account = $this->drupalCreateUser(array_merge(
$this->basePermissions,
['update any default entity_test_enhanced_with_owner']
));
$entity->setOwner($account)->save();
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->submitForm($edit, 'Apply to selected items');
// The entity is deleted in the web process, but will still be in the static
// cache of the test process, so we need to clear it manually.
$this->storage->resetCache([$id]);
$this->assertSession()->elementTextContains('css', 'h1', 'Enhanced entities with owner');
$this->assertSession()->elementTextContains('xpath', '//div[@aria-label="Status message"]', 'Unpublish enhanced entities with owner was applied to 1 item.');
$entity = $this->storage->load($id);
$this->assertFalse($entity->isPublished());
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the collection route access check.
*
* @group entity
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class CollectionRouteAccessTest extends BrowserTestBase {
use BlockCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_module_test', 'user', 'entity', 'block'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->placeBlock('local_tasks_block');
$this->placeBlock('system_breadcrumb_block');
}
/**
* Test the collection route access.
*/
public function testCollectionRouteAccess() {
$entity = EnhancedEntity::create([
'name' => 'rev 1',
'type' => 'default',
]);
$entity->save();
// User without any relevant permissions.
$account = $this->drupalCreateUser(['access administration pages']);
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->assertSession()->statusCodeEquals(403);
// User with "access overview" permissions.
$account = $this->drupalCreateUser(['access entity_test_enhanced overview']);
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->assertSession()->statusCodeEquals(200);
// User with full administration permissions.
$account = $this->drupalCreateUser(['administer entity_test_enhanced']);
$this->drupalLogin($account);
$this->drupalGet($entity->toUrl('collection'));
$this->assertSession()->statusCodeEquals(200);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the entity duplicate UI.
*
* @group entity
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class EntityDuplicateTest extends BrowserTestBase {
use BlockCreationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The entity_test_enhanced storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_module_test', 'user', 'entity', 'block', 'views'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->placeBlock('local_tasks_block');
$this->placeBlock('page_title_block');
$this->placeBlock('system_breadcrumb_block');
$this->account = $this->drupalCreateUser([
'administer entity_test_enhanced',
]);
$this->drupalLogin($this->account);
$this->storage = $this->container->get('entity_type.manager')->getStorage('entity_test_enhanced');
}
/**
* Tests the duplicate form.
*/
public function testForm() {
$entity = EnhancedEntity::create([
'name' => 'Test',
'type' => 'default',
]);
$entity->save();
$this->drupalGet($entity->toUrl('duplicate-form'));
$this->assertSession()->pageTextContains('Duplicate Test');
$this->submitForm(['name[0][value]' => 'Test2'], 'Save');
$this->assertSession()->pageTextContains('Saved the Test2 enhanced entity.');
$this->storage->resetCache();
$entity = EnhancedEntity::load('1');
$this->assertEquals('Test', $entity->label());
$duplicated_entity = EnhancedEntity::load('2');
$this->assertEquals('Test2', $duplicated_entity->label());
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Drupal\Tests\entity\Functional\Menu;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that entity local actions are generated correctly.
*
* @group entity
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class EntityLocalActionTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block', 'entity', 'entity_module_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->drupalPlaceBlock('local_actions_block');
$account = $this->drupalCreateUser(['administer entity_test_enhanced']);
$this->drupalLogin($account);
}
/**
* Tests the local action on the collection is provided correctly.
*/
public function testCollectionLocalAction() {
$this->drupalGet('/entity_test_enhanced');
$this->assertSession()->linkByHrefExists('/entity_test_enhanced/add?destination=/entity_test_enhanced');
$this->assertSession()->linkExists('Add enhanced entity');
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Drupal\Tests\entity\Functional\Menu;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that entity local tasks are generated correctly.
*
* @group entity
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class EntityLocalTaskTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block', 'entity', 'entity_module_test'];
/**
* The view path of the entity used in the test.
*
* @var string
*/
protected $viewPath;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$entity = EnhancedEntity::create([
'type' => 'default',
'name' => 'Enhanced Entity test'
]);
$entity->save();
$this->viewPath = $entity->toUrl()->toString();
$this->drupalPlaceBlock('local_tasks_block');
$account = $this->drupalCreateUser(['administer entity_test_enhanced']);
$this->drupalLogin($account);
}
/**
* Tests the local tasks of the entity are provided correctly.
*/
public function testCollectionLocalAction() {
$this->drupalGet($this->viewPath);
$this->assertLocalTasks();
$this->clickLink('Edit');
$this->assertLocalTasks();
$this->clickLink('Duplicate');
$this->assertLocalTasks();
$this->clickLink('Revisions');
$this->assertLocalTasks();
}
/**
* Asserts that the entity's local tasks are visible.
*/
protected function assertLocalTasks() {
$this->assertSession()->linkByHrefExists($this->viewPath);
$this->assertSession()->linkExists('View');
$this->assertSession()->linkByHrefExists("$this->viewPath/edit");
$this->assertSession()->linkExists('Edit');
$this->assertSession()->linkByHrefExists("$this->viewPath/duplicate");
$this->assertSession()->linkExists('Duplicate');
$this->assertSession()->linkByHrefExists("$this->viewPath/revisions");
$this->assertSession()->linkExists('Revisions');
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Drupal\Tests\entity\Functional;
use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the revision route access check.
*
* @group entity
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class RevisionRouteAccessTest extends BrowserTestBase {
use BlockCreationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_module_test', 'user', 'entity', 'block'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->placeBlock('local_tasks_block');
$this->placeBlock('system_breadcrumb_block');
$this->account = $this->drupalCreateUser([
'administer entity_test_enhanced',
'view all entity_test_enhanced revisions',
]);
$this->drupalLogin($this->account);
}
/**
* Test enhanced entity revision routes access.
*/
public function testRevisionRouteAccess() {
$entity = EnhancedEntity::create([
'name' => 'rev 1',
'type' => 'default',
]);
$entity->save();
$revision = clone $entity;
$revision->name->value = 'rev 2';
$revision->setNewRevision(TRUE);
$revision->isDefaultRevision(FALSE);
$revision->save();
$this->drupalGet('/entity_test_enhanced/1/revisions');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('Revisions');
$collection_link = $this->getSession()->getPage()->findLink('Enhanced entities');
$collection_link->click();
$this->assertSession()->addressEquals('/entity_test_enhanced');
$this->assertSession()->responseContains('Edit');
$edit_link = $this->getSession()->getPage()->findLink('Edit');
$edit_link->click();
$this->assertSession()->addressEquals('/entity_test_enhanced/1/edit');
// Check if we have revision tab link on edit page.
$this->getSession()->getPage()->findLink('Revisions')->click();
$this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
$this->drupalGet('/entity_test_enhanced/1/revisions/2/view');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('rev 2');
$revisions_link = $this->getSession()->getPage()->findLink('Revisions');
$revisions_link->click();
$this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
$this->assertSession()->statusCodeEquals(200);
}
}