ModerationContentTranslationTest.php in Drupal 9
File
core/modules/content_moderation/tests/src/Functional/ModerationContentTranslationTest.php
View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class ModerationContentTranslationTest extends BrowserTestBase {
use ContentModerationTestTrait;
protected $adminUser;
protected static $modules = [
'node',
'locale',
'content_translation',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this->rootUser);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
])
->save();
$edit = [
'predefined_langcode' => 'fr',
];
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$this
->drupalGet('admin/config/regional/content-language');
$edit = [
'entity_types[node]' => TRUE,
'settings[node][article][translatable]' => TRUE,
'settings[node][article][settings][language][language_alterable]' => TRUE,
];
$this
->submitForm($edit, 'Save configuration');
$this
->rebuildContainer();
}
public function testModerationWithExistingContent() {
$edit = [
'title[0][value]' => 'Published English node',
'langcode[0][value]' => 'en',
];
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Article Published English node has been created.');
$english_node = $this
->drupalGetNodeByTitle('Published English node');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink('Add');
$edit = [
'title[0][value]' => 'Published French node',
];
$this
->submitForm($edit, 'Save (this translation)');
$this
->assertSession()
->pageTextContains('Article Published French node has been updated.');
\Drupal::service('module_installer')
->install([
'content_moderation',
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'article');
$workflow
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('node/' . $english_node
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'title[0][value]' => 'Published English new node',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Article Published English new node has been updated.');
$this
->drupalGet('fr/node/' . $english_node
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'title[0][value]' => 'Published French new node',
];
$this
->submitForm($edit, 'Save (this translation)');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Article Published French new node has been updated.');
}
}