Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / ModerationStateFieldItemListTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\node\Entity\Node;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\workflows\Entity\Workflow;
9
10 /**
11  * @coversDefaultClass \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList
12  *
13  * @group content_moderation
14  */
15 class ModerationStateFieldItemListTest extends KernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = [
21     'node',
22     'content_moderation',
23     'user',
24     'system',
25     'language',
26     'workflows',
27   ];
28
29   /**
30    * @var \Drupal\node\NodeInterface
31    */
32   protected $testNode;
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function setUp() {
38     parent::setUp();
39
40     $this->installSchema('node', 'node_access');
41     $this->installEntitySchema('node');
42     $this->installEntitySchema('user');
43     $this->installEntitySchema('content_moderation_state');
44     $this->installConfig('content_moderation');
45
46     $node_type = NodeType::create([
47       'type' => 'example',
48     ]);
49     $node_type->save();
50     $workflow = Workflow::load('editorial');
51     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
52     $workflow->save();
53
54     $this->testNode = Node::create([
55       'type' => 'example',
56       'title' => 'Test title',
57     ]);
58     $this->testNode->save();
59     \Drupal::entityTypeManager()->getStorage('node')->resetCache();
60     $this->testNode = Node::load($this->testNode->id());
61   }
62
63   /**
64    * Test the field item list when accessing an index.
65    */
66   public function testArrayIndex() {
67     $this->assertFalse($this->testNode->isPublished());
68     $this->assertEquals('draft', $this->testNode->moderation_state[0]->value);
69   }
70
71   /**
72    * Test the field item list when iterating.
73    */
74   public function testArrayIteration() {
75     $states = [];
76     foreach ($this->testNode->moderation_state as $item) {
77       $states[] = $item->value;
78     }
79     $this->assertEquals(['draft'], $states);
80   }
81
82 }