3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\workflows\Entity\Workflow;
12 * @coversDefaultClass \Drupal\content_moderation\ParamConverter\EntityRevisionConverter
13 * @group content_moderation
15 class EntityRevisionConverterTest extends KernelTestBase {
17 public static $modules = [
29 protected function setUp() {
32 $this->installEntitySchema('entity_test');
33 $this->installEntitySchema('node');
34 $this->installEntitySchema('user');
35 $this->installEntitySchema('content_moderation_state');
36 $this->installSchema('system', 'router');
37 $this->installSchema('system', 'sequences');
38 $this->installSchema('node', 'node_access');
39 \Drupal::service('router.builder')->rebuild();
45 public function testConvertNonRevisionableEntityType() {
46 $entity_test = EntityTest::create([
52 /** @var \Symfony\Component\Routing\RouterInterface $router */
53 $router = \Drupal::service('router.no_access_checks');
54 $result = $router->match('/entity_test/' . $entity_test->id());
56 $this->assertInstanceOf(EntityTest::class, $result['entity_test']);
57 $this->assertEquals($entity_test->getRevisionId(), $result['entity_test']->getRevisionId());
63 public function testConvertWithRevisionableEntityType() {
64 $this->installConfig(['content_moderation']);
65 $node_type = NodeType::create([
69 $workflow = Workflow::load('editorial');
70 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');
74 $node = Node::create([
78 $node->moderation_state->value = 'published';
81 $revision_ids[] = $node->getRevisionId();
83 $node->setNewRevision(TRUE);
85 $revision_ids[] = $node->getRevisionId();
87 $node->setNewRevision(TRUE);
88 $node->moderation_state->value = 'draft';
90 $revision_ids[] = $node->getRevisionId();
92 /** @var \Symfony\Component\Routing\RouterInterface $router */
93 $router = \Drupal::service('router.no_access_checks');
94 $result = $router->match('/node/' . $node->id() . '/edit');
96 $this->assertInstanceOf(Node::class, $result['node']);
97 $this->assertEquals($revision_ids[2], $result['node']->getRevisionId());
98 $this->assertFalse($result['node']->isDefaultRevision());