X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FEntityRevisionConverterTest.php;fp=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FKernel%2FEntityRevisionConverterTest.php;h=6f209d13ae09cf8ce97d5c931a05c50a4d49891c;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php b/web/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php new file mode 100644 index 000000000..6f209d13a --- /dev/null +++ b/web/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php @@ -0,0 +1,101 @@ +installEntitySchema('entity_test'); + $this->installEntitySchema('node'); + $this->installEntitySchema('user'); + $this->installEntitySchema('content_moderation_state'); + $this->installSchema('system', 'router'); + $this->installSchema('system', 'sequences'); + $this->installSchema('node', 'node_access'); + \Drupal::service('router.builder')->rebuild(); + } + + /** + * @covers ::convert + */ + public function testConvertNonRevisionableEntityType() { + $entity_test = EntityTest::create([ + 'name' => 'test', + ]); + + $entity_test->save(); + + /** @var \Symfony\Component\Routing\RouterInterface $router */ + $router = \Drupal::service('router.no_access_checks'); + $result = $router->match('/entity_test/' . $entity_test->id()); + + $this->assertInstanceOf(EntityTest::class, $result['entity_test']); + $this->assertEquals($entity_test->getRevisionId(), $result['entity_test']->getRevisionId()); + } + + /** + * @covers ::convert + */ + public function testConvertWithRevisionableEntityType() { + $this->installConfig(['content_moderation']); + $node_type = NodeType::create([ + 'type' => 'article', + ]); + $node_type->save(); + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article'); + $workflow->save(); + + $revision_ids = []; + $node = Node::create([ + 'title' => 'test', + 'type' => 'article', + ]); + $node->moderation_state->value = 'published'; + $node->save(); + + $revision_ids[] = $node->getRevisionId(); + + $node->setNewRevision(TRUE); + $node->save(); + $revision_ids[] = $node->getRevisionId(); + + $node->setNewRevision(TRUE); + $node->moderation_state->value = 'draft'; + $node->save(); + $revision_ids[] = $node->getRevisionId(); + + /** @var \Symfony\Component\Routing\RouterInterface $router */ + $router = \Drupal::service('router.no_access_checks'); + $result = $router->match('/node/' . $node->id() . '/edit'); + + $this->assertInstanceOf(Node::class, $result['node']); + $this->assertEquals($revision_ids[2], $result['node']->getRevisionId()); + $this->assertFalse($result['node']->isDefaultRevision()); + } + +}