Commit 552cb8e751c for woocommerce
commit 552cb8e751c2f2510ab1b14e81622d705477a4c1
Author: Ján Mikláš <neosinner@gmail.com>
Date: Wed Nov 25 09:11:38 2026 +0100
Test Analytics scanning of Cart and Checkout blocks (#71404)
* Test Analytics scanning of Cart and Checkout blocks
* Validate the Analytics changelog and cover classic shortcode blocks
diff --git a/packages/php/woocommerce-analytics/changelog/wooplug-8168-dependency-cleanup b/packages/php/woocommerce-analytics/changelog/wooplug-8168-dependency-cleanup
new file mode 100644
index 00000000000..dbcef8fb128
--- /dev/null
+++ b/packages/php/woocommerce-analytics/changelog/wooplug-8168-dependency-cleanup
@@ -0,0 +1,3 @@
+Significance: patch
+Type: changed
+Comment: Cover Cart and Checkout block scanning in Analytics tests. No production change.
diff --git a/packages/php/woocommerce-analytics/tests/php/Universal_Test.php b/packages/php/woocommerce-analytics/tests/php/Universal_Test.php
index b71979f887b..98adcefb008 100644
--- a/packages/php/woocommerce-analytics/tests/php/Universal_Test.php
+++ b/packages/php/woocommerce-analytics/tests/php/Universal_Test.php
@@ -25,6 +25,47 @@ class Universal_Test extends BaseTestCase {
$wc_get_order_mock_return = false;
}
+ /**
+ * @testdox Collects additional blocks outside the main WooCommerce block.
+ *
+ * @param string $page Page to scan.
+ * @param bool $has_extra_blocks Whether the page has additional blocks.
+ * @param string[] $expected Expected block names in document order.
+ *
+ * @testWith ["cart", false, []]
+ * ["checkout", false, []]
+ * ["cart", true, ["core/group", "core/paragraph", "core/spacer"]]
+ * ["checkout", true, ["core/group", "core/paragraph", "core/spacer"]]
+ */
+ public function test_get_additional_blocks_on_page( string $page, bool $has_extra_blocks, array $expected ): void {
+ $content = sprintf(
+ '<!-- wp:woocommerce/%1$s --><!-- wp:core/buttons /--><!-- /wp:woocommerce/%1$s --><!-- wp:core/shortcode /--><!-- wp:woocommerce/classic-shortcode /-->',
+ $page
+ );
+
+ if ( $has_extra_blocks ) {
+ $content .= '<!-- wp:group --><div><!-- wp:paragraph --><p>Hello</p><!-- /wp:paragraph --></div><!-- /wp:group --><!-- wp:spacer /-->';
+ }
+
+ $sut = new class( $page, $content ) extends Universal {
+ /**
+ * Set the content source for the page under test.
+ *
+ * @param string $page Page to scan.
+ * @param string $content Page block markup.
+ */
+ public function __construct( string $page, string $content ) {
+ if ( 'cart' === $page ) {
+ $this->cart_content_source = $content;
+ } else {
+ $this->checkout_content_source = $content;
+ }
+ }
+ };
+
+ $this->assertSame( $expected, $sut->get_additional_blocks_on_page( $page ), 'The scan should report only blocks outside the ignored blocks.' );
+ }
+
/**
* Test that order_process calls wc_get_order with an integer order ID.
*/