3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\entity_test\Entity\EntityTestRev;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\workflows\Entity\Workflow;
10 * @coversDefaultClass \Drupal\content_moderation\ModerationInformation
11 * @group content_moderation
13 class ModerationInformationTest extends KernelTestBase {
18 public static $modules = ['content_moderation', 'entity_test', 'user', 'workflows'];
23 protected function setUp() {
26 $this->installEntitySchema('entity_test_rev');
27 $this->installEntitySchema('content_moderation_state');
28 $this->installConfig(['content_moderation']);
32 * @covers ::getDefaultRevisionId
33 * @covers ::getLatestRevisionId
35 public function testDefaultAndLatestRevisionId() {
36 $workflow = Workflow::load('editorial');
37 $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
40 $entity_test_rev = EntityTestRev::create([
41 'name' => 'Default Revision',
42 'moderation_state' => 'published',
44 $entity_test_rev->save();
46 $entity_test_rev->name = 'Pending revision';
47 $entity_test_rev->moderation_state = 'draft';
48 $entity_test_rev->save();
50 /** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
51 $moderation_info = \Drupal::service('content_moderation.moderation_information');
53 // Check that moderation information service returns the correct default
55 $default_revision_id = $moderation_info->getDefaultRevisionId('entity_test_rev', $entity_test_rev->id());
56 $this->assertSame(1, $default_revision_id);
58 // Check that moderation information service returns the correct latest
60 $latest_revision_id = $moderation_info->getLatestRevisionId('entity_test_rev', $entity_test_rev->id());
61 $this->assertSame(2, $latest_revision_id);