From 996119820992138fc29fda2e76abdbe81626a3f9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 30 Apr 2024 09:14:51 -0700 Subject: [PATCH 1/2] Use posts member of WP_Query instead of get_posts method --- bin/add-test-widgets-to-sidebar.php | 2 +- bin/create-embed-test-post.php | 2 +- includes/validation/class-amp-validated-url-post-type.php | 4 ++-- src/Support/SupportData.php | 2 +- src/Validation/ScannableURLProvider.php | 4 ++-- tests/php/src/Validation/ScannableURLProviderTest.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/add-test-widgets-to-sidebar.php b/bin/add-test-widgets-to-sidebar.php index 68580abc2ca..915852b712a 100644 --- a/bin/add-test-widgets-to-sidebar.php +++ b/bin/add-test-widgets-to-sidebar.php @@ -294,7 +294,7 @@ function amp_media( $type, $count = 3 ) { ) ); } - return $query->get_posts(); + return $query->posts; } /** diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 8ac04574de2..d4388b93960 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -242,7 +242,7 @@ function amp_get_media_items_ids( $type, $image_count = 3 ) { ) ); } - return implode( ',', $query->get_posts() ); + return implode( ',', $query->posts ); } /** diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index d644bf29c93..3b16fb84565 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -994,7 +994,7 @@ public static function delete_stylesheets_postmeta_batch( $count, $before ) { 'posts_per_page' => $count, ] ); - foreach ( $query->get_posts() as $post_id ) { + foreach ( $query->posts as $post_id ) { if ( delete_post_meta( $post_id, self::STYLESHEETS_POST_META_KEY ) ) { $deleted++; } @@ -1037,7 +1037,7 @@ public static function garbage_collect_validated_urls( $count = 100, $before = ' ], ] ); - foreach ( $query->get_posts() as $post ) { + foreach ( $query->posts as $post ) { if ( ! self::is_post_safe_to_garbage_collect( $post ) ) { continue; } diff --git a/src/Support/SupportData.php b/src/Support/SupportData.php index fa06b0263c3..dd288df26b0 100644 --- a/src/Support/SupportData.php +++ b/src/Support/SupportData.php @@ -679,7 +679,7 @@ public function get_amp_urls() { ]; $query = new WP_Query( $query_args ); - $amp_validated_posts = $query->get_posts(); + $amp_validated_posts = $query->posts; foreach ( $amp_validated_posts as $amp_validated_post ) { $validation_data = $this->process_raw_post_errors( $amp_validated_post ); diff --git a/src/Validation/ScannableURLProvider.php b/src/Validation/ScannableURLProvider.php index d3937b646b0..24f2a1efff4 100644 --- a/src/Validation/ScannableURLProvider.php +++ b/src/Validation/ScannableURLProvider.php @@ -336,7 +336,7 @@ private function get_author_page_urls( $offset, $number ) { 'posts_per_page' => 1, ] ); - if ( count( $authored_post_query->get_posts() ) > 0 ) { + if ( count( $authored_post_query->posts ) > 0 ) { $author_page_urls[] = get_author_posts_url( $author->ID, $author->user_nicename ); } } @@ -376,7 +376,7 @@ private function get_date_page() { 'order' => 'DESC', ] ); - $posts = $query->get_posts(); + $posts = $query->posts; $latest_post = array_shift( $posts ); if ( ! $latest_post ) { diff --git a/tests/php/src/Validation/ScannableURLProviderTest.php b/tests/php/src/Validation/ScannableURLProviderTest.php index c5eadafc04a..c8713745b12 100644 --- a/tests/php/src/Validation/ScannableURLProviderTest.php +++ b/tests/php/src/Validation/ScannableURLProviderTest.php @@ -517,7 +517,7 @@ public function test_get_date_page() { 'fields' => 'ids', ] ); - foreach ( $query->get_posts() as $deleted_post ) { + foreach ( $query->posts as $deleted_post ) { wp_delete_post( $deleted_post ); } $this->assertNull( $this->call_private_method( $this->scannable_url_provider, 'get_date_page' ) ); From 3e75a3318ed05f7562155127cc7d50ecba52ec58 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 7 Jul 2024 14:48:38 +0530 Subject: [PATCH 2/2] Update test cases for latest WP and Gutenberg changes --- tests/php/test-amp-style-sanitizer.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/php/test-amp-style-sanitizer.php b/tests/php/test-amp-style-sanitizer.php index 68bd4963414..b2ee1a986e3 100644 --- a/tests/php/test-amp-style-sanitizer.php +++ b/tests/php/test-amp-style-sanitizer.php @@ -3518,8 +3518,18 @@ function ( $original_dom, $original_source, $amphtml_dom, $amphtml_source ) { $this->assertStringContainsString( 'admin-bar', $original_dom->body->getAttribute( 'class' ) ); $this->assertStringContainsString( 'earlyprintstyle', $original_source, 'Expected early print style to not be present.' ); - $this->assertStringContainsString( '.wp-block-audio figcaption', $amphtml_source, 'Expected block-library/style.css' ); - $this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) figcaption', $amphtml_source, 'Expected twentyten/blocks.css' ); + if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '18.7', '>=' ) ) { + $this->assertStringContainsString( '.wp-block-audio :where(figcaption)', $amphtml_source, 'Expected block-library/style.css' ); + } else { + $this->assertStringContainsString( '.wp-block-audio figcaption', $amphtml_source, 'Expected block-library/style.css' ); + } + + if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '6.6', '>=' ) ) { + $this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) > figcaption', $amphtml_source, 'Expected twentyten/blocks.css' ); + } else { + $this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) figcaption', $amphtml_source, 'Expected twentyten/blocks.css' ); + } + $amphtml_source = preg_replace( '/\s*>\s*/', '>', $amphtml_source ); // Account for variance in postcss. $this->assertStringContainsString( '.amp-wp-default-form-message>p', $amphtml_source, 'Expected amp-default.css' ); $this->assertStringContainsString( 'ab-empty-item', $amphtml_source, 'Expected admin-bar.css to still be present.' );