0150d3c6e5f524c329937700aed7832c0864ca22
[yaffs-website] / web / core / modules / content_moderation / tests / src / Kernel / InitialStateTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Kernel;
4
5 use Drupal\entity_test\Entity\EntityTestRev;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\workflows\Entity\Workflow;
10
11 /**
12  * Tests the correct initial states are set on install.
13  *
14  * @group content_moderation
15  */
16 class InitialStateTest extends KernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = [
22     'entity_test',
23     'node',
24     'user',
25     'system',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33
34     $this->installSchema('node', 'node_access');
35     $this->installEntitySchema('node');
36     $this->installEntitySchema('user');
37     $this->installEntitySchema('entity_test_rev');
38   }
39
40   /**
41    * Tests the correct initial state.
42    */
43   public function testInitialState() {
44     $node_type = NodeType::create([
45       'type' => 'example',
46     ]);
47     $node_type->save();
48
49     // Test with an entity type that implements EntityPublishedInterface.
50     $unpublished_node = Node::create([
51       'type' => 'example',
52       'title' => 'Unpublished node',
53       'status' => 0,
54     ]);
55     $unpublished_node->save();
56
57     $published_node = Node::create([
58       'type' => 'example',
59       'title' => 'Published node',
60       'status' => 1,
61     ]);
62     $published_node->save();
63
64     // Test with an entity type that doesn't implement EntityPublishedInterface.
65     $entity_test = EntityTestRev::create();
66     $entity_test->save();
67
68     \Drupal::service('module_installer')->install(['content_moderation'], TRUE);
69     $workflow = Workflow::load('editorial');
70     $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
71     $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
72     $workflow->save();
73
74     $loaded_unpublished_node = Node::load($unpublished_node->id());
75     $loaded_published_node = Node::load($published_node->id());
76     $loaded_entity_test = EntityTestRev::load($entity_test->id());
77     $this->assertEquals('draft', $loaded_unpublished_node->moderation_state->value);
78     $this->assertEquals('published', $loaded_published_node->moderation_state->value);
79     $this->assertEquals('draft', $loaded_entity_test->moderation_state->value);
80   }
81
82 }