summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-06-15 07:32:16 (GMT)
committerGabor Hojtsy2017-06-15 07:32:16 (GMT)
commit69555bcd079574257c7f04b231a71a525f1a8052 (patch)
treeeb64aca59c2a20cf4b6d6dbc4a6cf42fe9662b45
parent985c26a3542aa7a3adb79210da6e34e4ac034692 (diff)
Issue #2884715 by timmillwood, Sam152, larowlan, tstoeckler: Initial Content Moderation transitions are not correct
-rw-r--r--core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php2
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php6
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php5
3 files changed, 10 insertions, 3 deletions
diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
index 4a41631..b80ccdd 100644
--- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
+++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
@@ -331,7 +331,7 @@ class ContentModeration extends WorkflowTypeFormBase implements ContainerFactory
*/
public function getInitialState(WorkflowInterface $workflow, $entity = NULL) {
if ($entity instanceof EntityPublishedInterface) {
- return $workflow->getState($entity->isPublished() ? 'published' : 'draft');
+ return $workflow->getState($entity->isPublished() && !$entity->isNew() ? 'published' : 'draft');
}
return parent::getInitialState($workflow);
}
diff --git a/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php b/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php
index 0150d3c..3db6a66 100644
--- a/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php
@@ -77,6 +77,12 @@ class InitialStateTest extends KernelTestBase {
$this->assertEquals('draft', $loaded_unpublished_node->moderation_state->value);
$this->assertEquals('published', $loaded_published_node->moderation_state->value);
$this->assertEquals('draft', $loaded_entity_test->moderation_state->value);
+
+ $presave_node = Node::create([
+ 'type' => 'example',
+ 'title' => 'Presave node',
+ ]);
+ $this->assertEquals('draft', $presave_node->moderation_state->value);
}
}
diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
index 7e9a75c..5a2f6a0 100644
--- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
@@ -64,7 +64,8 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
* Test the field item list when accessing an index.
*/
public function testArrayIndex() {
- $this->assertEquals('published', $this->testNode->moderation_state[0]->value);
+ $this->assertFalse($this->testNode->isPublished());
+ $this->assertEquals('draft', $this->testNode->moderation_state[0]->value);
}
/**
@@ -75,7 +76,7 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
foreach ($this->testNode->moderation_state as $item) {
$states[] = $item->value;
}
- $this->assertEquals(['published'], $states);
+ $this->assertEquals(['draft'], $states);
}
}