From c0489c0d2557f7e560daa74dd77a66b4a21a0fc3 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 27 Oct 2026 17:43:13 +0530 Subject: [PATCH] fix: preserve queries in onboarding archives --- library/archive/archive-boxed.php | 2 +- library/archive/archive-cards.php | 2 +- library/archive/archive-rows.php | 2 +- tests/test-onboarding-templates.php | 55 +++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/test-onboarding-templates.php diff --git a/library/archive/archive-boxed.php b/library/archive/archive-boxed.php index 85b0ae22..0fdab50c 100644 --- a/library/archive/archive-boxed.php +++ b/library/archive/archive-boxed.php @@ -16,7 +16,7 @@ -
+
diff --git a/library/archive/archive-cards.php b/library/archive/archive-cards.php index e8b95943..23574dcf 100644 --- a/library/archive/archive-cards.php +++ b/library/archive/archive-cards.php @@ -18,7 +18,7 @@ -
+
diff --git a/library/archive/archive-rows.php b/library/archive/archive-rows.php index d04a5faf..7dc664e4 100644 --- a/library/archive/archive-rows.php +++ b/library/archive/archive-rows.php @@ -16,7 +16,7 @@ -
+
diff --git a/tests/test-onboarding-templates.php b/tests/test-onboarding-templates.php new file mode 100644 index 00000000..5df8163e --- /dev/null +++ b/tests/test-onboarding-templates.php @@ -0,0 +1,55 @@ +, innerBlocks: list>, innerHTML: string, innerContent: list} + */ + +class Test_Onboarding_Templates extends WP_UnitTestCase { + /** + * Onboarding archive templates must list the posts of the archive being viewed. + * + * @return void + */ + public function test_archive_templates_inherit_the_archive_query(): void { + $support = get_theme_support( 'otter-onboarding' ); + + /** @var array $archive_templates */ + $archive_templates = $support[0]['templates']['archive']; + + $this->assertNotEmpty( $archive_templates ); + + foreach ( $archive_templates as $slug => $template ) { + $queries = $this->find_query_blocks( parse_blocks( include $template['file'] ) ); + + $this->assertNotEmpty( $queries, $slug ); + + foreach ( $queries as $query ) { + $this->assertTrue( $query['attrs']['query']['inherit'], $slug ); + } + } + } + + /** + * Collect every Query block, including nested ones. + * + * @param list $blocks Parsed blocks. + * + * @return list + */ + private function find_query_blocks( array $blocks ): array { + $queries = array(); + + foreach ( $blocks as $block ) { + if ( 'core/query' === $block['blockName'] ) { + $queries[] = $block; + } + + $queries = array_merge( $queries, $this->find_query_blocks( $block['innerBlocks'] ) ); + } + + return $queries; + } +}