From 6bc91c314dfd1dc692b86396eb8f0285b142a7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Wed, 19 Jun 2024 11:20:27 -0400 Subject: [PATCH 01/14] Fixes#4830 Rankmath class not found (#6695) --- inc/ThirdParty/Plugins/SEO/RankMathSEO.php | 38 +++++++----------- inc/ThirdParty/ServiceProvider.php | 1 - .../{rocketSitemap.php => addSitemap.php} | 8 ++-- .../Plugins/SEO/RankMathSEO/addSitemap.php | 39 +++++++++++++++++++ .../Plugins/SEO/RankMathSEO/rocketSitemap.php | 39 ------------------- .../Plugins/SEO/RankMathSEO/addSitemap.php | 37 ++++++++++++++++++ .../Plugins/SEO/RankMathSEO/rocketSitemap.php | 36 ----------------- 7 files changed, 94 insertions(+), 104 deletions(-) rename tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/{rocketSitemap.php => addSitemap.php} (62%) create mode 100644 tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php delete mode 100644 tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php create mode 100644 tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php delete mode 100644 tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php diff --git a/inc/ThirdParty/Plugins/SEO/RankMathSEO.php b/inc/ThirdParty/Plugins/SEO/RankMathSEO.php index f9e9e40bc0..639fea8445 100644 --- a/inc/ThirdParty/Plugins/SEO/RankMathSEO.php +++ b/inc/ThirdParty/Plugins/SEO/RankMathSEO.php @@ -1,42 +1,29 @@ option = $option; - } + public static function get_subscribed_events(): array { + if ( ! class_exists( 'RankMath\Helper' ) ) { + return []; + } - /** - * Subscribed events. - */ - public static function get_subscribed_events() { - // @phpstan-ignore-next-line if ( ! defined( 'RANK_MATH_FILE' ) || ! Helper::is_module_active( 'sitemap' ) ) { return []; } return [ - 'rocket_sitemap_preload_list' => [ 'rocket_sitemap', 15 ], + 'rocket_sitemap_preload_list' => [ 'add_sitemap', 15 ], ]; } @@ -44,11 +31,14 @@ public static function get_subscribed_events() { * Add SEO sitemap URL to the sitemaps to preload * * @param array $sitemaps Sitemaps to preload. - * @return array Updated Sitemaps to preload + * + * @return array */ - public function rocket_sitemap( $sitemaps ) { + public function add_sitemap( $sitemaps ) { + if ( ! class_exists( 'RankMath\Sitemap\Router' ) ) { + return $sitemaps; + } - // @phpstan-ignore-next-line $sitemaps[] = Router::get_base_url( 'sitemap_index.xml' ); return $sitemaps; diff --git a/inc/ThirdParty/ServiceProvider.php b/inc/ThirdParty/ServiceProvider.php index 80e710b4a1..50fbc95569 100644 --- a/inc/ThirdParty/ServiceProvider.php +++ b/inc/ThirdParty/ServiceProvider.php @@ -238,7 +238,6 @@ public function register(): void { ->addTag( 'common_subscriber' ); $this->getContainer() ->addShared( 'rank_math_seo', RankMathSEO::class ) - ->addArgument( $options ) ->addTag( 'common_subscriber' ); $this->getContainer() ->addShared( 'all_in_one_seo_pack', AllInOneSEOPack::class ) diff --git a/tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php b/tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php similarity index 62% rename from tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php rename to tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php index 7d0cada3a8..2587a1e28c 100644 --- a/tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php +++ b/tests/Fixtures/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php @@ -2,11 +2,11 @@ return [ 'shouldAddSitemap' => [ 'config' => [ - 'sitemap' => 'sitemap', - 'sitemaps' => [] + 'sitemap' => 'sitemap', + 'sitemaps' => [], ], 'expected' => [ 'sitemap', - ] - ] + ], + ], ]; diff --git a/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php b/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php new file mode 100644 index 0000000000..6dc6ca2df4 --- /dev/null +++ b/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php @@ -0,0 +1,39 @@ +unregisterAllCallbacksExcept( 'rocket_sitemap_preload_list', 'add_sitemap', 15 ); + } + + public function tear_down() { + $this->restoreWpHook( 'rocket_sitemap_preload_list' ); + + parent::tear_down(); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnExpected( $config, $expected ) { + Router::$sitemap = $config['sitemap']; + + $this->assertSame( + $expected, + apply_filters( 'rocket_sitemap_preload_list', $config['sitemaps'] ) + ); + } +} diff --git a/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php b/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php deleted file mode 100644 index 68b116abad..0000000000 --- a/tests/Integration/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php +++ /dev/null @@ -1,39 +0,0 @@ -unregisterAllCallbacksExcept('rocket_sitemap_preload_list', 'rocket_sitemap', 15); - } - - public function tearDown(): void - { - $this->restoreWpHook('rocket_sitemap_preload_list'); - parent::tearDown(); - } - - /** - * @dataProvider configTestData - */ - public function testShouldReturnAsExpected($config, $expected) { - Router::$sitemap = $config['sitemap']; - $this->assertSame($expected, apply_filters('rocket_sitemap_preload_list', $config['sitemaps'])); - } - -} diff --git a/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php b/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php new file mode 100644 index 0000000000..d05229d41a --- /dev/null +++ b/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/addSitemap.php @@ -0,0 +1,37 @@ +subscriber = new RankMathSEO(); + } + + /** + * @dataProvider configTestData + */ + public function testShouldReturnAsExpected( $config, $expected ) { + Router::$sitemap = $config['sitemap']; + + $this->assertSame( + $expected, + $this->subscriber->add_sitemap( $config['sitemaps'] ) + ); + } +} diff --git a/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php b/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php deleted file mode 100644 index a34d8fab8a..0000000000 --- a/tests/Unit/inc/ThirdParty/Plugins/SEO/RankMathSEO/rocketSitemap.php +++ /dev/null @@ -1,36 +0,0 @@ -option = Mockery::mock(Options_Data::class); - $this->subscriber = new RankMathSEO($this->option); - } - - /** - * @dataProvider configTestData - */ - public function testShouldReturnAsExpected($config, $expected) { - Router::$sitemap = $config['sitemap']; - $this->assertSame($expected, $this->subscriber->rocket_sitemap($config['sitemaps'])); - } -} From 1b3b8a523dcae5d0928a64862df70b33cc3b3fa7 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Wed, 19 Jun 2024 16:54:09 +0100 Subject: [PATCH 02/14] closes #6672 add attribute to link preload (#6674) --- .../AboveTheFold/Frontend/Controller.php | 2 +- .../GoogleFonts/AbstractGFOptimization.php | 2 +- .../Optimization/RUCSS/Controller/UsedCSS.php | 2 +- ...tput_lcp_bg_responsive_imgset_template.php | 2 +- ...tput_lcp_bg_responsive_webkit_template.php | 2 +- .../Subscriber/HTML/output_lcp_image.php | 2 +- .../Subscriber/HTML/output_lcp_layered_bg.php | 2 +- .../Subscriber/HTML/output_lcp_picture.php | 2 +- .../Subscriber/HTML/output_lcp_picture_2.php | 2 +- .../Subscriber/HTML/output_lcp_picture_3.php | 2 +- .../Subscriber/HTML/output_lcp_picture_4.php | 2 +- .../Subscriber/HTML/output_lcp_responsive.php | 2 +- .../Subscriber/HTML/output_lcp_single_bg.php | 2 +- .../HTML/output_lcp_with_fetchpriority.html | 2 +- .../HTML/output_lcp_with_markup_comment.html | 2 +- .../HTML/output_w_bg_image_lcp.html | 2 +- .../Subscriber/HTML/output_w_img_lcp.html | 2 +- .../HTML/output_w_picture_img_lcp.html | 2 +- .../Subscriber/HTML/output_w_preload.html | 2 +- .../HTML/output_with_absolute_img_lcp.php | 2 +- .../HTML/output_with_relative_img_lcp.php | 2 +- .../GoogleFonts/Combine/optimize.php | 26 +++++++++---------- .../GoogleFonts/CombineV1V2/optimize.php | 20 +++++++------- .../GoogleFonts/CombineV2/optimize.php | 12 ++++----- .../Subscriber/HTML/outputFontExcluded.html | 2 +- .../Subscriber/HTML/outputFontPreloaded.html | 2 +- 26 files changed, 52 insertions(+), 52 deletions(-) diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index 1259d2faa7..f5bb1dece3 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -266,7 +266,7 @@ private function generate_lcp_link_tag_with_sources( $lcp ): array { } $tag = ''; - $start_tag = '', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet + '', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet $url ); } diff --git a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php index 03624c046c..9a8ba4a31a 100644 --- a/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php +++ b/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php @@ -615,7 +615,7 @@ private function preload_links( array $urls ): string { $links = ''; foreach ( $urls as $url ) { - $links .= ''; + $links .= ''; } return $links; diff --git a/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_lcp_bg_responsive_imgset_template.php b/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_lcp_bg_responsive_imgset_template.php index 68f7551be0..778485258c 100644 --- a/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_lcp_bg_responsive_imgset_template.php +++ b/tests/Fixtures/inc/Engine/Media/AboveTheFold/Frontend/Subscriber/HTML/output_lcp_bg_responsive_imgset_template.php @@ -8,7 +8,7 @@ - lcp_bg_responsive_template + lcp_bg_responsive_template