a few more base modules
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Tests some integration of the revision overview:
|
||||
*
|
||||
* - Are the routes added properly.
|
||||
* - Are the local tasks added properly.
|
||||
*/
|
||||
class RevisionOverviewIntegrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'entity_module_test', 'entity', 'user', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installSchema('system', 'router');
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
public function testIntegration() {
|
||||
/** @var \Drupal\Core\Menu\LocalTaskManagerInterface $local_tasks_manager */
|
||||
$local_tasks_manager = \Drupal::service('plugin.manager.menu.local_task');
|
||||
|
||||
$tasks = $local_tasks_manager->getDefinitions();
|
||||
$this->assertArrayHasKey('entity.revisions_overview:entity_test_enhanced', $tasks);
|
||||
$this->assertArrayNotHasKey('entity.revisions_overview:node', $tasks, 'Node should have been excluded because it provides their own');
|
||||
|
||||
$this->assertEquals('entity.entity_test_enhanced.version_history', $tasks['entity.revisions_overview:entity_test_enhanced']['route_name']);
|
||||
$this->assertEquals('entity.entity_test_enhanced.canonical', $tasks['entity.revisions_overview:entity_test_enhanced']['base_route']);
|
||||
|
||||
/** @var \Drupal\Core\Routing\RouteProviderInterface $route_provider */
|
||||
$route_provider = \Drupal::service('router.route_provider');
|
||||
|
||||
$route = $route_provider->getRouteByName('entity.entity_test_enhanced.version_history');
|
||||
$this->assertInstanceOf(Route::class, $route);
|
||||
$this->assertEquals('\Drupal\entity\Controller\RevisionOverviewController::revisionOverviewController', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
entity_module_test.entity_test_enhanced_bundle.*:
|
||||
type: config_entity
|
||||
label: 'Entity test with enhancements - Bundle'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'Type'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
description:
|
||||
type: text
|
||||
label: 'Description'
|
||||
new_revision:
|
||||
type: boolean
|
||||
label: 'New revision'
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
name: Entity test
|
||||
type: module
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2016-06-23
|
||||
version: '8.x-1.0-alpha3+2-dev'
|
||||
core: '8.x'
|
||||
project: 'entity'
|
||||
datestamp: 1466693538
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
entity.entity_test_enhanced.canonical:
|
||||
title: View
|
||||
route_name: entity.entity_test_enhanced.canonical
|
||||
base_route: entity.entity_test_enhanced.canonical
|
||||
|
||||
entity.entity_module_test.edit_form:
|
||||
title: Edit
|
||||
route_name: entity.entity_test_enhanced.edit_form
|
||||
base_route: entity.entity_test_enhanced.canonical
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'administer entity_test_enhanced':
|
||||
title: 'Administer entity_test_enhanced'
|
||||
'restrict access': TRUE
|
||||
|
||||
'view all entity_test_enhanced revisions':
|
||||
title: 'View all entity_test_enhanced revisions'
|
||||
'restrict access': TRUE
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
entity.entity_test_enhanced.collection:
|
||||
path: '/entity_test_enhanced'
|
||||
defaults:
|
||||
_entity_list: 'entity_test_enhanced'
|
||||
_title: 'Entity test with enhancements'
|
||||
requirements:
|
||||
_permission: 'administer entity_test_enhanced'
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\entity_module_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
|
||||
/**
|
||||
* Provides a test entity which uses all the capabilities of entity module.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_enhanced",
|
||||
* label = @Translation("Entity test with enhancements"),
|
||||
* handlers = {
|
||||
* "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
|
||||
* "form" = {
|
||||
* "add" = "\Drupal\entity\Form\RevisionableContentEntityForm",
|
||||
* "edit" = "\Drupal\entity\Form\RevisionableContentEntityForm",
|
||||
* "delete" = "\Drupal\Core\Entity\EntityDeleteForm",
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "\Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
||||
* "revision" = "\Drupal\entity\Routing\RevisionRouteProvider",
|
||||
* "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider",
|
||||
* },
|
||||
* "list_builder" = "\Drupal\Core\Entity\EntityListBuilder",
|
||||
* },
|
||||
* base_table = "entity_test_enhanced",
|
||||
* data_table = "entity_test_enhanced_field_data",
|
||||
* revision_table = "entity_test_enhanced_revision",
|
||||
* revision_data_table = "entity_test_enhanced_field_revision",
|
||||
* translatable = TRUE,
|
||||
* revisionable = TRUE,
|
||||
* admin_permission = "administer entity_test_enhanced",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "bundle" = "type",
|
||||
* "revision" = "vid",
|
||||
* "langcode" = "langcode",
|
||||
* },
|
||||
* links = {
|
||||
* "add-page" = "/entity_test_enhanced/add",
|
||||
* "add-form" = "/entity_test_enhanced/add/{type}",
|
||||
* "edit-form" = "/entity_test_enhanced/{entity_test_enhanced}/edit",
|
||||
* "canonical" = "/entity_test_enhanced/{entity_test_enhanced}",
|
||||
* "collection" = "/entity_test_enhanced",
|
||||
* "delete-multiple-form" = "/entity_test_enhanced/delete",
|
||||
* "revision" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/view",
|
||||
* "revision-revert-form" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/revert",
|
||||
* "version-history" = "/entity_test_enhanced/{entity_test_enhanced}/revisions",
|
||||
* },
|
||||
* bundle_entity_type = "entity_test_enhanced_bundle",
|
||||
* )
|
||||
*/
|
||||
class EnhancedEntity extends RevisionableContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel('Name')
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\entity_module_test\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
use Drupal\Core\Entity\EntityDescriptionInterface;
|
||||
use Drupal\entity\Entity\RevisionableEntityBundleInterface;
|
||||
|
||||
/**
|
||||
* Provides bundles for the test entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "entity_test_enhanced_bundle",
|
||||
* label = @Translation("Entity test with enhancments - Bundle"),
|
||||
* admin_permission = "administer entity_test_enhanced",
|
||||
* config_prefix = "entity_test_enhanced_bundle",
|
||||
* bundle_of = "entity_test_enhanced",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label"
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
* "label",
|
||||
* "description"
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescriptionInterface, RevisionableEntityBundleInterface {
|
||||
|
||||
/**
|
||||
* The bundle ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The bundle label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* The bundle description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Should new entities of this bundle have a new revision by default.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $new_revision = FALSE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function shouldCreateNewRevision() {
|
||||
return $this->new_revision;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Functional;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\simpletest\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the delete multiple confirmation form.
|
||||
*
|
||||
* @group entity
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class DeleteMultipleFormTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface;
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['entity_module_test', 'user', 'entity'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
])->save();
|
||||
$this->account = $this->drupalCreateUser(['administer entity_test_enhanced']);
|
||||
$this->drupalLogin($this->account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the add page.
|
||||
*/
|
||||
public function testForm() {
|
||||
$entities = [];
|
||||
$selection = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$entity = EnhancedEntity::create([
|
||||
'type' => 'default',
|
||||
]);
|
||||
$entity->save();
|
||||
$entities[$entity->id()] = $entity;
|
||||
|
||||
$langcode = $entity->language()->getId();
|
||||
$selection[$entity->id()][$langcode] = $langcode;
|
||||
}
|
||||
// Add the selection to the tempstore just like DeleteAction would.
|
||||
$tempstore = \Drupal::service('user.private_tempstore')->get('entity_delete_multiple_confirm');
|
||||
$tempstore->set($this->account->id(), $selection);
|
||||
|
||||
$this->drupalGet('/entity_test_enhanced/delete');
|
||||
$assert = $this->assertSession();
|
||||
$assert->statusCodeEquals(200);
|
||||
$assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these items?');
|
||||
$delete_button = $this->getSession()->getPage()->findButton('Delete');
|
||||
$delete_button->click();
|
||||
$assert = $this->assertSession();
|
||||
$assert->addressEquals('/entity_test_enhanced');
|
||||
$assert->responseContains('Deleted 2 items.');
|
||||
|
||||
\Drupal::entityTypeManager()->getStorage('entity_test_enhanced')->resetCache();
|
||||
$remaining_entities = EnhancedEntity::loadMultiple(array_keys($selection));
|
||||
$this->assertEmpty($remaining_entities);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Functional;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\simpletest\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;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['entity_module_test', 'user', 'entity', 'block'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
])->save();
|
||||
|
||||
$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('Entity test with enhancements');
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\entity\Plugin\Action\DeleteAction;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\system\Entity\Action;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the delete entity action.
|
||||
* @group entity
|
||||
*/
|
||||
class DeleteActionTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['action', 'node', 'entity_module_test', 'entity',
|
||||
'user', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
$this->installSchema('system', ['key_value_expire', 'sequences']);
|
||||
|
||||
$bundle = EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
$this->user = User::create([
|
||||
'name' => 'username',
|
||||
'status' => 1,
|
||||
]);
|
||||
$this->user->save();
|
||||
\Drupal::service('current_user')->setAccount($this->user);
|
||||
}
|
||||
|
||||
public function testAction() {
|
||||
/** @var \Drupal\system\ActionConfigEntityInterface $action */
|
||||
$action = Action::create([
|
||||
'id' => 'enhanced_entity_delete_action',
|
||||
'label' => 'Delete enhanced entity',
|
||||
'plugin' => 'entity_delete_action:entity_test_enhanced',
|
||||
]);
|
||||
$status = $action->save();
|
||||
$this->assertEquals(SAVED_NEW, $status);
|
||||
$this->assertInstanceOf(DeleteAction::class, $action->getPlugin());
|
||||
|
||||
$entities = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$entity = EnhancedEntity::create([
|
||||
'type' => 'default',
|
||||
]);
|
||||
$entity->save();
|
||||
$entities[$entity->id()] = $entity;
|
||||
}
|
||||
|
||||
$action->execute($entities);
|
||||
// Confirm that the entity ids and langcodes are now in the tempstore.
|
||||
$tempstore = \Drupal::service('user.private_tempstore')->get('entity_delete_multiple_confirm');
|
||||
$selection = $tempstore->get($this->user->id());
|
||||
$this->assertEquals(array_keys($entities), array_keys($selection));
|
||||
$this->assertEquals([['en' => 'en'], ['en' => 'en']], array_values($selection));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @group entity
|
||||
*/
|
||||
class RevisionBasicUITest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_module_test', 'system', 'user', 'entity'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
$this->installSchema('system', 'router');
|
||||
$this->installConfig(['system']);
|
||||
|
||||
$bundle = EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the revision history controller.
|
||||
*/
|
||||
public function testRevisionHistory() {
|
||||
$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();
|
||||
|
||||
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
|
||||
$http_kernel = \Drupal::service('http_kernel');
|
||||
$request = Request::create($revision->url('version-history'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
|
||||
$role = Role::create(['id' => 'test_role']);
|
||||
$role->grantPermission('view all entity_test_enhanced revisions');
|
||||
$role->grantPermission('administer entity_test_enhanced');
|
||||
$role->save();
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'Test user',
|
||||
]);
|
||||
$user->addRole($role->id());
|
||||
\Drupal::service('account_switcher')->switchTo($user);
|
||||
|
||||
$request = Request::create($revision->url('version-history'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
// This ensures that the default revision is still the first revision.
|
||||
$this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1/revisions/2/view') !== FALSE);
|
||||
$this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1') !== FALSE);
|
||||
|
||||
// Publish a new revision.
|
||||
$revision = clone $entity;
|
||||
$revision->name->value = 'rev 3';
|
||||
$revision->setNewRevision(TRUE);
|
||||
$revision->isDefaultRevision(TRUE);
|
||||
$revision->save();
|
||||
|
||||
$request = Request::create($revision->url('version-history'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
// The first revision row should now include a revert link.
|
||||
$this->assertTrue(strpos($response->getContent(), 'entity_test_enhanced/1/revisions/1/revert') !== FALSE);
|
||||
}
|
||||
|
||||
public function testRevisionView() {
|
||||
$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();
|
||||
|
||||
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
|
||||
$http_kernel = \Drupal::service('http_kernel');
|
||||
$request = Request::create($revision->url('revision'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(403, $response->getStatusCode());
|
||||
|
||||
$role = Role::create(['id' => 'test_role']);
|
||||
$role->grantPermission('view all entity_test_enhanced revisions');
|
||||
$role->grantPermission('administer entity_test_enhanced');
|
||||
$role->save();
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'Test user',
|
||||
]);
|
||||
$user->addRole($role->id());
|
||||
\Drupal::service('account_switcher')->switchTo($user);
|
||||
|
||||
$request = Request::create($revision->url('revision'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertNotContains('rev 1', $response->getContent());
|
||||
$this->assertContains('rev 2', $response->getContent());
|
||||
}
|
||||
|
||||
public function testRevisionRevert() {
|
||||
$entity = EnhancedEntity::create([
|
||||
'name' => 'rev 1',
|
||||
'type' => 'entity_test_enhance',
|
||||
]);
|
||||
$entity->save();
|
||||
$entity->name->value = 'rev 2';
|
||||
$entity->setNewRevision(TRUE);
|
||||
$entity->isDefaultRevision(TRUE);
|
||||
$entity->save();
|
||||
|
||||
$role = Role::create(['id' => 'test_role']);
|
||||
$role->grantPermission('administer entity_test_enhanced');
|
||||
$role->grantPermission('revert all entity_test_enhanced revisions');
|
||||
$role->save();
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'Test user',
|
||||
]);
|
||||
$user->addRole($role->id());
|
||||
\Drupal::service('account_switcher')->switchTo($user);
|
||||
|
||||
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
|
||||
$http_kernel = \Drupal::service('http_kernel');
|
||||
$request = Request::create($entity->url('revision-revert-form'));
|
||||
$response = $http_kernel->handle($request);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user