Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Entity / RevisionableContentEntityBaseTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Entity;
4
5 use Drupal\entity_test\Entity\EntityTestWithRevisionLog;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\user\Entity\User;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Entity\RevisionableContentEntityBase
11  * @group Entity
12  */
13 class RevisionableContentEntityBaseTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['entity_test', 'system', 'user'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     $this->installEntitySchema('entity_test_revlog');
27     $this->installEntitySchema('user');
28     $this->installSchema('system', 'sequences');
29   }
30
31   public function testRevisionableContentEntity() {
32     $user = User::create(['name' => 'test name']);
33     $user->save();
34     /** @var \Drupal\entity_test\Entity\EntityTestWithRevisionLog $entity */
35     $entity = EntityTestWithRevisionLog::create([
36       'type' => 'entity_test_revlog',
37     ]);
38     $entity->save();
39
40     $entity->setNewRevision(TRUE);
41     $random_timestamp = rand(1e8, 2e8);
42     $entity->setRevisionCreationTime($random_timestamp);
43     $entity->setRevisionUserId($user->id());
44     $entity->setRevisionLogMessage('This is my log message');
45     $entity->save();
46
47     $revision_id = $entity->getRevisionId();
48
49     $entity = \Drupal::entityTypeManager()->getStorage('entity_test_revlog')->loadRevision($revision_id);
50     $this->assertEquals($random_timestamp, $entity->getRevisionCreationTime());
51     $this->assertEquals($user->id(), $entity->getRevisionUserId());
52     $this->assertEquals($user->id(), $entity->getRevisionUser()->id());
53     $this->assertEquals('This is my log message', $entity->getRevisionLogMessage());
54   }
55
56 }