installSchema('node', 'node_access'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installEntitySchema('content_moderation_state'); $this->installConfig('content_moderation'); $node_type = NodeType::create([ 'type' => 'example', ]); $node_type->save(); $workflow = Workflow::load('editorial'); $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example'); $workflow->save(); $this->testNode = Node::create([ 'type' => 'example', 'title' => 'Test title', ]); $this->testNode->save(); \Drupal::entityTypeManager()->getStorage('node')->resetCache(); $this->testNode = Node::load($this->testNode->id()); } /** * Test the field item list when accessing an index. */ public function testArrayIndex() { $this->assertFalse($this->testNode->isPublished()); $this->assertEquals('draft', $this->testNode->moderation_state[0]->value); } /** * Test the field item list when iterating. */ public function testArrayIteration() { $states = []; foreach ($this->testNode->moderation_state as $item) { $states[] = $item->value; } $this->assertEquals(['draft'], $states); } }