Skip to content
Snippets Groups Projects
Verified Commit f0be4c1c authored by Dave Long's avatar Dave Long
Browse files

Revert "Issue #3403337 by alexpott, quietone, Akhil Babu, vakulrai,...

Revert "Issue #3403337 by alexpott, quietone, Akhil Babu, vakulrai, smustgrave, penyaskito, Gábor Hojtsy: The order of the projects coming from locale_translation_get_projects() is not consistent"

This reverts commit cc3f4029.
parent 747d12b9
No related branches found
No related tags found
35 merge requests!12802Issue #3537193 by opauwlo: Add enable absolute path option for CKEditor5 image uploads,!12745Fixed: Path alias language doesn't changes on changing of node language,!12684Issue #3220784,!12537Add ViewsConfigUpdater deprecation support for default_argument_skip_url,!12523Issue #3493858 by vidorado, xavier.masson, smustgrave: Extend ViewsBlockBase...,!122353526426-warning-for-missing,!12212Issue #3445525 by alexpott, japerry, catch, mglaman, longwave: Add BC layer...,!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #112315 passed with warnings
Pipeline: drupal

#112324

    Pipeline: drupal

    #112320

      ......@@ -120,9 +120,6 @@ function hook_locale_translation_projects_alter(&$projects) {
      'info' => [
      'interface translation server pattern' => 'http://example.com/files/translations/%core/%project/%project-%version.%language.po',
      ],
      // An optional key to change the order in which translation files are
      // processed. By default, the projects are sorted alphabetically by key.
      'weight' => 1,
      ];
      }
      ......
      ......@@ -28,14 +28,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
      *
      * @var bool
      */
      protected bool $all = FALSE;
      /**
      * Sorted status flag.
      *
      * @var bool
      */
      protected bool $sorted = FALSE;
      protected static $all = FALSE;
      /**
      * Constructs a State object.
      ......@@ -105,7 +98,6 @@ public function setMultiple(array $data) {
      $this->cache[$key] = $value;
      }
      $this->keyValueStore->setMultiple($data);
      $this->sorted = FALSE;
      }
      /**
      ......@@ -130,7 +122,7 @@ public function deleteMultiple(array $keys) {
      */
      public function resetCache() {
      $this->cache = [];
      $this->sorted = $this->all = FALSE;
      static::$all = FALSE;
      }
      /**
      ......@@ -167,23 +159,11 @@ public function countProjects() {
      * {@inheritdoc}
      */
      public function getAll() {
      if (!$this->all) {
      if (!static::$all) {
      $this->cache = $this->keyValueStore->getAll();
      $this->all = TRUE;
      }
      if (!$this->sorted) {
      uksort($this->cache, function ($a, $b) {
      // Sort by weight, if available, and then by key. This allows locale
      // projects to set a weight, if required, and keeps the order consistent
      // regardless of whether the list is built from code or retrieved from
      // the database.
      $sort = ($this->cache[$a]['weight'] ?? 0) <=> ($this->cache[$b]['weight'] ?? 0);
      return $sort === 0 ? $a <=> $b : $sort;
      });
      $this->sorted = TRUE;
      }
      // Remove any NULL values as these are not valid projects.
      return array_filter($this->cache, fn ($value) => $value !== NULL);
      static::$all = TRUE;
      }
      return $this->cache;
      }
      }
      <?php
      declare(strict_types=1);
      namespace Drupal\Tests\locale\Unit;
      use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
      use Drupal\locale\LocaleProjectStorage;
      use Drupal\Tests\UnitTestCase;
      /**
      * @coversDefaultClass \Drupal\locale\LocaleProjectStorage
      * @group locale
      * @runTestsInSeparateProcesses
      */
      class LocaleProjectStorageTest extends UnitTestCase {
      /**
      * @var \Drupal\locale\LocaleProjectStorage
      */
      private LocaleProjectStorage $projectStorage;
      /**
      * @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory
      */
      private KeyValueMemoryFactory $keyValueMemoryFactory;
      /**
      * {@inheritdoc}
      */
      protected function setUp(): void {
      parent::setUp();
      $this->keyValueMemoryFactory = new KeyValueMemoryFactory();
      $this->projectStorage = new LocaleProjectStorage($this->keyValueMemoryFactory);
      }
      /**
      * Tests that projects are sorted by weight and key.
      */
      public function testSorting(): void {
      // There are no projects.
      $this->assertSame([], $this->projectStorage->getAll());
      // Add project 'b'.
      $this->projectStorage->set('b', ['name' => 'b']);
      $this->assertSame(['b'], array_keys($this->projectStorage->getAll()));
      // Add project 'c' and confirm alphabetical order.
      $this->projectStorage->set('c', ['name' => 'c']);
      $this->assertSame(['b', 'c'], array_keys($this->projectStorage->getAll()));
      // Add project 'a' and confirm 'a' is first.
      $this->projectStorage->set('a', ['name' => 'a']);
      $this->assertSame(['a', 'b', 'c'], array_keys($this->projectStorage->getAll()));
      // Add project 'd' with a negative weight and confirm 'd' is first.
      $this->projectStorage->set('d', ['name' => 'd', 'weight' => -1]);
      $this->assertSame(['d', 'a', 'b', 'c'], array_keys($this->projectStorage->getAll()));
      // Add project 'aa' with a positive weight and confirm 'aa' is last.
      $this->projectStorage->set('aa', ['name' => 'aa', 'weight' => 1]);
      $this->assertSame(['d', 'a', 'b', 'c', 'aa'], array_keys($this->projectStorage->getAll()));
      // Delete project 'a'.
      $this->projectStorage->delete('a');
      $this->assertSame(['d', 'b', 'c', 'aa'], array_keys($this->projectStorage->getAll()));
      // Add project 'e' with a lower negative weight than 'd' and confirm 'e' is
      // first.
      $this->projectStorage->set('e', ['name' => 'e', 'weight' => -5]);
      $this->assertSame(['e', 'd', 'b', 'c', 'aa'], array_keys($this->projectStorage->getAll()));
      // Pretend there is a container rebuild by generating a new
      // LocaleProjectStorage object with the same data.
      $this->projectStorage = new LocaleProjectStorage($this->keyValueMemoryFactory);
      $this->projectStorage->set('z', ['name' => 'z']);
      $this->assertSame(['e', 'd', 'b', 'c', 'z', 'aa'], array_keys($this->projectStorage->getAll()));
      // Now delete all projects.
      $this->projectStorage->deleteAll();
      $this->assertSame([], $this->projectStorage->getAll());
      // Add project 'z' before project 'a' and confirm 'a' is first.
      $this->projectStorage->set('z', ['name' => 'z']);
      $this->projectStorage->set('a', ['name' => 'a']);
      $this->assertSame(['a', 'z'], array_keys($this->projectStorage->getAll()));
      }
      /**
      * Tests deleted projects are not included in the count.
      */
      public function testDelete(): void {
      $this->projectStorage->set('b', ['name' => 'b']);
      $this->assertSame(['name' => 'b'], $this->projectStorage->get('b'));
      $this->assertSame(1, $this->projectStorage->countProjects());
      $this->projectStorage->delete('b');
      $this->assertNull($this->projectStorage->get('b'));
      $this->assertSame(0, $this->projectStorage->countProjects());
      }
      }
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Please register or to comment