Skip to content

[tests] Cut product export E2E from 4 titles to 1, moving the export screen to PHPUnit - #68649

Open
vladolaru wants to merge 2 commits into
trunkfrom
testops-288/products-admin-export
Open

[tests] Cut product export E2E from 4 titles to 1, moving the export screen to PHPUnit#68649
vladolaru wants to merge 2 commits into
trunkfrom
testops-288/products-admin-export

Conversation

@vladolaru

@vladolaru vladolaru commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Submission Review Guidelines:

Changes proposed in this Pull Request:

Three of the four product export browser titles were checking what the export screen renders when you arrive from the product list with a selection: which products it lists, where the clear link points, and what it shows when nothing is selected. That is a view assertion, and a view is cheaper and more precisely testable from PHP than through wp-admin. Those three move down a layer; the one that genuinely needs a browser stays.

Refs TESTOPS-288

Part of the #68046 split.

Removed E2E test Existing coverage Knowingly dropped
should allow exporting a single selected simple product WC_Admin_Product_Export_View_Test::test_selected_products_render_exact_export_state renders the real view template and asserts the hidden product_ids input and the screen copy The product list's Export 1 selected button text and href. See below.
should allow exporting multiple selected products (simple and variable) the same view test, plus WC_Product_CSV_Exporter_Test::test_selected_product_ids_restrict_export_rows, which proves the exporter scopes its rows to the selected products and their variations Nothing. The PHP test asserts more than the browser title did: the browser never checked which rows the exporter would produce.
should allow clearing selection from the export page folded into the retained title, which still navigates the clear link and asserts the URL drops product_ids Nothing.
should show the default export screen when no products are selected WC_Admin_Product_Export_View_Test's second test renders the same template with no selection Nothing on the export screen itself.

The retained title, preserves multiple selection through export and clear, is the one no lower layer can replace: it starts on the product list, carries a real selection across a navigation, and then clears it.

No test here reads an actual CSV file, and none did before

Worth stating plainly, because "product export" suggests otherwise. Neither the removed browser titles nor the new PHP tests ever generate a CSV and read its bytes. The old titles asserted button text, hrefs and screen copy; the new tests assert the rendered view and the exporter's in-memory row set. product-export.spec.ts has no download handling at all — the only specs in the suite that wait on a download are analytics.spec.ts and customer-list.spec.ts.

So this batch moves assertions sideways, from the browser to PHP. It does not deepen coverage of the export mechanism, and the gap in end-to-end CSV file coverage is pre-existing and untouched.

The one real loss: the product list's export button

The Export N selected button on the product list is written by jQuery (client/legacy/js/admin/woocommerce_admin.js), not by the view this batch tests, so no PHP test can reach it.

The singular case is less of a loss than it first looks. The button text is a single string with %d substituted — woocommerce_admin.strings.export_selected_products.replace( '%d', count ) — with no separate singular branch, so Export 1 selected and Export 2 selected travel the same code path, and the retained title still exercises it with two products.

What is genuinely unverified now is the other branch: restoring the button's original text and href when the last checkbox is unchecked. Nothing covers that any more.

This file had moved on trunk, and the branch's version was not taken blind

class-wc-product-csv-exporter-test.php gained a method on trunk after this work branched: #68567 added test_export_row_for_product_loaded_before_its_global_attribute_is_deleted. Checking out the migration branch's copy wholesale would have deleted it.

Instead trunk's file was kept and only this branch's method re-applied on top. The result is checkable rather than asserted: both methods are present, the file's diff against trunk has zero deleted lines, and the class goes from 5 tests to 6.

Screenshots or screen recordings:

Not applicable. Test-only change.

