+ /**
+ * @covers ::getValue
+ */
+ public function testGetValue() {
+ $this->assertEquals([['value' => 'draft']], $this->testNode->moderation_state->getValue());
+ }
+
+ /**
+ * @covers ::get
+ */
+ public function testGet() {
+ $this->assertEquals('draft', $this->testNode->moderation_state->get(0)->value);
+ $this->setExpectedException(\InvalidArgumentException::class);
+ $this->testNode->moderation_state->get(2);
+ }
+
+ /**
+ * Tests the computed field when it is unset or set to an empty value.
+ */
+ public function testSetEmptyState() {
+ $this->testNode->moderation_state->value = '';
+ $this->assertEquals('draft', $this->testNode->moderation_state->value);
+
+ $this->testNode->moderation_state = '';
+ $this->assertEquals('draft', $this->testNode->moderation_state->value);
+
+ unset($this->testNode->moderation_state);
+ $this->assertEquals('draft', $this->testNode->moderation_state->value);
+ }
+
+ /**
+ * Test the list class with a non moderated entity.
+ */
+ public function testNonModeratedEntity() {
+ $unmoderated_node = Node::create([
+ 'type' => 'unmoderated',
+ 'title' => 'Test title',
+ ]);
+ $unmoderated_node->save();
+ $this->assertEquals(0, $unmoderated_node->moderation_state->count());
+
+ $unmoderated_node->moderation_state = NULL;
+ $this->assertEquals(0, $unmoderated_node->moderation_state->count());
+ }
+