Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / EntityRevisionConverterTest.php
index 6f209d13ae09cf8ce97d5c931a05c50a4d49891c..69eee60d1a30065911dea88935d49ae59ef1e89f 100644 (file)
@@ -2,21 +2,22 @@
 
 namespace Drupal\Tests\content_moderation\Kernel;
 
-use Drupal\entity_test\Entity\EntityTest;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\node\Entity\Node;
 use Drupal\node\Entity\NodeType;
-use Drupal\workflows\Entity\Workflow;
 
 /**
  * @coversDefaultClass \Drupal\content_moderation\ParamConverter\EntityRevisionConverter
  * @group content_moderation
+ * @group legacy
  */
 class EntityRevisionConverterTest extends KernelTestBase {
 
+  /**
+   * {@inheritdoc}
+   */
   public static $modules = [
     'user',
-    'entity_test',
     'system',
     'content_moderation',
     'node',
@@ -28,74 +29,36 @@ class EntityRevisionConverterTest extends KernelTestBase {
    */
   protected function setUp() {
     parent::setUp();
-
-    $this->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
+   * @expectedDeprecationMessage The load_pending_revision flag has been deprecated. You should use load_latest_revision instead.
    */
-  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([
+  public function testDeprecatedLoadPendingRevisionFlag() {
+    NodeType::create([
       'type' => 'article',
-    ]);
-    $node_type->save();
-    $workflow = Workflow::load('editorial');
-    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');
-    $workflow->save();
+    ])->save();
 
-    $revision_ids = [];
     $node = Node::create([
       'title' => 'test',
       'type' => 'article',
     ]);
-    $node->moderation_state->value = 'published';
     $node->save();
 
-    $revision_ids[] = $node->getRevisionId();
-
+    $node->isDefaultRevision(FALSE);
     $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());
+    $converted = $this->container->get('paramconverter.latest_revision')->convert($node->id(), [
+      'load_pending_revision' => TRUE,
+      'type' => 'entity:node',
+    ], 'node', []);
+    $this->assertEquals($converted->getLoadedRevisionId(), $node->getLoadedRevisionId());
   }
 
 }