3 namespace Drupal\Tests\content_moderation\Kernel;
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;
12 * Tests the correct initial states are set on install.
14 * @group content_moderation
16 class InitialStateTest extends KernelTestBase {
21 public static $modules = [
31 protected function setUp() {
34 $this->installSchema('node', 'node_access');
35 $this->installEntitySchema('node');
36 $this->installEntitySchema('user');
37 $this->installEntitySchema('entity_test_rev');
41 * Tests the correct initial state.
43 public function testInitialState() {
44 $node_type = NodeType::create([
49 // Test with an entity type that implements EntityPublishedInterface.
50 $unpublished_node = Node::create([
52 'title' => 'Unpublished node',
55 $unpublished_node->save();
57 $published_node = Node::create([
59 'title' => 'Published node',
62 $published_node->save();
64 // Test with an entity type that doesn't implement EntityPublishedInterface.
65 $entity_test = EntityTestRev::create();
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');
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);