Skip to content
Snippets Groups Projects
Unverified Commit ed9e93f5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2971157 by jhedstrom, Sam152: Moderation state set to default after entity is serialized

parent b989db1a
No related branches found
No related tags found
No related merge requests found
...@@ -141,11 +141,13 @@ public function onChange($delta) { ...@@ -141,11 +141,13 @@ public function onChange($delta) {
public function setValue($values, $notify = TRUE) { public function setValue($values, $notify = TRUE) {
parent::setValue($values, $notify); parent::setValue($values, $notify);
if (isset($this->list[0])) {
$this->valueComputed = TRUE;
}
// If the parent created a field item and if the parent should be notified // If the parent created a field item and if the parent should be notified
// about the change (e.g. this is not initialized with the current value), // about the change (e.g. this is not initialized with the current value),
// update the moderated entity. // update the moderated entity.
if (isset($this->list[0]) && $notify) { if (isset($this->list[0]) && $notify) {
$this->valueComputed = TRUE;
$this->updateModeratedEntity($this->list[0]->value); $this->updateModeratedEntity($this->list[0]->value);
} }
} }
......
...@@ -211,13 +211,39 @@ public function testEntityWithNoWorkflow() { ...@@ -211,13 +211,39 @@ public function testEntityWithNoWorkflow() {
/** /**
* Test the moderation_state field after an entity has been serialized. * Test the moderation_state field after an entity has been serialized.
*
* @dataProvider entityUnserializeTestCases
*/ */
public function testEntityUnserialize() { public function testEntityUnserialize($state, $default, $published) {
$this->testNode->moderation_state->value = 'draft'; $this->testNode->moderation_state->value = $state;
$this->assertEquals($state, $this->testNode->moderation_state->value);
$this->assertEquals($default, $this->testNode->isDefaultRevision());
$this->assertEquals($published, $this->testNode->isPublished());
$unserialized = unserialize(serialize($this->testNode)); $unserialized = unserialize(serialize($this->testNode));
$this->assertEquals('Test title', $unserialized->title->value); $this->assertEquals($state, $unserialized->moderation_state->value);
$this->assertEquals('draft', $unserialized->moderation_state->value); $this->assertEquals($default, $unserialized->isDefaultRevision());
$this->assertEquals($published, $unserialized->isPublished());
}
/**
* Test cases for ::testEntityUnserialize.
*/
public function entityUnserializeTestCases() {
return [
'Default draft state' => [
'draft',
TRUE,
FALSE,
],
'Non-default published state' => [
'published',
TRUE,
TRUE,
],
];
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment