Make WordPress Core

Opened 6 months ago

Closed 2 months ago

Last modified 5 weeks ago

#60705 closed task (blessed) (fixed)

Test tool and unit test improvements for 6.6

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by:
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Previously:

This ticket is for various fixes and improvements in PHPUnit tests that don't have a more specific ticket, as well as general improvements to the GitHub Actions workflows that run automated testing.

Change History (19)

This ticket was mentioned in PR #5100 on WordPress/wordpress-develop by @johnbillion.


6 months ago
#1

  • Keywords has-patch has-unit-tests added

Trac ticket:
https://core.trac.wordpress.org/ticket/60705
https://core.trac.wordpress.org/ticket/59647
https://core.trac.wordpress.org/ticket/58955

This changes several instances of test skipping to test failures, and removes some unnecessary function_exists() checks for compat functions.

If any of the checks in these test aren't satisfied then the test should fail rather than be skipped.

In addition, I removed some multisite test skipping which is redundant as it's handled by the ms-required and ms-excluded test group handling.

Previously:

This ticket was mentioned in PR #5849 on WordPress/wordpress-develop by @hellofromTonya.


6 months ago
#2

Reorganizes the hooks tests to align to coding standards and consistency within the test suite.

  • [X] Moves WP_Hooks method tests to into separate directory <GroupName>/<className>/<methodName>.php.
  • [X] Splits the function tests in actions.php and filters.php into separate test classes within the tests/hooks/ directory.
  • [ ] Add assertion failure message to each instance where there are more than 1 assertion in the test method.

Trac ticket:
https://core.trac.wordpress.org/ticket/60705
https://core.trac.wordpress.org/ticket/59647

#3 @SergeyBiryukov
6 months ago

In 57861:

Tests: Remove unnecessary use of utf8_encode() in KSES tests.

One of the tests for the wp_kses_xml_named_entities() function used utf8_encode( chr( 160 ) ) to set an expectation of a Unicode character for a non-breaking space.

It is understandable that this expectation was previously set this way, as it is not possible for a developer to distinguish between a breaking space and a non-breaking space visually, so the chances of the test accidentally breaking on an incorrect save when the plain Unicode character would be used, was high.

However, the utf8_encode() function is deprecated as of PHP 8.2, and its use needs to be removed from the WP codebase.

PHP 7.0 has introduced Unicode escape sequences, which allows to create a text string using Unicode characters referenced by their codepoint. By switching the test case to provide the test expectation using a Unicode escape sequence, we remove the use of the deprecated PHP function and still preserve the safeguard against the test accidentally breaking.

Follow-up to [52229].

Props jrf, afercia, poena, SergeyBiryukov.
See #55603, #60705.

#4 @SergeyBiryukov
5 months ago

In 57892:

Tests: Use an existing user fixture in the test for logging in with an email address.

Creating a new user is redundant here, the fixture shared by other tests can be used instead.

Follow-up to [36617].

See #60705.

#5 @SergeyBiryukov
4 months ago

In 58136:

Tests: Move add_settings_section() tests to a more appropriate place.

Follow-up to [54247].

See #60705.

#6 @SergeyBiryukov
4 months ago

In 58176:

Tests: Correct a number of invalid @covers tags.

This resolves a few warnings when running PHPUnit with the code coverage report:

"@covers WP_Privacy_Requests_List_Table::get_views" is invalid
"@covers WP_Block_Bindings_Registry::register_block_bindings_source" is invalid
"@covers WP_Block_Patterns_Registry::_register_theme_block_patterns" is invalid

The two removed @coversDefaultClass annotations are redundant, as the class name is already included in the individual @covers tags. Removing them allows @covers ::_register_theme_block_patterns to work as expected, where _register_theme_block_patterns is an standalone function, not a class method.

Follow-up to [54215], [56733], [57373], [57562].

See #60705.

#7 @SergeyBiryukov
4 months ago

In 58181:

Tests: Use assertSame() in block support tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Includes renaming a few test classes per the naming conventions.

Reference: Writing PHP Tests: Naming and Organization.

Follow-up to [53076], [53085], [54497], [56046], [56614], [57246], [57491].

See #60705.

#8 @SergeyBiryukov
4 months ago

In 58183:

Tests: Use assertSame() in navigation fallback tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [56052].

See #60705.

This ticket was mentioned in PR #6641 on WordPress/wordpress-develop by @peterwilsoncc.


3 months ago
#9

Avoid the assertTrue|False( file_exists() ) pattern and use file assertions directly.

Trac ticket: https://core.trac.wordpress.org/ticket/60705

#10 @peterwilsoncc
3 months ago

In 58221:

Build/Test Tools: Assert files exist/do not exist directly.

Replaces various boolean assertions wrapping file_exists() with either assertFileExists() or assertFileDoesNotExist() as appropriate for the test.

Props peterwilsoncc, mukesh27.
See #60705.

#12 @SergeyBiryukov
3 months ago

In 58235:

Tests: Use more specific assertions in a few tests.

Follow-up to [121/tests], [915/tests], [34903], [36307], [43548], [44154], [52286], [57337].

See #60705.

This ticket was mentioned in PR #6680 on WordPress/wordpress-develop by @desrosj.


3 months ago
#13

MySQL 8.4 was released on April 30, 2024 and is the latest LTS version of MySQL.

Trac ticket: https://core.trac.wordpress.org/ticket/60705

#14 @desrosj
3 months ago

In 58251:

Build/Test Tools: Add supported MySQL versions for 6.6 to the support file.

See #60705.

#15 @SergeyBiryukov
3 months ago

In 58420:

Tests: Use more specific assertions in WP_Script_Modules tests.

Follow-up to [57269], [57327], [57593].

See #60705.

#16 @SergeyBiryukov
3 months ago

In 58458:

Tests: Use named data provider in iso8601_to_datetime() tests.

Follow-up to [54230], [58164].

See #60705.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


2 months ago

#18 @jorbin
2 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Closing in favor of #61530 since we are now in RC for 6.6.

@desrosj commented on PR #6680:


5 weeks ago
#19

@aristath I saw that you self assigned to perform a review. I think this is getting really close, so wanted to make sure you had a chance to take a look.

Note: See TracTickets for help on using tickets.