Skip to content
Snippets Groups Projects
Commit 520bbcde authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3070354 by tedbow, Wim Leers, xjm, Gábor Hojtsy: Add a test for...

Issue #3070354 by tedbow, Wim Leers, xjm, Gábor Hojtsy: Add a test for locale_translation_build_projects() to unensure that 'core' key does not affect translations URLs
parent e0a8d337
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,15 @@ function locale_test_system_info_alter(&$info, Extension $file, $type) {
$info['hidden'] = FALSE;
}
}
// Alter the name and the core version of the project. This should not affect
// the locale project information.
if (\Drupal::state()->get('locale.test_system_info_alter_name_core')) {
if ($file->getName() == 'locale_test') {
$info['core'] = '8.6.7';
$info['name'] = 'locale_test_alter';
}
}
}
/**
......
<?php
namespace Drupal\Tests\locale\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests building the translatable project information.
*
* @group locale
*/
class LocaleBuildTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'locale',
'locale_test',
'system',
];
/**
* Checks if a list of translatable projects gets built.
*/
public function testBuildProjects() {
$this->container->get('module_handler')->loadInclude('locale', 'compare.inc');
/** @var \Drupal\Core\Extension\ExtensionList $module_list */
$module_list = \Drupal::service('extension.list.module');
// Make the test modules look like a normal custom module. I.e. make the
// modules not hidden. locale_test_system_info_alter() modifies the project
// info of the locale_test and locale_test_translate modules.
\Drupal::state()->set('locale.test_system_info_alter', TRUE);
// Confirm the project name and core value before the module is altered.
$projects = locale_translation_build_projects();
$this->assertSame('locale_test', $projects['locale_test']->name);
$this->assertSame('8.x', $projects['locale_test']->core);
$projects['locale_test']->langcode = 'de';
$this->assertSame('/8.x/locale_test/locale_test-1.2.de.po', locale_translation_build_server_pattern($projects['locale_test'], '/%core/%project/%project-%version.%language.po'));
// Alter both the name and core value of the project.
\Drupal::state()->set('locale.test_system_info_alter_name_core', TRUE);
drupal_static_reset('locale_translation_project_list');
$module_list->reset();
// Confirm the name and core value are changed in $module->info.
$module = $module_list->get('locale_test');
$this->assertSame('locale_test_alter', $module->info['name']);
$this->assertSame('8.6.7', $module->info['core']);
$this->assertSame('locale_test', $module->getName());
// Confirm the name and core value are not changed in the project.
$projects = locale_translation_build_projects();
$this->assertSame('locale_test', $projects['locale_test']->name);
$this->assertSame('8.x', $projects['locale_test']->core);
$projects['locale_test']->langcode = 'de';
$this->assertSame('/8.x/locale_test/locale_test-1.2.de.po', locale_translation_build_server_pattern($projects['locale_test'], '/%core/%project/%project-%version.%language.po'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment