View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\lingotek\Lingotek;
use Drupal\node\Entity\NodeType;
class LingotekContentTypeTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'image',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'header',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'header',
'weight' => -10,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
}
public function testContentTypeTranslation() {
$assert_session = $this
->assertSession();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'content_type');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink(t('Upload'));
$this
->assertText(t('Article uploaded successfully'));
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertEqual(3, count($data));
$this
->assertTrue(array_key_exists('name', $data));
$this
->assertTrue(array_key_exists('description', $data));
$this
->assertTrue(array_key_exists('help', $data));
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');
$this
->clickLink(t('Check upload status'));
$this
->assertText(t('Article status checked successfully'));
$this
->clickLink(t('Request translation'));
$this
->assertText(t('Translation to es_MX requested successfully'));
$this
->assertIdentical('es_MX', \Drupal::state()
->get('lingotek.added_target_locale'));
$this
->clickLink(t('Check Download'));
$this
->assertText(t('Translation to es_MX status checked successfully'));
$this
->clickLink('Download');
$this
->assertText(t('Translation to es_MX downloaded successfully'));
$basepath = \Drupal::request()
->getBasePath();
$assert_session
->linkByHrefExists($basepath . '/admin/structure/types/manage/article/translate/es/edit');
}
public function testEditedContentTypeTranslation() {
$assert_session = $this
->assertSession();
$this
->testContentTypeTranslation();
ConfigurableLanguage::createFromLangcode('eu')
->setThirdPartySetting('lingotek', 'locale', 'eu_ES')
->save();
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->clickLink(t('Translate'));
$assert_session
->linkByHrefExists('admin/lingotek/config/request/node_type/article/eu_ES');
$assert_session
->linkByHrefNotExists('admin/lingotek/config/request/node_type/article/es_MX');
$this
->clickLink('Check Download');
$this
->assertText('Translation to es_MX status checked successfully');
$this
->clickLink('Download');
$this
->assertText('Translation to es_MX downloaded successfully');
}
public function testLanguageDisabled() {
$assert_session = $this
->assertSession();
$italian = ConfigurableLanguage::createFromLangcode('it')
->setThirdPartySetting('lingotek', 'locale', 'it_IT');
$italian
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink(t('Upload'));
$this
->assertText(t('Article uploaded successfully'));
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertEqual(3, count($data));
$this
->assertTrue(array_key_exists('name', $data));
$this
->assertTrue(array_key_exists('description', $data));
$this
->assertTrue(array_key_exists('help', $data));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');
$this
->clickLink('Check upload status');
$this
->assertText(t('Article status checked successfully'));
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/node_type/article/it_IT');
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/node_type/article/es_MX');
$assert_session
->linkByHrefExists('/admin/structure/types/manage/article/translate/it/add');
$assert_session
->linkByHrefExists('/admin/structure/types/manage/article/translate/es/add');
$lingotek_config = \Drupal::service('lingotek.configuration');
$lingotek_config
->disableLanguage($italian);
$this
->drupalGet('/admin/structure/types/manage/article/translate');
$assert_session
->linkByHrefNotExists('/admin/lingotek/config/request/node_type/article/it_IT');
$assert_session
->linkByHrefExists('/admin/lingotek/config/request/node_type/article/es_MX');
$assert_session
->linkByHrefExists('/admin/structure/types/manage/article/translate/it/add');
$assert_session
->linkByHrefExists('/admin/structure/types/manage/article/translate/es/add');
}
public function testUploadingWithAnError() {
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article upload failed. Please try again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
}
public function testUploadingWithAPaymentRequiredError() {
\Drupal::state()
->set('lingotek.must_payment_required_error_in_upload', TRUE);
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
}
public function testUploadingWithAPaymentRequiredErrorViaAutomaticUpload() {
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
\Drupal::state()
->set('lingotek.must_payment_required_error_in_upload', TRUE);
$edit = [
'name' => 'Landing Page',
'type' => 'landing_page',
];
$this
->drupalPostForm('admin/structure/types/add', $edit, 'Save content type');
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$nodeType = NodeType::load('landing_page');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
}
public function testUpdatingWithAPaymentRequiredError() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost has been updated.');
}
public function testUpdatingWithAPaymentRequiredErrorViaAutomaticUpload() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', TRUE);
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->assertText('Community has been disabled. Please contact support@lingotek.com to re-enable your community.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_payment_required_error_in_update', FALSE);
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost has been updated.');
}
public function testUpdatingWithAnError() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost update failed. Please try again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_error_in_upload', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost has been updated.');
}
public function testUpdatingWithAnErrorViaAutomaticUpload() {
$edit = [
'name' => 'Landing Page',
'type' => 'landing_page',
];
$this
->drupalPostForm('admin/structure/types/add', $edit, 'Save content type');
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$edit['name'] = 'Landing Page EDITED';
$this
->drupalPostForm('/admin/structure/types/manage/landing_page', $edit, t('Save content type'));
$this
->assertText('The update for node_type Landing Page EDITED failed. Please try again.');
$nodeType = NodeType::load('landing_page');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
}
public function testUpdatingWithADocumentArchivedError() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Document Blogpost has been archived. Please upload again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_UNTRACKED, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost uploaded successfully');
}
public function testUpdatingWithADocumentLockedError() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', TRUE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Document node_type Blogpost has a new version. The document id has been updated for all future interactions. Please try again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_EDITED, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', FALSE);
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost has been updated.');
}
public function testUpdatingWithADocumentLockedErrorViaAutomaticUpload() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', TRUE);
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->assertText('Document node_type Blogpost has a new version. The document id has been updated for all future interactions. Please try again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_EDITED, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_locked_error_in_update', FALSE);
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost has been updated.');
}
public function testUpdatingWithADocumentArchivedErrorViaAutomaticUpload() {
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Article uploaded successfully');
$this
->clickLink('Check upload status');
$this
->assertText('Article status checked successfully');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', TRUE);
$edit['name'] = 'Blogpost';
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->assertText('The content type Blogpost has been updated.');
$this
->assertText('Document node_type Blogpost has been archived. Please upload again.');
$nodeType = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_UNTRACKED, $source_status, 'The node type has been marked as error.');
\Drupal::state()
->set('lingotek.must_document_archived_error_in_update', FALSE);
$this
->clickLink(t('Translate'));
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$this
->assertText('Blogpost uploaded successfully');
}
public function testUploadingWithAnErrorViaAutomaticUpload() {
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
\Drupal::state()
->set('lingotek.must_error_in_upload', TRUE);
$this
->drupalGet('admin/lingotek/settings');
$edit = [
'name' => 'Landing Page',
'type' => 'landing_page',
];
$this
->drupalPostForm('admin/structure/types/add', $edit, 'Save content type');
$this
->assertText('The upload for node_type Landing Page failed. Please try again.');
$nodeType = NodeType::load('landing_page');
$translation_service = \Drupal::service('lingotek.config_translation');
$source_status = $translation_service
->getSourceStatus($nodeType);
$this
->assertEqual(Lingotek::STATUS_ERROR, $source_status, 'The node type has been marked as error.');
}
public function testTranslatingFromUnexistingLocale() {
$this
->drupalCreateContentType([
'type' => 'aaa_test_content_type',
'name' => 'AAA Test Content Type',
'langcode' => 'nap',
]);
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/node_type');
$this
->clickLink('Translate');
$this
->assertText('Translations for AAA Test Content Type content type');
$this
->assertText('Unknown (nap) (original)');
}
}