magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Fixes problem with latest versions of ICU library where AmPmMarkers i…

Open hostep opened this issue 1 year ago • 11 comments

…s no longer defined for each locale. If that's the case fall back to AmPmMarkersAbbr and if that one doesn't exist, fallback to null. This fixes a second problem where previously we always returned 'null' due to the index being a string instead of an integer. That's also fixed now.

Description (*)

See discussions in #38214

The second commit in this PR is to deal with static test failures where a method can contain at most 100 lines, which we just managed to reach with the change in the first commit.

I think this is quite an important fix, because an update of the ICU library on a server will start crashing the shop on every frontend page that contains a JS calendar widget. So if a Linux operating system decides to upgrade to a different version of ICU, your shop might be in trouble despite no other changes have being made to it. Which could be surprising to the merchant & developers. Maybe it's worth turning this into a quality patch as every Magento version might run into this issue one day or another.

Here's an example of how this data is defined in ICU:

  • English: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/en.txt#L783-L802
  • Swedish: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/sv.txt#L695-L698
  • German: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/de.txt#L484 (nothing is here)

This PR fixes the problem mentioned in the issue and fixes a second bug that has existed since forever in Magento where we always outputted null to the am & pm variables that get exposed in the phtml files that use this block. This was due to using ['0'] and ['1'] instead of [0] & [1]

After some thinking, I decided to implement a fallback system, where we first try to fetch AmPmMarkers. If that doesn't exists, try fetching AmPmMarkersAbbr and if that doesn't exists, fallback to null.

As far as I can see, these am and pm variable assignments aren't used in core Magento, but are send to the calendar.phtml file and can be outputted with <?= $am; ?> and <?= $pm; ?>. So that if custom theme needs this info, they can use it.

I've added some more locale's to be tested in the unit tests, those will also fail without the fixes proposed here when the ICU library is 74.1 or 74.2

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes #38214

Manual testing scenarios (*)

  1. Setup clean Magento
  2. In backoffice, go to Stores > Attributes > Product
  3. Find and edit the special_from_date attribute
  4. Under Storefront Properties, enable both 'Use in Search' and 'Visible in Advanced Search' and save the attribute
  5. Reindex
  6. Edit the file app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml and add this line at the very bottom: <ul><li>am: <?= $am; ?></li><li>pm: <?= $pm; ?></li></ul>
  7. Configure "lv_LV" locale: bin/magento config:set general/locale/code lv_LV
  8. Flush the caches
  9. In frontend click on the Advanced Search link in the footer
  10. Expected to see "priekšpusdienā" & "pēcpusdienā" (but then escaped for JS)
  11. Configure "sv_SE" locale: bin/magento config:set general/locale/code sv_SE
  12. Flush the caches
  13. In frontend click on the Advanced Search link in the footer
  14. Expected to see "fm" & "em"
  15. Configure "de_AT" locale: bin/magento config:set general/locale/code de_AT
  16. Flush the caches
  17. In frontend click on the Advanced Search link in the footer
  18. Expected to see "null" & "null"

The biggest thing to check for is that this page doesn't crash. It will not crash with older versions of the ICU library but will crash without these fixes with ICU 74.1 or 74.2. The output for "de_AT" will also be different when using older versions of the ICU library.

Questions or comments

Contribution checklist (*)

  • [x] Pull request has a meaningful description of its purpose
  • [x] All commits are accompanied by meaningful commit messages
  • [ ] All new or changed code is covered with unit/integration tests (if applicable)
  • [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • [ ] All automated tests passed successfully (all builds are green)

hostep avatar Jan 18 '24 16:01 hostep

Hi @hostep. Thank you for your contribution! Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

:exclamation: Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s) For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here :information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation. Join Magento Community Engineering Slack and ask your questions in #github channel.

m2-assistant[bot] avatar Jan 18 '24 16:01 m2-assistant[bot]

@magento run all tests

hostep avatar Jan 18 '24 16:01 hostep

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@magento run all tests

hostep avatar Jan 18 '24 20:01 hostep

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@magento run all tests

hostep avatar Jan 18 '24 22:01 hostep

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

Hello @hostep Thank you for your contribution Looks like the failed tests are not related on your changes

andrewbess avatar Jan 19 '24 06:01 andrewbess

@magento run Functional Tests B2B, WebAPI Tests

andrewbess avatar Jan 19 '24 06:01 andrewbess

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

I don't see why that DevExperience label was added? Because this will cause issues on production environments once the ICU library used by PHP is at the latest version...

hostep avatar Feb 01 '24 09:02 hostep

@magento run all tests

engcom-Echo avatar Mar 07 '24 08:03 engcom-Echo

:heavy_check_mark: QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Manual testing scenario: We have followed steps from comment

Before: :heavy_multiplication_x:  Screenshot 2024-03-07 at 1 17 20 PM

After: :heavy_check_mark:   Screenshot 2024-03-07 at 1 30 49 PM

Builds are failed. Hence, moving this PR to Extended Testing.

engcom-Echo avatar Mar 07 '24 10:03 engcom-Echo

@magento run all tests

engcom-Echo avatar Mar 11 '24 02:03 engcom-Echo

@magento run WebAPI Tests,Unit Tests,Functional Tests EE,Functional Tests CE,Functional Tests B2B,Integration Tests

engcom-Echo avatar Mar 11 '24 05:03 engcom-Echo

@magento run Functional Tests EE,Functional Tests CE,Functional Tests B2B

engcom-Echo avatar Mar 11 '24 07:03 engcom-Echo

@magento run Unit Tests,Integration Tests

engcom-Echo avatar Mar 11 '24 09:03 engcom-Echo

WebAPI Tests failure are known failure not related to PR changes. Functional Tests EE,Functional Tests B2B failure are different on last two run on same commit. Functional Tests EE Run1 Screenshot 2024-03-11 at 3 43 46 PM

Run2 Screenshot 2024-03-11 at 3 45 02 PM

Functional Tests B2B Run1 Screenshot 2024-03-11 at 3 43 10 PM

Run2 Screenshot 2024-03-11 at 3 43 17 PM

Hence moving to merge in progress

engcom-Echo avatar Mar 11 '24 12:03 engcom-Echo