3 namespace Drupal\Tests\content_moderation\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
9 * Test content_moderation functionality with content_translation.
11 * @group content_moderation
13 class ModerationContentTranslationTest extends BrowserTestBase {
15 use ContentModerationTestTrait;
18 * A user with permission to bypass access content.
20 * @var \Drupal\Core\Session\AccountInterface
29 public static $modules = [
32 'content_translation',
38 protected function setUp() {
40 $this->drupalLogin($this->rootUser);
41 // Create an Article content type.
42 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article'])->save();
44 'predefined_langcode' => 'fr',
46 $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
47 // Enable content translation on articles.
48 $this->drupalGet('admin/config/regional/content-language');
50 'entity_types[node]' => TRUE,
51 'settings[node][article][translatable]' => TRUE,
52 'settings[node][article][settings][language][language_alterable]' => TRUE,
54 $this->drupalPostForm(NULL, $edit, 'Save configuration');
55 // Adding languages requires a container rebuild in the test running
56 // environment so that multilingual services are used.
57 $this->rebuildContainer();
61 * Tests existing translations being edited after enabling content moderation.
63 public function testModerationWithExistingContent() {
64 // Create a published article in English.
66 'title[0][value]' => 'Published English node',
67 'langcode[0][value]' => 'en',
69 $this->drupalPostForm('node/add/article', $edit, 'Save');
70 $this->assertSession()->pageTextContains('Article Published English node has been created.');
71 $english_node = $this->drupalGetNodeByTitle('Published English node');
73 // Add a French translation.
74 $this->drupalGet('node/' . $english_node->id() . '/translations');
75 $this->clickLink('Add');
77 'title[0][value]' => 'Published French node',
79 $this->drupalPostForm(NULL, $edit, 'Save (this translation)');
80 $this->assertSession()->pageTextContains('Article Published French node has been updated.');
82 // Install content moderation and enable moderation on Article node type.
83 \Drupal::service('module_installer')->install(['content_moderation']);
84 $workflow = $this->createEditorialWorkflow();
85 $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');
87 $this->drupalLogin($this->rootUser);
89 // Edit the English node.
90 $this->drupalGet('node/' . $english_node->id() . '/edit');
91 $this->assertSession()->statusCodeEquals(200);
93 'title[0][value]' => 'Published English new node',
95 $this->drupalPostForm(NULL, $edit, 'Save');
96 $this->assertSession()->statusCodeEquals(200);
97 $this->assertSession()->pageTextContains('Article Published English new node has been updated.');
98 // Edit the French translation.
99 $this->drupalGet('fr/node/' . $english_node->id() . '/edit');
100 $this->assertSession()->statusCodeEquals(200);
102 'title[0][value]' => 'Published French new node',
104 $this->drupalPostForm(NULL, $edit, 'Save (this translation)');
105 $this->assertSession()->statusCodeEquals(200);
106 $this->assertSession()->pageTextContains('Article Published French new node has been updated.');