Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D9 Run batch process during pm-enable when needed. #3446

Merged
merged 11 commits into from
Mar 22, 2018
3 changes: 3 additions & 0 deletions src/Drupal/Commands/pm/PmCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function enable(array $modules)
if (!$this->getModuleInstaller()->install($modules, true)) {
throw new \Exception('Unable to install modules.');
}
if (batch_get()) {
drush_backend_batch_process();
}
$this->logger()->success(dt('Successfully enabled: !list', $todo_str));
// Our logger got blown away during the container rebuild above.
$boot = Drush::bootstrapManager()->bootstrap();
Expand Down
53 changes: 53 additions & 0 deletions tests/PmEnLocaleImportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Unish;

use Drupal\Core\Language\Language;
use Drupal\language\Entity\ConfigurableLanguage;
use Webmozart\PathUtil\Path;

/**
* @group slow
* @group pm
*/
class PmEnLocaleImportCase extends CommandUnishTestCase
{

public function testBatchImportTranslations()
{
$sites = $this->setUpDrupal(1, true);
$uri = key($sites);
$root = $this->webroot();
$options = array(
'root' => $root,
'uri' => $uri,
);

$this->drush('pm-enable', ['language', 'locale', 'dblog'], $options);
$this->drush('config-set', ['locale.settings', 'translation.import_enabled', true], $options);

// Setup the interface translation system and prepare a source translation file.
// The test uses a local po file as translation source. This po file will be
// imported from the translations directory when a module is enabled.
$this->drush('config-set', ['locale.settings', 'translation.use_source', 'locale'], $options);
$this->drush('config-set', ['locale.settings', 'translation.default_filename', '%project.%language.po'], $options);
$this->drush('config-set', ['locale.settings', 'translation.path', '../translations'], $options);
$source = Path::join(__DIR__, '/resources/devel.nl.po');
$translationDir = Path::join($root, '../translations');
$this->mkdir($translationDir);
copy($source, $translationDir . '/devel.nl.po');

$this->drush('php-eval', ['\Drupal\language\Entity\ConfigurableLanguage::create([
"id" => "nl",
"label" => "Dutch",
])->save()']);

$this->drush('pm-enable', ['devel'], $options);
$this->drush('watchdog-show', [], $options);
$this->assertContains('Translations imported:', $this->getSimplifiedOutput());

// Clean up the mess this test creates.
unlink($translationDir . '/devel.nl.po');
rmdir($translationDir);
}
}
15 changes: 15 additions & 0 deletions tests/resources/devel.nl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Mock Dutch translation of Devel
#
msgid ""
msgstr ""
"Project-Id-Version: Devel\n"
"POT-Creation-Date: 2016-12-18 21:58+0000\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Language-Team: Dutch\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"

msgid "Devel"
msgstr "NL Devel"