class ModerationContentTranslationTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/content_moderation/tests/src/Functional/ModerationContentTranslationTest.php \Drupal\Tests\content_moderation\Functional\ModerationContentTranslationTest
- 9 core/modules/content_moderation/tests/src/Functional/ModerationContentTranslationTest.php \Drupal\Tests\content_moderation\Functional\ModerationContentTranslationTest
Test content_moderation functionality with content_translation.
@group content_moderation
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\content_moderation\Functional\ModerationContentTranslationTest uses ContentModerationTestTrait
Expanded class hierarchy of ModerationContentTranslationTest
File
- core/
modules/ content_moderation/ tests/ src/ Functional/ ModerationContentTranslationTest.php, line 13
Namespace
Drupal\Tests\content_moderation\FunctionalView source
class ModerationContentTranslationTest extends BrowserTestBase {
use ContentModerationTestTrait;
/**
* A user with permission to bypass access content.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'node',
'locale',
'content_translation',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this->rootUser);
// Create an Article content type.
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
])
->save();
$edit = [
'predefined_langcode' => 'fr',
];
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
// Enable content translation on articles.
$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');
// Adding languages requires a container rebuild in the test running
// environment so that multilingual services are used.
$this
->rebuildContainer();
}
/**
* Tests existing translations being edited after enabling content moderation.
*/
public function testModerationWithExistingContent() {
// Create a published article in English.
$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');
// Add a French translation.
$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.');
// Install content moderation and enable moderation on Article node type.
\Drupal::service('module_installer')
->install([
'content_moderation',
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'article');
$workflow
->save();
$this
->drupalLogin($this->rootUser);
// Edit the English node.
$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.');
// Edit the French translation.
$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.');
}
}