Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / ModerationInformationTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
5 use Drupal\entity_test\Entity\EntityTestRev;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\workflows\Entity\Workflow;
8
9 /**
10  * @coversDefaultClass \Drupal\content_moderation\ModerationInformation
11  * @group content_moderation
12  */
13 class ModerationInformationTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['content_moderation', 'entity_test', 'user', 'workflows'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     $this->installEntitySchema('entity_test_rev');
27     $this->installEntitySchema('content_moderation_state');
28     $this->installConfig(['content_moderation']);
29   }
30
31   /**
32    * @covers ::getDefaultRevisionId
33    * @covers ::getLatestRevisionId
34    */
35   public function testDefaultAndLatestRevisionId() {
36     $workflow = Workflow::load('editorial');
37     $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
38     $workflow->save();
39
40     $entity_test_rev = EntityTestRev::create([
41       'name' => 'Default Revision',
42       'moderation_state' => 'published',
43     ]);
44     $entity_test_rev->save();
45
46     $entity_test_rev->name = 'Pending revision';
47     $entity_test_rev->moderation_state = 'draft';
48     $entity_test_rev->save();
49
50     /** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
51     $moderation_info = \Drupal::service('content_moderation.moderation_information');
52
53     // Check that moderation information service returns the correct default
54     // revision ID.
55     $default_revision_id = $moderation_info->getDefaultRevisionId('entity_test_rev', $entity_test_rev->id());
56     $this->assertSame(1, $default_revision_id);
57
58     // Check that moderation information service returns the correct latest
59     // revision ID.
60     $latest_revision_id = $moderation_info->getLatestRevisionId('entity_test_rev', $entity_test_rev->id());
61     $this->assertSame(2, $latest_revision_id);
62   }
63
64 }