InstallerLanguageTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Drupal\KernelTests\Core\Installer;
  3. use Drupal\Core\StringTranslation\Translator\FileTranslation;
  4. use Drupal\KernelTests\KernelTestBase;
  5. /**
  6. * Tests for installer language support.
  7. *
  8. * @group Installer
  9. */
  10. class InstallerLanguageTest extends KernelTestBase {
  11. /**
  12. * Tests that the installer can find translation files.
  13. */
  14. public function testInstallerTranslationFiles() {
  15. // Different translation files would be found depending on which language
  16. // we are looking for.
  17. $expected_translation_files = [
  18. NULL => ['drupal-8.0.0-beta2.hu.po', 'drupal-8.0.0.de.po'],
  19. 'de' => ['drupal-8.0.0.de.po'],
  20. 'hu' => ['drupal-8.0.0-beta2.hu.po'],
  21. 'it' => [],
  22. ];
  23. // Hardcode the simpletest module location as we don't yet know where it is.
  24. // @todo Remove as part of https://www.drupal.org/node/2186491
  25. $file_translation = new FileTranslation('core/modules/simpletest/files/translations');
  26. foreach ($expected_translation_files as $langcode => $files_expected) {
  27. $files_found = $file_translation->findTranslationFiles($langcode);
  28. $this->assertTrue(count($files_found) == count($files_expected), format_string('@count installer languages found.', ['@count' => count($files_expected)]));
  29. foreach ($files_found as $file) {
  30. $this->assertTrue(in_array($file->filename, $files_expected), format_string('@file found.', ['@file' => $file->filename]));
  31. }
  32. }
  33. }
  34. /**
  35. * Tests profile info caching in non-English languages.
  36. */
  37. public function testInstallerTranslationCache() {
  38. require_once 'core/includes/install.inc';
  39. // Prime the drupal_get_filename() static cache with the location of the
  40. // testing profile as it is not the currently active profile and we don't
  41. // yet have any cached way to retrieve its location.
  42. // @todo Remove as part of https://www.drupal.org/node/2186491
  43. drupal_get_filename('profile', 'testing', 'core/profiles/testing/testing.info.yml');
  44. $info_en = install_profile_info('testing', 'en');
  45. $info_nl = install_profile_info('testing', 'nl');
  46. $this->assertFalse(in_array('locale', $info_en['dependencies']), 'Locale is not set when installing in English.');
  47. $this->assertTrue(in_array('locale', $info_nl['dependencies']), 'Locale is set when installing in Dutch.');
  48. }
  49. }