function LocaleUpdateTest::testEnableUninstallModule

Same name in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableUninstallModule()
  2. 10 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableUninstallModule()
  3. 11.x core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableUninstallModule()

Tests automatic translation import when a module is enabled.

File

core/modules/locale/tests/src/Functional/LocaleUpdateTest.php, line 297

Class

LocaleUpdateTest
Tests for updating the interface translations of projects.

Namespace

Drupal\Tests\locale\Functional

Code

public function testEnableUninstallModule() {
    // Make the hidden test modules look like a normal custom module.
    \Drupal::state()->set('locale.test_system_info_alter', TRUE);
    // Check if there is no translation yet.
    $this->assertTranslation('Tuesday', '', 'de');
    // Enable a module.
    $edit = [
        'modules[locale_test_translate][enable]' => 'locale_test_translate',
    ];
    $this->drupalPostForm('admin/modules', $edit, t('Install'));
    // Check if translations have been imported.
    $this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', [
        '%number' => 7,
        '%update' => 0,
        '%delete' => 0,
    ]), 'One translation file imported.');
    $this->assertTranslation('Tuesday', 'Dienstag', 'de');
    $edit = [
        'uninstall[locale_test_translate]' => 1,
    ];
    $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
    $this->drupalPostForm(NULL, [], t('Uninstall'));
    // Check if the file data is removed from the database.
    $history = locale_translation_get_file_history();
    $this->assertFalse(isset($history['locale_test_translate']), 'Project removed from the file history');
    $projects = locale_translation_get_projects();
    $this->assertFalse(isset($projects['locale_test_translate']), 'Project removed from the project list');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.