[random test failure] MenuUiTest::testMenuAdministration

Created on 12 September 2023, about 1 year ago
Updated 18 September 2023, about 1 year ago

Problem/Motivation

Drupal\Tests\menu_ui\Functional\MenuUiTest

fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-642.xml:
PHPUnit Test failed to complete; Error: PHPUnit 9.6.8 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\menu_ui\Functional\MenuUiTest
F.......                                                            8 / 8 (100%)

Time: 02:29.355, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuAdministration
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'/subdirectory/admin/structure/menu/manage/t8x04qjq'
+'/subdirectory/admin/structure/menu/manage/t66ruoln'

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:96
/var/www/html/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php:220
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Steps to reproduce

When the menu labels consist of consist of one letter followed by two or more numbers the sorting used in \Drupal\Core\Config\Entity\ConfigEntityBase::sort() is not exactly equal to sort().

This is because ConfigEntityBase::sort() uses a "natural order" algorithm (strnatcasecmp).

For example ['z41o8b7c', 'z5bwlcnj']:
- Sorted using sort(): ['z41o8b7c', 'z5bwlcnj'] (See #2 🐛 [random test failure] MenuUiTest::testMenuAdministration Active )
- Sorted using \Drupal\Core\Config\Entity\ConfigEntityBase::sort(): ['z5bwlcnj', 'z41o8b7c'] (See #3 🐛 [random test failure] MenuUiTest::testMenuAdministration Active )

Besides the above there's another problem:

The test uses paging and that seems to use a non-"natural order" algorithm, creating failures when the first link on the second page (which is tested in the test)

So for example 's8apdikd' and 's57l1jpq' on the above positions will fail, since the natural sort will put 's8apdikd' after 's57l1jpq', whilst the non-natural sorting of the pager will put 's8apdikd' before 's57l1jpq'. This basically makes testing the first link on a paged list unreliable.

Proposed resolution

The sorting used in \Drupal\Core\Config\Entity\ConfigEntityBase::sort() is not exactly equal to sort().
At least not when the menu labels consist of one letter followed by two or more numbers.

Use \Drupal\Core\Config\Entity\ConfigEntityBase::sort() instead sort().

Also accommodate the current sorting-behaviour of the pager which is non-natural sorting, whilst the test currently expects it to be naturally sorted.

Most probably needs a follow-up issue to determine if the current sorting of the pager is correct (I personally don't think so) and if this should and can be changed without BC-breakage.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
PHPUnit 

Last updated about 10 hours ago

Created by

🇳🇱Netherlands spokje

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024