From 1af6d2248f39b7cdc90d89a51ba8832c3261914d Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 16:30:07 -0400 Subject: [PATCH 1/6] Return fewer patterns to avoid timeouts during test runs --- .../public_html/patterns/1.0/tests/test-index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index 180ff21f9b..dd5017b73d 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -81,12 +81,12 @@ public function get_term_slugs( $patterns ) { * @group e2e */ public function test_browse_all_patterns() : void { - $response = send_request( '/patterns/1.0/?per_page=100' ); + $response = send_request( '/patterns/1.0/?per_page=20' ); $this->assertResponseHasPattern( $response ); - // When all locales and keywords are included, there should be at least 100 patterns. + // When all locales and keywords are included, there should be at least 20 patterns. $patterns = json_decode( $response->body ); - $this->assertSame( 100, count( $patterns ) ); + $this->assertSame( 20, count( $patterns ) ); /* * The exact number of unique categories will vary based on which cohort of pattens happen to be returned, @@ -108,7 +108,7 @@ public function test_browse_patterns_by_category() : void { * This can't include a `pattern-keyword` param because of the workaround in * `WordPressdotorg\Pattern_Directory\Pattern_Post_Type\register_rest_fields()`. */ - $response = send_request( '/patterns/1.0/?pattern-categories=' . $button_term_id . '&locale=en_US' ); + $response = send_request( '/patterns/1.0/?per_page=20&pattern-categories=' . $button_term_id . '&locale=en_US' ); $this->assertResponseHasPattern( $response ); $patterns = json_decode( $response->body ); From ade8440b0ab3e21d35577db7802f908e65f9c564 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 16:31:16 -0400 Subject: [PATCH 2/6] Remove terms count This isn't testing much of anything, and the dynamic nature of the live content means this could just be 1 if the latest batch of patterns are all translations of a single pattern. --- .../public_html/patterns/1.0/tests/test-index.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index dd5017b73d..e019eda546 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -87,13 +87,6 @@ public function test_browse_all_patterns() : void { // When all locales and keywords are included, there should be at least 20 patterns. $patterns = json_decode( $response->body ); $this->assertSame( 20, count( $patterns ) ); - - /* - * The exact number of unique categories will vary based on which cohort of pattens happen to be returned, - * but `3` seems like a safe minimum in practice. - */ - $term_slugs = $this->get_term_slugs( $patterns ); - $this->assertGreaterThan( 3, count( $term_slugs ) ); } /** From 43c6a179fdd3adc83ee9272f3fc0432b8379ff0e Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 16:33:03 -0400 Subject: [PATCH 3/6] Update title boosted test term "image" no longer returns patterns without the term in the title, so the array is arbitrarily resorted (all sort weights are 0). Switching to "heading" returns some items without the term in the title. --- .../public_html/patterns/1.0/tests/test-index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index e019eda546..5e1bfe7764 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -290,7 +290,7 @@ public function data_search_patterns() { * @group e2e */ public function test_search_title_match_boosted_above_description_match() : void { - $search_term = 'image'; + $search_term = 'heading'; $locale = 'en_US'; $response = send_request( "/patterns/1.0/?search=$search_term&pattern-keywords=11&locale=$locale" ); @@ -307,8 +307,8 @@ public function test_search_title_match_boosted_above_description_match() : void usort( $expectedPatterns, function( $a, $b ) use ( $search_term ) { $adjustment = 0; - $found_in_title_a = false === stripos( $search_term, $a->title->rendered ); - $found_in_title_b = false === stripos( $search_term, $b->title->rendered ); + $found_in_title_a = false !== stripos( $search_term, $a->title->rendered ); + $found_in_title_b = false !== stripos( $search_term, $b->title->rendered ); if ( $found_in_title_a && ! $found_in_title_b ) { $adjustment = -1; From 786960d507bc92c6aa6f28c5134a2f425ea6b3ed Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 16:46:24 -0400 Subject: [PATCH 4/6] Update test search term The previous search term now matches a core pattern. --- api.wordpress.org/public_html/patterns/1.0/tests/test-index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index 5e1bfe7764..0f0434f327 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -253,7 +253,7 @@ public function data_search_patterns() { // The Core keyword (11) is hardcoded in `test_search_patterns()`, so don't need to specify it here. "only match Core posts" => array( - 'search_term' => 'two buttons', // Post ID 727. + 'search_term' => 'Two images with text and buttons', // Post ID 727. 'locale' => 'en_US', 'match_expected' => false, 'expected_post_ids' => false, From 2b857ed9f4049a03ba75e9347ea8f7277f06f976 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 17:15:41 -0400 Subject: [PATCH 5/6] Add link to relevant issue for this incomplete test --- .../public_html/patterns/1.0/tests/test-index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index 0f0434f327..b226014a92 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -340,7 +340,9 @@ public function test_search_locale_sort() : void { $this->assertAllPatternsMatchSearchTerm( $patterns, $search_term ); - $this->markTestIncomplete(); // todo the following code works, but `WordPressdotorg\Pattern_Directory\Search\modify_es_query_args` isn't boosting the primary locale yet + // The following test works, but `WordPressdotorg\Pattern_Directory\Search\modify_es_query_args` isn't boosting the primary locale yet. + // See https://github.com/WordPress/pattern-directory/issues/347 + $this->markTestIncomplete(); $actualOrder = array_column( array_column( $patterns, 'meta' ), 'wpop_locale' ); From c96caeaf4641721d364a575d85700580b0f4c59c Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 3 Oct 2024 17:16:30 -0400 Subject: [PATCH 6/6] Test full response for matching the pattern format --- .../public_html/patterns/1.0/tests/test-index.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php index b226014a92..d690a85018 100644 --- a/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php +++ b/api.wordpress.org/public_html/patterns/1.0/tests/test-index.php @@ -9,7 +9,7 @@ */ class Test_Patterns extends TestCase { /** - * Asserts that an HTTP response is valid and contains a pattern. + * Asserts that an HTTP response is valid and contains items matching the pattern format. * * @param Requests_Response $response */ @@ -19,10 +19,12 @@ public function assertResponseHasPattern( $response ) { $patterns = json_decode( $response->body ); $this->assertIsArray( $patterns ); $this->assertGreaterThan( 0, count( $patterns ) ); - $this->assertIsString( $patterns[0]->title->rendered ); - $this->assertIsInt( $patterns[0]->meta->wpop_viewport_width ); - $this->assertIsArray( $patterns[0]->category_slugs ); - $this->assertIsArray( $patterns[0]->keyword_slugs ); + foreach ( $patterns as $pattern ) { + $this->assertIsString( $pattern->title->rendered ); + $this->assertIsInt( $pattern->meta->wpop_viewport_width ); + $this->assertIsArray( $pattern->category_slugs ); + $this->assertIsArray( $pattern->keyword_slugs ); + } } /**