d37f5d8ec4a982adf4d5a9e03e58a04c011cf365
[yaffs-website] / web / core / modules / content_translation / tests / src / Functional / ContentTranslationOutdatedRevisionTranslationTest.php
1 <?php
2
3 namespace Drupal\Tests\content_translation\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\language\Entity\ConfigurableLanguage;
7
8 /**
9  * Tests the "Flag as outdated" functionality with revision translations.
10  *
11  * @group content_translation
12  */
13 class ContentTranslationOutdatedRevisionTranslationTest extends ContentTranslationPendingRevisionTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setUp() {
19     parent::setUp();
20     $this->enableContentModeration();
21   }
22
23   /**
24    * Tests that outdated revision translations work correctly.
25    */
26   public function testFlagAsOutdatedHidden() {
27     // Create a test node.
28     $values = [
29       'title' => 'Test 1.1 EN',
30       'moderation_state' => 'published',
31     ];
32     $id = $this->createEntity($values, 'en');
33     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
34     $entity = $this->storage->load($id);
35
36     // Add a published Italian translation.
37     $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
38         $entity->getEntityTypeId() => $id,
39         'source' => 'en',
40         'target' => 'it',
41       ],
42       [
43         'language' => ConfigurableLanguage::load('it'),
44         'absolute' => FALSE,
45       ]
46     );
47     $this->drupalGet($add_translation_url);
48     $this->assertFlagWidget();
49     $edit = [
50       'title[0][value]' => 'Test 1.2 IT',
51       'moderation_state[0][state]' => 'published',
52     ];
53     $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
54
55     // Add a published French translation.
56     $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
57         $entity->getEntityTypeId() => $id,
58         'source' => 'en',
59         'target' => 'fr',
60       ],
61       [
62         'language' => ConfigurableLanguage::load('fr'),
63         'absolute' => FALSE,
64       ]
65     );
66     $this->drupalGet($add_translation_url);
67     $this->assertFlagWidget();
68     $edit = [
69       'title[0][value]' => 'Test 1.3 FR',
70       'moderation_state[0][state]' => 'published',
71     ];
72     $this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
73
74     // Create an English draft.
75     $entity = $this->storage->loadUnchanged($id);
76     $en_edit_url = $this->getEditUrl($entity);
77     $this->drupalGet($en_edit_url);
78     $this->assertFlagWidget();
79   }
80
81   /**
82    * Checks whether the flag widget is displayed.
83    */
84   protected function assertFlagWidget() {
85     $this->assertSession()->pageTextNotContains('Flag other translations as outdated');
86     $this->assertSession()->pageTextContains('Translations cannot be flagged as outdated when content is moderated.');
87   }
88
89 }