Commit f1a46c52c56 for woocommerce
commit f1a46c52c5669826442b1cd79f203b7da67490eb
Author: louwie17 <lourensschep@gmail.com>
Date: Mon Nov 2 16:36:22 2026 +0100
Add tests that core links use Analytics instead of legacy Reports (#69246)
* Add tests for status widget and download log report links
* Add changelog entry for legacy report link tests
* Turn Analytics off in tests with a filter, not update_option()
Saving woocommerce_analytics_enabled sets Analytics::$is_updated, which
never resets, so later settings-save tests hit the reload redirect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015zLZuxfy4CYaqLzuGzU2Na
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/wooplug-7852-legacy-report-links b/plugins/woocommerce/changelog/wooplug-7852-legacy-report-links
new file mode 100644
index 00000000000..6daea5fcc00
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-7852-legacy-report-links
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Test status widget and download log report links with Analytics on and off; no production change.
+
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php b/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
index fdd5fbe815a..62a8ac83015 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
@@ -143,7 +143,6 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
* Test: get_status_widget
*/
public function test_status_widget_content() {
- $this->skip_if_hpos_enabled( 'We don\'t support legacy reports on HPOS' );
wp_set_current_user( $this->user );
$order = WC_Helper_Order::create_order();
$order->set_status( OrderStatus::COMPLETED );
@@ -159,19 +158,44 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;filter\=single_product/', $widget_output );
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;type\=lowstock/', $widget_output );
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;type\=outofstock/', $widget_output );
+ $this->assertDoesNotMatchRegularExpression( '/page\=wc-reports/', $widget_output, 'No status widget link should point to legacy Reports while Analytics is enabled.' );
}
/**
- * Test: get_status_widget with woo admin disabled.
+ * Ways Analytics can be turned off, each of which must bring back the legacy report links.
+ *
+ * @return array<string, array{callable}>
*/
- public function test_status_widget_with_woo_admin_disabled() {
+ public function provide_analytics_disabled_setups(): array {
+ return array(
+ 'woocommerce_admin_disabled filter' => array(
+ function () {
+ add_filter( 'woocommerce_admin_disabled', '__return_true' );
+ },
+ ),
+ 'analytics feature turned off' => array(
+ function () {
+ // A filter, not update_option(): saving the option makes Analytics redirect on the next settings save.
+ add_filter( 'pre_option_woocommerce_analytics_enabled', fn() => 'no' );
+ },
+ ),
+ );
+ }
+
+ /**
+ * @testdox Should use the legacy status widget reports filter when Analytics is disabled.
+ * @dataProvider provide_analytics_disabled_setups
+ *
+ * @param callable $disable_analytics Turns Analytics off.
+ */
+ public function test_status_widget_with_analytics_disabled( callable $disable_analytics ) {
$this->skip_if_hpos_enabled( 'We don\'t support legacy reports on HPOS' );
wp_set_current_user( $this->user );
$order = WC_Helper_Order::create_order();
$order->set_status( OrderStatus::COMPLETED );
$order->save();
- add_filter( 'woocommerce_admin_disabled', '__return_true' );
+ $disable_analytics();
$this->expectOutputRegex( '/50\.00 worth in the/' );
@@ -182,8 +206,7 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=orders\&\#038\;report\=sales_by_product/', $widget_output );
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=low_in_stock/', $widget_output );
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=out_of_stock/', $widget_output );
-
- remove_filter( 'woocommerce_admin_disabled', '__return_true' );
+ $this->assertDoesNotMatchRegularExpression( '/page\=wc-admin/', $widget_output, 'No status widget link should point to Analytics while it is disabled.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-reports-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-reports-test.php
index 9066e8cc838..ed4483ebb8c 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-reports-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-reports-test.php
@@ -25,4 +25,16 @@ final class WC_Admin_Reports_Test extends WC_Unit_Test_Case {
do_action( 'woocommerce_delete_legacy_report_transients', 0, false );
$this->assertFalse( get_transient( 'wc_admin_report' ) );
}
+
+ /**
+ * @testdox Should point the dashboard status widget at legacy Reports, which it only uses when Analytics is disabled.
+ */
+ public function test_replace_dashboard_status_widget_reports_uses_legacy_report_links(): void {
+ $reports = \WC_Admin_Reports::replace_dashboard_status_widget_reports( array() );
+
+ $this->assertSame( 'admin.php?page=wc-reports&tab=orders&range=month', $reports['net_sales_link'] );
+ $this->assertSame( 'admin.php?page=wc-reports&tab=orders&report=sales_by_product&range=month&product_ids=', $reports['top_seller_link'] );
+ $this->assertSame( 'admin.php?page=wc-reports&tab=stock&report=low_in_stock', $reports['lowstock_link'] );
+ $this->assertSame( 'admin.php?page=wc-reports&tab=stock&report=out_of_stock', $reports['outofstock_link'] );
+ }
}
diff --git a/plugins/woocommerce/tests/php/includes/admin/meta-boxes/views/html-order-download-permission-test.php b/plugins/woocommerce/tests/php/includes/admin/meta-boxes/views/html-order-download-permission-test.php
new file mode 100644
index 00000000000..e06d350d541
--- /dev/null
+++ b/plugins/woocommerce/tests/php/includes/admin/meta-boxes/views/html-order-download-permission-test.php
@@ -0,0 +1,38 @@
+<?php
+declare( strict_types = 1 );
+
+/**
+ * Tests for the download permission row rendered inside the order downloads meta box.
+ *
+ * @package WooCommerce\Tests\Admin
+ */
+class Html_Order_Download_Permission_Test extends WC_Unit_Test_Case {
+
+ /**
+ * @testdox Should keep the "View report" link on the legacy downloads report while Analytics is enabled.
+ */
+ public function test_view_report_links_to_legacy_downloads_report_when_analytics_is_enabled(): void {
+ add_filter( 'pre_option_woocommerce_analytics_enabled', fn() => 'yes' );
+
+ $product = WC_Helper_Product::create_simple_product();
+ $download = new WC_Customer_Download();
+ $download->set_product_id( $product->get_id() );
+ $download->set_download_id( 'file-id' );
+ $download->set_user_email( 'customer@example.com' );
+ $download->save();
+
+ $file_count = 'File 1';
+ $loop = 0;
+
+ ob_start();
+ include WC_ABSPATH . 'includes/admin/meta-boxes/views/html-order-download-permission.php';
+ $output = (string) ob_get_clean();
+
+ // Analytics has no per-permission downloads view, so this link is a documented exception.
+ $this->assertStringContainsString(
+ 'wp-admin/admin.php?page=wc-reports&tab=orders&report=downloads&permission_id=' . $download->get_id() . '"',
+ $output,
+ 'The download log link should target the legacy downloads report for this permission.'
+ );
+ }
+}