diff --git a/core/lib/Drupal/Core/Entity/EntityRevisionLogInterface.php b/core/lib/Drupal/Core/Entity/EntityRevisionLogInterface.php index 043e4c5..8793ee9 100644 --- a/core/lib/Drupal/Core/Entity/EntityRevisionLogInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityRevisionLogInterface.php @@ -6,11 +6,12 @@ */ namespace Drupal\Core\Entity; +use Drupal\user\UserInterface; /** * Defines an entity type with create time/author/log information for revisions. */ -interface EntityRevisionLogInterface { +interface EntityRevisionLogInterface extends RevisionableInterface { /** * Gets the entity revision creation timestamp. @@ -48,7 +49,7 @@ public function getRevisionUser(); * * @return $this */ - public function setRevisionUser($account); + public function setRevisionUser(UserInterface $account); /** * Gets the entity revision author ID. diff --git a/core/lib/Drupal/Core/Entity/RevisionableContentEntityBase.php b/core/lib/Drupal/Core/Entity/RevisionableContentEntityBase.php index 1500a05..34b6955 100644 --- a/core/lib/Drupal/Core/Entity/RevisionableContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/RevisionableContentEntityBase.php @@ -15,7 +15,7 @@ * * @ingroup entity_api */ -abstract class RevisionableContentEntityBase extends ContentEntityBase { +abstract class RevisionableContentEntityBase extends ContentEntityBase implements EntityRevisionLogInterface { /** * {@inheritdoc} diff --git a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php index e1ce5d7..07dfacf 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php @@ -9,6 +9,7 @@ use Drupal\entity_test\Entity\EntityTestWithRevisionLog; use Drupal\Tests\token\Kernel\KernelTestBase; +use Drupal\user\Entity\User; /** * @coversDefaultClass \Drupal\Core\Entity\RevisionableContentEntityBase @@ -19,7 +20,7 @@ class RevisionableContentEntityBaseTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['entity_test', 'system']; + public static $modules = ['entity_test', 'system', 'user']; /** * {@inheritdoc} @@ -28,13 +29,33 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_revlog'); + $this->installEntitySchema('user'); + $this->installSchema('system', 'sequences'); } public function testRevisionableContentEntity() { + $user = User::create(['name' => 'test name']); + $user->save(); + /** @var \Drupal\entity_test\Entity\EntityTestWithRevisionLog $entity */ $entity = EntityTestWithRevisionLog::create([ 'type' => 'entity_test_revlog', ]); $entity->save(); + + $entity->setNewRevision(TRUE); + $random_timestamp = rand(1e8, 2e8); + $entity->setRevisionCreationTime($random_timestamp); + $entity->setRevisionUserId($user->id()); + $entity->setRevisionLogMessage('This is my log message'); + $entity->save(); + + $revision_id = $entity->getRevisionId(); + + $entity = \Drupal::entityTypeManager()->getStorage('entity_test_revlog')->loadRevision($revision_id); + $this->assertEquals($random_timestamp, $entity->getRevisionCreationTime()); + $this->assertEquals($user->id(), $entity->getRevisionUserId()); + $this->assertEquals($user->id(), $entity->getRevisionUser()->id()); + $this->assertEquals('This is my log message', $entity->getRevisionLogMessage()); }