Commit 229630f2 authored by voleger's avatar voleger Committed by voleger
Browse files

Issue #3097446 by voleger: Weight override not working as expected

parent faaca68c
......@@ -52,13 +52,13 @@ class QueueWorkerManager extends CoreQueueWorkerManager {
*
* @param array $definitions
* Queue worker definitions.
* @param array $weight
* @param array $weights
* Weight overrides.
*
* @return array
* Reordered Queue worker definitions.
*/
public static function sortDefinitions(array $definitions, array $weight) {
public static function sortDefinitions(array $definitions, array $weights) {
// Prepare definitions for sorting.
foreach ($definitions as $key => &$definition) {
$weight = 0;
......@@ -70,7 +70,9 @@ class QueueWorkerManager extends CoreQueueWorkerManager {
$weight = intval($definition['weight']);
}
// Check weight value overrides.
$definition['weight'] = empty($weight[$key]) ? $weight : intval($weight[$key]);
$definition['weight'] = isset($weights[$key]) ?
intval($weights[$key]) :
$weight;
}
// Sort definitions by weight element.
uasort($definitions, [SortArray::class, 'sortByWeightElement']);
......
......@@ -3,3 +3,5 @@ type: module
description: 'Provides testing definitions for Queue Order module'
package: Testing
core: 8.x
core_version_requirement: ^8 || ^9
order:
queue_order_worker_A: 30
queue_order_worker_B: 20
queue_order_worker_C: 10
queue_order_worker_D: 0
queue_order_worker_E: -10
queue_order_worker_F: -20
name: Queue Order Definitions Test
type: module
description: 'Provides testing definitions for Queue Order module'
package: Testing
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- queue_order:queue_order_definition_fixtures
<?php
namespace Drupal\Tests\queue_order\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Class DefinitionsWithModuleTest.
*
* @package Drupal\queue_order\Tests\Kernel
*
* @group queue_order
*/
class DefinitionsWithOverridesTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'queue_order_overrides_fixtures',
'queue_order',
];
/**
* Queue Worker Manager service.
*
* @var \Drupal\Core\Queue\QueueWorkerManagerInterface
*/
protected $QueueWorkerManager;
protected $orderedList = [
'queue_order_worker_F',
'queue_order_worker_E',
'queue_order_worker_D',
'queue_order_worker_C',
'queue_order_worker_B',
'queue_order_worker_A',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->QueueWorkerManager = $this->container->get('plugin.manager.queue_worker');
}
/**
* Test equality of Queue Worker definition order.
*/
public function testOrder() {
$this->assertEquals(
$this->orderedList,
array_keys($this->QueueWorkerManager->getDefinitions()),
'Order is not managed by the config settings'
);
$this->assertSame(
$this->orderedList,
array_keys($this->QueueWorkerManager->getDefinitions()),
'Order is not managed by the config settings'
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment