View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class LingotekNodeContentModerationTranslationTest extends LingotekTestBase {
use ContentModerationTestTrait;
public static $modules = [
'block',
'node',
'content_moderation',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
'new_revision' => FALSE,
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'article', TRUE);
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(TRUE)
->save();
\Drupal::service('content_translation.manager')
->setEnabled('node', 'page', TRUE);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$workflow = $this
->createEditorialWorkflow();
$this
->configureContentModeration('editorial', [
'node' => [
'article',
],
]);
$this
->saveLingotekContentTranslationSettingsForNodeTypes([
'article',
'page',
]);
}
public function testNewRevisionCreatedWhenProcessing() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit);
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->clickLink('Llamas are cool');
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$result = $node_storage
->getQuery()
->allRevisions()
->condition('nid', 1)
->sort('vid', 'DESC')
->pager(50)
->count()
->execute();
$this
->assertEqual(1, $result, 'Only one revision is stored.');
$this
->goToContentBulkManagementForm();
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_MX');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_MX translation for node Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_MX');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_MX has been downloaded.');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('es_MX', 'dummy-document-hash-id', 'ES');
$this
->clickLink('Llamas are cool');
$assert_session
->linkExists('Revisions');
$this
->clickLink('Revisions');
$this
->drupalGet('es/node/1/revisions');
$this
->assertText('Document translated into ES by Lingotek.');
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$result = $node_storage
->getQuery()
->allRevisions()
->condition('nid', 1)
->sort('vid', 'DESC')
->pager(50)
->count()
->execute();
$this
->assertEqual(2, $result, 'A new revision is stored.');
}
public function testNoNewRevisionCreatedWhenProcessing() {
$this
->drupalGet('admin/structure/types/manage/page');
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAndPublishNodeForm($edit, 'page');
$this
->goToContentBulkManagementForm();
$this
->assertLingotekUploadLink();
$this
->assertNoLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('Node Llamas are cool has been uploaded.');
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$this
->clickLink('Llamas are cool');
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$result = $node_storage
->getQuery()
->allRevisions()
->condition('nid', 1)
->sort('vid', 'DESC')
->pager(50)
->count()
->execute();
$this
->assertEqual(1, $result, 'Only one revision is stored.');
$this
->goToContentBulkManagementForm();
$this
->assertLingotekCheckSourceStatusLink();
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('EN');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->assertLingotekRequestTranslationLink('es_MX');
$this
->clickLink('ES');
$this
->assertText("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->assertLingotekCheckTargetStatusLink('es_MX');
$this
->clickLink('ES');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.checked_target_locale'));
$this
->assertText('The es_MX translation for node Llamas are cool is ready for download.');
$this
->assertLingotekDownloadTargetLink('es_MX');
$this
->clickLink('ES');
$this
->assertText('The translation of node Llamas are cool into es_MX has been downloaded.');
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.downloaded_locale'));
$this
->assertLingotekWorkbenchLink('es_MX', 'dummy-document-hash-id', 'ES');
$this
->clickLink('Llamas are cool');
$assert_session
->linkNotExists('Revisions');
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$result = $node_storage
->getQuery()
->allRevisions()
->condition('nid', 1)
->sort('vid', 'DESC')
->pager(50)
->count()
->execute();
$this
->assertEqual(1, $result, 'A new revision has not been stored.');
}
}