View source
<?php
namespace Drupal\workbench_moderation\Tests;
class ModerationLocaleTest extends ModerationStateTestBase {
public static $modules = [
'node',
'workbench_moderation',
'locale',
'content_translation',
];
function testTranslateModeratedContent() {
$this
->drupalLogin($this->rootUser);
$this
->createContentTypeFromUI('Article', 'article', TRUE, [
'draft',
'published',
'archived',
], 'draft');
$edit = [
'predefined_langcode' => 'fr',
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('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
->drupalPostForm(NULL, $edit, t('Save configuration'));
$edit = [
'title[0][value]' => 'Published English node',
'langcode[0][value]' => 'en',
];
$this
->drupalPostForm('node/add/article', $edit, t('Save and Publish'));
$this
->assertText(t('Article Published English node has been created.'));
$english_node = $this
->drupalGetNodeByTitle('Published English node');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink(t('Add'));
$edit = [
'title[0][value]' => 'French node Draft',
];
$this
->drupalPostForm(NULL, $edit, t('Save and Create New Draft (this translation)'));
$this
->assertText(t('Article French node Draft has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Published English node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$edit = [
'title[0][value]' => 'English node',
'langcode[0][value]' => 'en',
];
$this
->drupalPostForm('node/add/article', $edit, t('Save and Create New Draft'));
$this
->assertText(t('Article English node has been created.'));
$english_node = $this
->drupalGetNodeByTitle('English node');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink(t('Add'));
$edit = [
'title[0][value]' => 'French node',
];
$this
->drupalPostForm(NULL, $edit, t('Save and Create New Draft (this translation)'));
$this
->assertText(t('Article French node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('English node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->drupalPostForm('node/' . $english_node
->id() . '/edit', [], t('Save and Publish (this translation)'));
$this
->assertText(t('Article English node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('English node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->assertEqual($english_node->moderation_state->target_id, 'published');
$this
->assertTrue($english_node
->isPublished());
$this
->assertEqual($french_node->moderation_state->target_id, 'draft');
$this
->assertFalse($french_node
->isPublished());
$edit = [
'title[0][value]' => 'Another node',
];
$this
->drupalPostForm('node/add/article', $edit, t('Save and Create New Draft'));
$this
->assertText(t('Article Another node has been created.'));
$english_node = $this
->drupalGetNodeByTitle('Another node');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink(t('Add'));
$edit = [
'title[0][value]' => 'Translated node',
];
$this
->drupalPostForm(NULL, $edit, t('Save and Create New Draft (this translation)'));
$this
->assertText(t('Article Translated node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->drupalPostForm('fr/node/' . $english_node
->id() . '/edit', [], t('Save and Publish (this translation)'));
$this
->assertText(t('Article Translated node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->assertEqual($french_node->moderation_state->target_id, 'published');
$this
->assertTrue($french_node
->isPublished());
$this
->assertEqual($english_node->moderation_state->target_id, 'draft');
$this
->assertFalse($english_node
->isPublished());
$edit = [
'title[0][value]' => 'New draft of translated node',
];
$this
->drupalPostForm('fr/node/' . $english_node
->id() . '/edit', $edit, t('Save and Create New Draft (this translation)'));
$this
->assertText(t('Article New draft of translated node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->assertEqual($french_node->moderation_state->target_id, 'published');
$this
->assertTrue($french_node
->isPublished());
$this
->assertEqual($french_node
->getTitle(), 'Translated node', 'The default revision of the published translation remains the same.');
$edit = [
'new_state' => 'published',
];
$this
->drupalPostForm('fr/node/' . $english_node
->id() . '/latest', $edit, t('Apply'));
$this
->assertText(t('The moderation state has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->assertEqual($french_node->moderation_state->target_id, 'published');
$this
->assertTrue($french_node
->isPublished());
$this
->assertEqual($french_node
->getTitle(), 'New draft of translated node', 'The draft has replaced the published revision.');
$this
->drupalPostForm('node/' . $english_node
->id() . '/edit', [], t('Save and Publish (this translation)'));
$this
->assertText(t('Article Another node has been updated.'));
$this
->drupalPostForm('node/' . $english_node
->id() . '/edit', [], t('Save and Archive (this translation)'));
$this
->assertText(t('Article Another node has been updated.'));
$this
->drupalPostForm('fr/node/' . $english_node
->id() . '/edit', [], t('Save and Archive (this translation)'));
$this
->assertText(t('Article New draft of translated node has been updated.'));
$english_node = $this
->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node
->getTranslation('fr');
$this
->assertEqual($english_node->moderation_state->target_id, 'archived');
$this
->assertFalse($english_node
->isPublished());
$this
->assertEqual($french_node->moderation_state->target_id, 'archived');
$this
->assertFalse($french_node
->isPublished());
}
}