Skip to content
Snippets Groups Projects
Commit 407c5aef authored by Daniel Wehner's avatar Daniel Wehner
Browse files

use one example test entity type instead of multiple

parent 7de3f7a3
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\Tests\entity\Kernel; namespace Drupal\Tests\entity\Kernel;
use Drupal\entity_module_test\Entity\EntityWithRevisionLog; use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
...@@ -42,7 +42,7 @@ class EntityRevisionLogTraitTest extends KernelTestBase { ...@@ -42,7 +42,7 @@ class EntityRevisionLogTraitTest extends KernelTestBase {
$user2->save(); $user2->save();
/** @var \Drupal\entity\Revision\EntityRevisionLogInterface $entity */ /** @var \Drupal\entity\Revision\EntityRevisionLogInterface $entity */
$entity = EntityWithRevisionLog::create([ $entity = EnhancedEntity::create([
'revision_user' => $user->id(), 'revision_user' => $user->id(),
'revision_created' => 1447941735, 'revision_created' => 1447941735,
'revision_log_message' => 'Test message', 'revision_log_message' => 'Test message',
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\Tests\entity\Kernel; namespace Drupal\Tests\entity\Kernel;
use Drupal\entity_module_test\Entity\EntityWithRevisionRoutes; use Drupal\entity_module_test\Entity\EnhancedEntity;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role; use Drupal\user\Entity\Role;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
...@@ -30,14 +30,14 @@ class RevisionBasicUITest extends KernelTestBase { ...@@ -30,14 +30,14 @@ class RevisionBasicUITest extends KernelTestBase {
parent::setUp(); parent::setUp();
$this->installEntitySchema('user'); $this->installEntitySchema('user');
$this->installEntitySchema('entity_test__rev_routes'); $this->installEntitySchema('entity_test_enhanced');
$this->installSchema('system', 'router'); $this->installSchema('system', 'router');
\Drupal::service('router.builder')->rebuild(); \Drupal::service('router.builder')->rebuild();
} }
public function testRevisionView() { public function testRevisionView() {
$entity = EntityWithRevisionRoutes::create([ $entity = EnhancedEntity::create([
'name' => 'rev 1', 'name' => 'rev 1',
]); ]);
$entity->save(); $entity->save();
...@@ -55,8 +55,8 @@ class RevisionBasicUITest extends KernelTestBase { ...@@ -55,8 +55,8 @@ class RevisionBasicUITest extends KernelTestBase {
$this->assertEquals(403, $response->getStatusCode()); $this->assertEquals(403, $response->getStatusCode());
$role = Role::create(['id' => 'test_role']); $role = Role::create(['id' => 'test_role']);
$role->grantPermission('view all entity_test__rev_routes revisions'); $role->grantPermission('view all entity_test_enhanced revisions');
$role->grantPermission('administer entity_test__revision_routes'); $role->grantPermission('administer entity_test_enhanced');
$role->save(); $role->save();
$user = User::create([ $user = User::create([
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\entity_module_test\Entity\EntityWithRevisionRoutes. * Contains \Drupal\entity_module_test\Entity\EnhancedEntity.
*/ */
namespace Drupal\entity_module_test\Entity; namespace Drupal\entity_module_test\Entity;
...@@ -14,33 +14,35 @@ use Drupal\entity\EntityKeysFieldsTrait; ...@@ -14,33 +14,35 @@ use Drupal\entity\EntityKeysFieldsTrait;
use Drupal\entity\Revision\EntityRevisionLogTrait; use Drupal\entity\Revision\EntityRevisionLogTrait;
/** /**
* Provides a test entity which uses all the capabilities of entity module.
*
* @ContentEntityType( * @ContentEntityType(
* id = "entity_test__rev_routes", * id = "entity_test_enhanced",
* label = @Translation("Entity test with revision routes"), * label = @Translation("Entity test with enhancements"),
* handlers = { * handlers = {
* "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage", * "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
* "route_provider" = { * "route_provider" = {
* "revision" = "\Drupal\entity\Routing\RevisionRouteProvider", * "revision" = "\Drupal\entity\Routing\RevisionRouteProvider",
* }, * },
* }, * },
* base_table = "entity_test__revision_routes", * base_table = "entity_test_enhanced",
* data_table = "entity_test__revision_routes__field_data", * data_table = "entity_test_enhanced_field_data",
* revision_table = "entity_test__revision_routes__revision", * revision_table = "entity_test_enhanced_revision",
* revision_data_table = "entity_test__revision_routes__field_revision", * revision_data_table = "entity_test_enhanced_field_revision",
* translatable = TRUE, * translatable = TRUE,
* revisionable = TRUE, * revisionable = TRUE,
* admin_permission = "administer entity_test__revision_routes", * admin_permission = "administer entity_test_enhanced",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "revision" = "vid", * "revision" = "vid",
* "langcode" = "langcode", * "langcode" = "langcode",
* }, * },
* links = { * links = {
* "revision" = "/entity_test__rev_routes/{entity_test__rev_routes}/revisions/{entity_test__rev_routes_revision}/view", * "revision" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/view",
* } * }
* ) * )
*/ */
class EntityWithRevisionRoutes extends ContentEntityBase { class EnhancedEntity extends ContentEntityBase {
use EntityRevisionLogTrait; use EntityRevisionLogTrait;
use EntityKeysFieldsTrait; use EntityKeysFieldsTrait;
...@@ -52,6 +54,7 @@ class EntityWithRevisionRoutes extends ContentEntityBase { ...@@ -52,6 +54,7 @@ class EntityWithRevisionRoutes extends ContentEntityBase {
$fields = []; $fields = [];
$fields += static::entityKeysBaseFieldDefinitions($entity_type); $fields += static::entityKeysBaseFieldDefinitions($entity_type);
$fields += static::entityRevisionLogBaseFieldDefinitions();
$fields['name'] = BaseFieldDefinition::create('string') $fields['name'] = BaseFieldDefinition::create('string')
->setLabel('Name') ->setLabel('Name')
......
<?php
/**
* @file
* Contains \Drupal\entity_module_test\Entity\EntityWithRevisionLog.
*/
namespace Drupal\entity_module_test\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity\EntityKeysFieldsTrait;
use Drupal\entity\Revision\EntityRevisionLogTrait;
/**
* @ContentEntityType(
* id = "entity_test__revision_log",
* label = @Translation("Entity test with revision log"),
* handlers = {
* "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
* },
* translatable = TRUE,
* revisionable = TRUE,
* entity_keys = {
* "id" = "id",
* "revision" = "vid",
* "langcode" = "langcode",
* }
* )
*/
class EntityWithRevisionLog extends ContentEntityBase {
use EntityRevisionLogTrait;
use EntityKeysFieldsTrait;
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
$fields += static::entityKeysBaseFieldDefinitions($entity_type);
$fields += static::entityRevisionLogBaseFieldDefinitions();
return $fields;
}
}
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