Pull merge.
[yaffs-website] / web / core / modules / content_moderation / tests / src / Functional / ModerationContentTranslationTest.php
1 <?php
2
3 namespace Drupal\Tests\content_moderation\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
7
8 /**
9  * Test content_moderation functionality with content_translation.
10  *
11  * @group content_moderation
12  */
13 class ModerationContentTranslationTest extends BrowserTestBase {
14
15   use ContentModerationTestTrait;
16
17   /**
18    * A user with permission to bypass access content.
19    *
20    * @var \Drupal\Core\Session\AccountInterface
21    */
22   protected $adminUser;
23
24   /**
25    * Modules to enable.
26    *
27    * @var array
28    */
29   public static $modules = [
30     'node',
31     'locale',
32     'content_translation',
33   ];
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function setUp() {
39     parent::setUp();
40     $this->drupalLogin($this->rootUser);
41     // Create an Article content type.
42     $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article'])->save();
43     $edit = [
44       'predefined_langcode' => 'fr',
45     ];
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');
49     $edit = [
50       'entity_types[node]' => TRUE,
51       'settings[node][article][translatable]' => TRUE,
52       'settings[node][article][settings][language][language_alterable]' => TRUE,
53     ];
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();
58   }
59
60   /**
61    * Tests existing translations being edited after enabling content moderation.
62    */
63   public function testModerationWithExistingContent() {
64     // Create a published article in English.
65     $edit = [
66       'title[0][value]' => 'Published English node',
67       'langcode[0][value]' => 'en',
68     ];
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');
72
73     // Add a French translation.
74     $this->drupalGet('node/' . $english_node->id() . '/translations');
75     $this->clickLink('Add');
76     $edit = [
77       'title[0][value]' => 'Published French node',
78     ];
79     $this->drupalPostForm(NULL, $edit, 'Save (this translation)');
80     $this->assertSession()->pageTextContains('Article Published French node has been updated.');
81
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');
86     $workflow->save();
87     $this->drupalLogin($this->rootUser);
88
89     // Edit the English node.
90     $this->drupalGet('node/' . $english_node->id() . '/edit');
91     $this->assertSession()->statusCodeEquals(200);
92     $edit = [
93       'title[0][value]' => 'Published English new node',
94     ];
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);
101     $edit = [
102       'title[0][value]' => 'Published French new node',
103     ];
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.');
107   }
108
109 }