How to test the changes in this Pull Request:

  1. Check out this branch and run pnpm install --frozen-lockfile from the repository root.
  2. Start the PHPUnit environment: pnpm --filter=@woocommerce/plugin-woocommerce env:test.
  3. Run the two PHP classes with anchored filters. Anchoring matters: a sibling class WC_Tests_Product_CSV_Exporter exists, and PHPUnit's --filter is an unanchored substring regex, so a loose filter runs more than it claims.
    • pnpm --filter=@woocommerce/plugin-woocommerce test:php:env -- --filter '/^WC_Product_CSV_Exporter_Test::/' — expect OK (6 tests, 32 assertions).
    • pnpm --filter=@woocommerce/plugin-woocommerce test:php:env -- --filter '/^WC_Admin_Product_Export_View_Test::/' — expect OK (2 tests, 21 assertions).
  4. Start the E2E environment: pnpm --filter=@woocommerce/plugin-woocommerce env:e2e.
  5. Run the spec with retries disabled: pnpm --filter=@woocommerce/plugin-woocommerce test:e2e:with-env default --project=core-parallel --retries=0 --workers=1 tests/e2e/tests/product/product-export.spec.ts. The retained title should pass; the summary reads 3 passed and 1 skipped, the 3 being that title plus the global authentication and site setup projects.
  6. Confirm the new view test detects a real regression in the template. In plugins/woocommerce/includes/admin/views/html-admin-page-product-export.php, find the branch that echoes the hidden product_ids input and change its if ( $is_exporting_product_ids ) { to if ( false ) {. Re-run the first command in step 3 and expect test_selected_products_render_exact_export_state to fail with Failed asserting that null is identical to '10'.. Revert.
  7. Confirm the exporter test detects a scoping regression. In plugins/woocommerce/includes/export/class-wc-product-csv-exporter.php, in prepare_data_to_export, change $args['include'] = $this->product_ids_to_export; to $args['include'] = array();. Re-run the first command in step 3 and expect test_selected_product_ids_restrict_export_rows to fail on an array-identity assertion, admitting an unrelated product and omitting the selected variations. Revert.
  8. Confirm the retained browser title still guards the clear link. In the same view file, change $clear_url = remove_query_arg( 'product_ids' ); to $clear_url = add_query_arg( 'product_ids', implode( ',', $product_ids_to_export ) );. Re-run step 5 and expect a failure reading Expected substring: not "product_ids=", with the URL still carrying the selected IDs. Revert.

Testing that has already taken place:

Everything below ran on this branch against a local WordPress, with retries disabled and one worker. Trunk was at adefb5f971.

  • Baseline first. Trunk's copy of the spec ran green before extraction (4 titles), and trunk's WC_Product_CSV_Exporter_Test was OK (5 tests, 29 assertions) under the anchored filter. So the environment was known good and the merge result is measured against a real starting point.
  • Extraction. The spec and the new view test are byte-identical to the migration branch. The exporter test is deliberately not: it is trunk's file plus this branch's one method, verified additive.
  • Retained title. Green at --retries=0 --workers=1.
  • Lower layer. WC_Product_CSV_Exporter_Test OK (6 tests, 32 assertions); WC_Admin_Product_Export_View_Test OK (2 tests, 21 assertions).
  • Mutation re-check, all 3 behavior families. One recorded mutation per family, each turning its focused command red at the assertion the mutation matrix names, each reverted and green again: the view's hidden-input branch, the exporter's include scoping, and the view's clear-link URL.
  • Lint. lint:changes:branch exits 0 with one pre-existing warning and no errors. oxlint attributes no new finding to the change.
  • PHPStan: not applicable, and checked rather than assumed. phpstan.neon scopes to woocommerce.php, src/ and includes/; this batch touches only tests/.
  • Identifier sweep. No internal campaign identifiers in any of the three paths, with a detector proven against a file where such identifiers do exist.

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Created manually: plugins/woocommerce/changelog/testops-288-products-admin-export.

Use of AI Tools

The migration was produced by an agent-run campaign with per-test mutation verification (see #68046). This PR was assembled, verified in isolation, and reviewed by an agent; the author reviewed the diff and takes responsibility for it.


🤖 Generated with Claude Code

Three of the four product export browser titles were checking what the
export screen renders when you arrive from the product list with a
selection: which products are listed, what the clear link points at,
and what the screen shows when nothing is selected. That is a view
assertion, and a view is cheaper and more precisely testable from PHP
than through wp-admin.

The retained title, `preserves multiple selection through export and
clear`, is the one that needs a browser: it starts on the product
list, carries a real selection across a navigation, and then clears
it. Nothing below the browser can prove that handoff.

Two PHP additions take the rest:

- WC_Admin_Product_Export_View_Test renders
  includes/admin/views/html-admin-page-product-export.php directly and
  asserts what the screen shows for a selection and for none.
- WC_Product_CSV_Exporter_Test gains
  test_selected_product_ids_restrict_export_rows, which proves the
  exporter scopes its rows to the selected products and their
  variations.

Knowingly dropped: the product list's "Export N selected" button is
written by jQuery on a different screen, so neither PHP test can
reach it. The retained title still covers it for two products; the
singular N=1 wording and the default button text before any selection
are no longer verified anywhere.

class-wc-product-csv-exporter-test.php had moved on trunk since this
work branched: #68567 added a regression test for exporting a product
whose global attribute was deleted. Rather than take the frozen state
blind and drop that method, trunk's copy was kept and only this
branch's method re-applied on top. The file's diff against trunk is
purely additive; both methods are present and the class goes from 5
tests to 6.

Carries the mega-branch commits:
- aba55f9 test(e2e): Reduce Product Export browser coverage
- d4d6e9e test: Fix migration branch lint

Refs TESTOPS-288
Refs #68046

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. focus: e2e tests Issues related to e2e tests labels Sep 12, 2026
@vladolaru
vladolaru marked this pull request as ready for review September 13, 2026 14:06
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 359fc3e6-309c-408f-86e2-878f2e81c121

📥 Commits

Reviewing files that changed from the base of the PR and between 3eeb64f and d39a9a5.

📒 Files selected for processing (4)
  • plugins/woocommerce/changelog/testops-288-products-admin-export
  • plugins/woocommerce/tests/e2e/tests/product/product-export.spec.ts
  • plugins/woocommerce/tests/php/includes/admin/views/class-wc-admin-product-export-view-test.php
  • plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant