Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / ModerationStateFieldItemListTest.php
index 7b57bd704913e4e1c55b343c4ea251b328fb7fbb..0c8db872a5597cc3fdbe07115ef728bfc661d91d 100644 (file)
@@ -3,9 +3,11 @@
 namespace Drupal\Tests\content_moderation\Kernel;
 
 use Drupal\KernelTests\KernelTestBase;
+use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\node\Entity\Node;
 use Drupal\node\Entity\NodeType;
 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
+use Drupal\workflows\Entity\Workflow;
 
 /**
  * @coversDefaultClass \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList
@@ -64,6 +66,8 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
     $this->testNode->save();
     \Drupal::entityTypeManager()->getStorage('node')->resetCache();
     $this->testNode = Node::load($this->testNode->id());
+
+    ConfigurableLanguage::createFromLangcode('de')->save();
   }
 
   /**
@@ -332,4 +336,37 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
     ];
   }
 
+  /**
+   * Test the field item list when used with existing unmoderated content.
+   */
+  public function testWithExistingUnmoderatedContent() {
+    $node = Node::create([
+      'title' => 'Test title',
+      'type' => 'unmoderated',
+    ]);
+    $node->save();
+    $translation = $node->addTranslation('de', $node->toArray());
+    $translation->title = 'Translated';
+    $translation->save();
+
+    $workflow = Workflow::load('editorial');
+    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'unmoderated');
+    $workflow->save();
+
+    // After enabling moderation, both the original node and translation should
+    // have a published moderation state.
+    $node = Node::load($node->id());
+    $translation = $node->getTranslation('de');
+    $this->assertEquals('published', $node->moderation_state->value);
+    $this->assertEquals('published', $translation->moderation_state->value);
+
+    // After the node has been updated, both the original node and translation
+    // should still have a value.
+    $node->title = 'Updated title';
+    $node->save();
+    $translation = $node->getTranslation('de');
+    $this->assertEquals('published', $node->moderation_state->value);
+    $this->assertEquals('published', $translation->moderation_state->value);
+  }
+
 }