Commit aec68060 authored by catch's avatar catch
Browse files

fix: #3609020 BC layer in locale_translation_get_projects() implemented incorrectly

By: alexpott
By: nicxvan
(cherry picked from commit a009581e)
parent 1908b48d
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@
 */
function locale_translation_get_projects(array $project_names = []) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal::service(LocaleProjectRepository::class)->getAll() or \Drupal::service(LocaleProjectRepository::class)->getMultiple($project_names) instead. See https://www.drupal.org/node/3569330', E_USER_DEPRECATED);
  if (empty($project_names)) {
    return \Drupal::service(LocaleProjectRepository::class)->getAll();
  }
  return \Drupal::service(LocaleProjectRepository::class)->getMultiple($project_names);
}

+14 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\locale\LocaleProjectRepository;
use Drupal\locale\LocaleSource;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
@@ -65,4 +66,17 @@ public function testBuildProjects(): void {
    $this->assertSame('/all/locale_test/locale_test-1.2.de.po', \Drupal::service(LocaleSource::class)->buildServerPattern($projects['locale_test'], '/%core/%project/%project-%version.%language.po'));
  }

  /**
   * Tests deprecated function locale_translation_get_projects().
   */
  #[IgnoreDeprecations]
  public function testLocaleTranslationGetProjects() : void {
    \Drupal::state()->set('locale.test_system_info_alter', TRUE);
    $this->expectUserDeprecationMessage('locale_translation_get_projects() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal::service(LocaleProjectRepository::class)->getAll() or \Drupal::service(LocaleProjectRepository::class)->getMultiple($project_names) instead. See https://www.drupal.org/node/3569330');
    $this->container->get('module_handler')->loadInclude('locale', 'translation.inc');
    $this->assertCount(2, locale_translation_get_projects());
    $this->assertCount(1, locale_translation_get_projects(['locale_test']));
    $this->assertCount(0, locale_translation_get_projects(['does_not_exist']));
  }

}