View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
class LingotekModuleUninstallationWithDataTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
];
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',
]);
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);
drupal_static_reset();
\Drupal::entityTypeManager()
->clearCachedDefinitions();
$this
->applyEntityUpdates();
$this
->rebuildContainer();
$this
->saveLingotekContentTranslationSettingsForNodeTypes();
}
public function testUninstallModule() {
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->rootUser);
$this
->createAndDownloadANodeTranslation();
$this
->drupalGet('/admin/modules');
$this
->assertSession()
->checkboxChecked('edit-modules-lingotek-enable');
$this
->clickLink('Uninstall');
$this
->assertSession()
->fieldDisabled('edit-uninstall-lingotek');
$this
->assertText('The following reasons prevent Lingotek Translation from being uninstalled:');
$edit = [
'uninstall[lingotek_test]' => '1',
];
$this
->drupalPostForm(NULL, $edit, 'Uninstall');
$this
->drupalPostForm(NULL, [], 'Uninstall');
$this
->assertText('The selected modules have been uninstalled.');
$this
->assertText('The following reason prevents Lingotek Translation from being uninstalled:');
$this
->assertText('There is content for the entity type: Lingotek Content Metadata');
$assert_session
->linkExists('Remove lingotek content metadata entities');
$this
->assertSession()
->fieldDisabled('edit-uninstall-lingotek');
$this
->clickLink('Remove lingotek content metadata entities');
$this
->assertText('Are you sure you want to delete all lingotek content metadata entities?');
$this
->assertText('This will delete 1 lingotek content metadata.');
$this
->drupalPostForm(NULL, [], 'Delete all lingotek content metadata entities');
$this
->assertFalse($this
->getSession()
->getPage()
->findField('edit-uninstall-lingotek')
->hasAttribute('disabled'));
$edit = [
'uninstall[lingotek]' => '1',
];
$this
->drupalPostForm(NULL, $edit, 'Uninstall');
$this
->assertText('The following modules will be completely uninstalled from your site, and all data from these modules will be lost!');
$this
->assertText('The listed configuration will be deleted.');
$this
->assertText('Lingotek Profile');
$this
->drupalPostForm(NULL, [], 'Uninstall');
$this
->assertText('The selected modules have been uninstalled.');
}
protected function createAndDownloadANodeTranslation() {
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$edit['langcode[0][value]'] = 'en';
$this
->saveAndPublishNodeForm($edit);
$this
->clickLink('Translate');
$this
->clickLink('Upload');
$this
->checkForMetaRefresh();
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertUploadedDataFieldCount($data, 2);
$this
->assertTrue(isset($data['title'][0]['value']));
$this
->assertEqual(1, count($data['body'][0]));
$this
->assertTrue(isset($data['body'][0]['value']));
$this
->assertIdentical('en_US', \Drupal::state()
->get('lingotek.uploaded_locale'));
$used_profile = \Drupal::state()
->get('lingotek.used_profile');
$this
->assertIdentical('manual', $used_profile, 'The manual profile was used.');
$this
->clickLink('Check Upload Status');
$this
->assertText('The import for node Llamas are cool is complete.');
$this
->clickLink('Request translation');
$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
->clickLink('Check translation status');
$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
->clickLink('Download completed translation');
$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'));
}
}