3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType;
9 use Drupal\workflows\Entity\Workflow;
12 * Tests the correct default revision is set.
14 * @group content_moderation
16 class DefaultRevisionStateTest extends KernelTestBase {
21 public static $modules = [
29 'content_translation',
35 * @var \Drupal\Core\Entity\EntityTypeManager
37 protected $entityTypeManager;
42 protected function setUp() {
45 $this->installSchema('node', 'node_access');
46 $this->installEntitySchema('node');
47 $this->installEntitySchema('user');
48 $this->installEntitySchema('entity_test_with_bundle');
49 $this->installEntitySchema('entity_test_rev');
50 $this->installEntitySchema('entity_test_mulrevpub');
51 $this->installEntitySchema('block_content');
52 $this->installEntitySchema('content_moderation_state');
53 $this->installConfig('content_moderation');
55 $this->entityTypeManager = $this->container->get('entity_type.manager');
59 * Tests a translatable Node.
61 public function testMultilingual() {
63 ConfigurableLanguage::createFromLangcode('fr')->save();
64 $node_type = NodeType::create([
69 $this->container->get('content_translation.manager')->setEnabled('node', 'example', TRUE);
71 $workflow = Workflow::load('editorial');
72 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
75 $english_node = Node::create([
77 'title' => 'Test title',
83 $this->assertEquals('draft', $english_node->moderation_state->value);
84 $this->assertFalse($english_node->isPublished());
85 $this->assertTrue($english_node->isDefaultRevision());
88 $french_node = $english_node->addTranslation('fr', ['title' => 'French title']);
89 $french_node->moderation_state->value = 'published';
91 $this->assertTrue($french_node->isPublished());
92 $this->assertTrue($french_node->isDefaultRevision());
95 $node = Node::load($english_node->id())->getTranslation('fr');
96 $node->moderation_state->value = 'draft';
98 $this->assertFalse($node->isPublished());
99 $this->assertFalse($node->isDefaultRevision());
102 $latest_revision = $this->entityTypeManager->getStorage('node')->loadRevision(3);
103 $latest_revision->moderation_state->value = 'draft';
104 $latest_revision->save();
105 $this->assertFalse($latest_revision->isPublished());
106 $this->assertFalse($latest_revision->isDefaultRevision());