From 982832ec79563155e1967c44172383f833bf8d6b Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 5 Nov 2024 19:59:49 +0000 Subject: [PATCH 1/7] Build/Test Tools: Add script for generating code coverage report. This adds documentation for how to generate code coverage reports to the README.md file. `test:coverage` has also been added as an npm script to make it easier to generate a report using the local Docker environment. The script will generate an HTML, PHP, and text report file. Props pbearne, hellofromTonya, netweb. Fixes #53414. git-svn-id: https://develop.svn.wordpress.org/trunk@59356 602fd350-edb4-49c9-b593-d223f7449a82 --- .gitignore | 1 + README.md | 13 +++++++++++++ package.json | 1 + tools/local-env/scripts/docker.js | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index 81f87c18056a3..229b3a269394b 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ wp-tests-config.php /packagehash.txt /artifacts /setup.log +/coverage # Files and folders that get created in wp-content /src/wp-content/blogs.dir diff --git a/README.md b/README.md index f1a12dda6952a..7b07b883d7544 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,19 @@ npm run test:php -- --filter npm run test:php -- --group ``` +#### Generating a code coverage report +PHP code coverage reports are [generated daily](https://github.com/WordPress/wordpress-develop/actions/workflows/test-coverage.yml) and [submitted to Codecov.io](https://app.codecov.io/gh/WordPress/wordpress-develop). + +After the local Docker environment has [been installed and started](#to-start-the-development-environment-for-the-first-time), the following command can be used to generate a code coverage report. + +``` +npm run test:coverage +``` + +The command will generate three coverage reports in HTML, PHP, and text formats, saving them in the `coverage` folder. + +**Note:** xDebug is required to generate a code coverage report, which can slow down PHPUnit significantly. Passing selection-based options such as `--group` or `--filter` can decrease the overall time required but will result in an incomplete report. + #### To restart the development environment You may want to restart the environment if you've made changes to the configuration in the `docker-compose.yml` or `.env` files. Restart the environment with: diff --git a/package.json b/package.json index 8367b527cb78b..f2035fb63036e 100644 --- a/package.json +++ b/package.json @@ -190,6 +190,7 @@ "env:pull": "node ./tools/local-env/scripts/docker.js pull", "test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.js", "test:php": "node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit", + "test:coverage": "npm run test:php -- --coverage-html ./coverage/html/ --coverage-php ./coverage/php/report.php --coverage-text=./coverage/text/report.txt", "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js", "sync-gutenberg-packages": "grunt sync-gutenberg-packages", diff --git a/tools/local-env/scripts/docker.js b/tools/local-env/scripts/docker.js index 078ce89f916a6..daa6b8826237a 100644 --- a/tools/local-env/scripts/docker.js +++ b/tools/local-env/scripts/docker.js @@ -7,5 +7,10 @@ dotenvExpand.expand( dotenv.config() ); const composeFiles = local_env_utils.get_compose_files(); +if (process.argv.includes('--coverage-html')) { + process.env.LOCAL_PHP_XDEBUG = 'true'; + process.env.LOCAL_PHP_XDEBUG_MODE = 'coverage'; +} + // Execute any docker compose command passed to this script. execSync( 'docker compose ' + composeFiles + ' ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } ); From da9a28d8d1e53c32127728354d93033de8609ed6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 5 Nov 2024 23:07:44 +0000 Subject: [PATCH 2/7] Coding Standards: Use `WP_User_Query::get_results()` instead of a private property. This resolves an issue where the private property `WP_User_Query::$results` is accessed directly in `WP_REST_Users_Controller::get_items()` instead of via the `::get_results()` method. Follow-up to [38832]. Props justlevine. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@59357 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-users-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index c8d9b11a11d20..84bcea052cf32 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -349,7 +349,7 @@ public function get_items( $request ) { $users = array(); - foreach ( $query->results as $user ) { + foreach ( $query->get_results() as $user ) { $data = $this->prepare_item_for_response( $user, $request ); $users[] = $this->prepare_response_for_collection( $data ); } From eab73a7351341df140a4882934ba96143651ba8d Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 6 Nov 2024 00:37:33 +0000 Subject: [PATCH 3/7] Media: Fix variable name in `wp_check_filetype_and_ext()`. Props peterwilsoncc. See #62272. git-svn-id: https://develop.svn.wordpress.org/trunk@59358 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index aea82e76c96e2..ef2ce9d9c3bcf 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3101,13 +3101,13 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { // Attempt to figure out what type of image it actually is. $real_mime = wp_get_image_mime( $file ); - $heic_images_etx = array( + $heic_images_extensions = array( 'heif', 'heics', 'heifs', ); - if ( $real_mime && ( $real_mime !== $type || in_array( $ext, $heic_images_etx, true ) ) ) { + if ( $real_mime && ( $real_mime !== $type || in_array( $ext, $heic_images_extensions, true ) ) ) { /** * Filters the list mapping image mime types to their respective extensions. * From 5ff971744e4b2d246c66f58d436cac5eff2a0662 Mon Sep 17 00:00:00 2001 From: ramonopoly Date: Wed, 6 Nov 2024 00:42:12 +0000 Subject: [PATCH 4/7] Performance: reuse block metadata in `WP_Theme_JSON::get_valid_block_style_variations()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In `WP_Theme_JSON::get_valid_block_style_variations()`, the method was calling `self::get_blocks_metadata()` even though the metadata was already retrieved in the parent function. This update reuses the existing block metadata instead of calling it again. A new optional parameter, `$blocks_metadata`, has been added to the function, allowing it to use pre-fetched metadata when available, improving efficiency. Fewer `self::get_blocks_metadata()` calls mean faster processing, especially in themes with many blocks. Props mukesh27, ramonopoly, aaronrobertshaw, flixos90. Fixes #62291. git-svn-id: https://develop.svn.wordpress.org/trunk@59359 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme-json.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index cfca9a2242b93..f40fde9cf82b3 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -757,9 +757,10 @@ public function __construct( $theme_json = array( 'version' => self::LATEST_SCHE } $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin ); - $valid_block_names = array_keys( static::get_blocks_metadata() ); + $blocks_metadata = static::get_blocks_metadata(); + $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); - $valid_variations = static::get_valid_block_style_variations(); + $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); $this->theme_json = static::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations ); $this->theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); $this->theme_json = static::maybe_opt_in_into_settings( $this->theme_json ); @@ -3482,9 +3483,10 @@ public static function remove_insecure_properties( $theme_json, $origin = 'theme $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json, $origin ); - $valid_block_names = array_keys( static::get_blocks_metadata() ); + $blocks_metadata = static::get_blocks_metadata(); + $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); - $valid_variations = static::get_valid_block_style_variations(); + $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names, $valid_variations ); @@ -4531,12 +4533,15 @@ function ( $matches ) use ( $variation_class ) { * Collects valid block style variations keyed by block type. * * @since 6.6.0 + * @since 6.8.0 Added the `$blocks_metadata` parameter. * + * @param array $blocks_metadata Optional. List of metadata per block. Default is the metadata for all blocks. * @return array Valid block style variations by block type. */ - protected static function get_valid_block_style_variations() { + protected static function get_valid_block_style_variations( $blocks_metadata = array() ) { $valid_variations = array(); - foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) { + $blocks_metadata = empty( $blocks_metadata ) ? static::get_blocks_metadata() : $blocks_metadata; + foreach ( $blocks_metadata as $block_name => $block_meta ) { if ( ! isset( $block_meta['styleVariations'] ) ) { continue; } From becc1733f62f0a75fcedcd605a68c32ab81daa43 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 6 Nov 2024 12:03:05 +0000 Subject: [PATCH 5/7] Editor: Correct the number of arguments for `WP_HTML_Tag_Processor::get_tag()`. This resolves an issue with `::get_tag()` being called in `WP_Block::replace_html()` with an extra argument, as the method accepts no arguments. Follow-up to [57514]. Props justlevine, mukesh27. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@59361 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 8cfa996028da2..a1c52019c29a5 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -374,7 +374,7 @@ private function replace_html( string $block_content, string $attribute_name, $s foreach ( $selectors as $selector ) { // If the parent tag, or any of its children, matches the selector, replace the HTML. - if ( strcasecmp( $block_reader->get_tag( $selector ), $selector ) === 0 || $block_reader->next_tag( + if ( strcasecmp( $block_reader->get_tag(), $selector ) === 0 || $block_reader->next_tag( array( 'tag_name' => $selector, ) From 7b94f096a57e505aee4b4af03b6c24dd2b7210af Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 6 Nov 2024 16:18:38 +0000 Subject: [PATCH 6/7] Bundled Themes: Sync some minor fixes for Twenty Twenty-Five. This merges several minor improvements to patterns in Twenty Twenty-Five. A full list of changes can be found on GitHub: https://github.com/WordPress/twentytwentyfive/compare/e7612e3cb31b7db9c43f5032a2cdcd79ed4a5cbf...b8c032e43c1101a5d57e07dd60768a326d44ac5c. Props juanfra. Fixes #62351. git-svn-id: https://develop.svn.wordpress.org/trunk@59362 602fd350-edb4-49c9-b593-d223f7449a82 --- .../patterns/banner-about-book.php | 4 +- .../patterns/banner-cover-big-heading.php | 4 +- .../patterns/banner-intro-image.php | 4 +- .../patterns/banner-intro.php | 4 +- .../patterns/banner-poster.php | 4 +- ...anner-with-description-and-images-grid.php | 4 +- .../patterns/contact-centered-social-link.php | 4 +- .../patterns/contact-info-locations.php | 4 +- .../patterns/contact-location-and-link.php | 4 +- .../patterns/cta-book-links.php | 4 +- .../patterns/cta-book-locations.php | 4 +- .../patterns/cta-centered-heading.php | 4 +- .../patterns/cta-events-list.php | 4 +- .../patterns/cta-grid-products-link.php | 4 +- .../patterns/cta-newsletter.php | 4 +- .../twentytwentyfive/patterns/event-3-col.php | 4 +- .../patterns/event-schedule.php | 16 ++++---- .../twentytwentyfive/patterns/grid-videos.php | 4 +- .../patterns/grid-with-categories.php | 33 +++++++++------ .../heading-and-paragraph-with-image.php | 4 +- .../twentytwentyfive/patterns/hero-book.php | 4 +- .../patterns/hero-full-width-image.php | 4 +- .../hero-overlapped-book-cover-with-links.php | 4 +- .../patterns/hero-podcast.php | 4 +- .../twentytwentyfive/patterns/logos.php | 4 +- .../patterns/media-instagram-grid.php | 4 +- .../patterns/overlapped-images.php | 4 +- .../patterns/page-business-home.php | 41 +++---------------- .../twentytwentyfive/patterns/page-cv-bio.php | 4 +- .../patterns/page-landing-book.php | 40 +++--------------- .../patterns/page-landing-event.php | 33 +++------------ .../patterns/page-landing-podcast.php | 33 +++------------ ...k-in-bio-heading-paragraph-links-image.php | 4 +- .../page-link-in-bio-wide-margins.php | 4 +- .../page-link-in-bio-with-tight-margins.php | 4 +- .../patterns/page-portfolio-home.php | 2 +- .../patterns/page-shop-home.php | 19 ++------- .../patterns/pricing-2-col.php | 4 +- .../patterns/pricing-3-col.php | 4 +- .../patterns/services-3-col.php | 4 +- .../services-subscriber-only-section.php | 4 +- .../patterns/services-team-photos.php | 4 +- .../patterns/template-home-news-blog.php | 14 +++---- .../patterns/testimonials-2-col.php | 4 +- .../patterns/testimonials-6-col.php | 4 +- .../patterns/testimonials-large.php | 4 +- .../twentytwentyfive/patterns/text-faqs.php | 4 +- 47 files changed, 137 insertions(+), 246 deletions(-) diff --git a/src/wp-content/themes/twentytwentyfive/patterns/banner-about-book.php b/src/wp-content/themes/twentytwentyfive/patterns/banner-about-book.php index 07eef9a8e319a..dc06f303cac81 100644 --- a/src/wp-content/themes/twentytwentyfive/patterns/banner-about-book.php +++ b/src/wp-content/themes/twentytwentyfive/patterns/banner-about-book.php @@ -12,8 +12,8 @@ ?> - -
+ +
diff --git a/src/wp-content/themes/twentytwentyfive/patterns/banner-cover-big-heading.php b/src/wp-content/themes/twentytwentyfive/patterns/banner-cover-big-heading.php index 8e3e72f2e6863..1b00c3a6f985a 100644 --- a/src/wp-content/themes/twentytwentyfive/patterns/banner-cover-big-heading.php +++ b/src/wp-content/themes/twentytwentyfive/patterns/banner-cover-big-heading.php @@ -11,8 +11,8 @@ */ ?> - -
+ +
diff --git a/src/wp-content/themes/twentytwentyfive/patterns/banner-intro-image.php b/src/wp-content/themes/twentytwentyfive/patterns/banner-intro-image.php index b0ee5ce66460d..428deb07af458 100644 --- a/src/wp-content/themes/twentytwentyfive/patterns/banner-intro-image.php +++ b/src/wp-content/themes/twentytwentyfive/patterns/banner-intro-image.php @@ -11,8 +11,8 @@ */ ?> - -
+ +
diff --git a/src/wp-content/themes/twentytwentyfive/patterns/banner-intro.php b/src/wp-content/themes/twentytwentyfive/patterns/banner-intro.php index 2250538e025ac..48a816a4dffe2 100644 --- a/src/wp-content/themes/twentytwentyfive/patterns/banner-intro.php +++ b/src/wp-content/themes/twentytwentyfive/patterns/banner-intro.php @@ -11,8 +11,8 @@ */ ?> - -
+ +

- -