Skip to content

Tests: Add unit tests for wp_start_scraping_edited_file_errors() - #14483

Closed
shail-mehta wants to merge 8 commits into
WordPress:trunkfrom
shail-mehta:65819-add-wp-start-scraping-edited-file-errors-tests
Closed

shail-mehta wants to merge 8 commits into
WordPress:trunkfrom
shail-mehta:65819-add-wp-start-scraping-edited-file-errors-tests

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #65819

Adds unit tests for wp_start_scraping_edited_file_errors() in tests/phpunit/tests/load/wpStartScrapingEditedFileErrors.php.

Covers missing/empty scrape params, a missing scrape transient, and a matching nonce that enables sandbox scraping.

Test-only change.

Why

This helper has had no dedicated PHPUnit coverage. Fits the #65819 missing-coverage track, and no open PR covers it.

How

  • Return early without scrape request params, empty params, or a missing transient
  • Define WP_SANDBOX_SCRAPING when the scrape key and nonce match

Testing instructions

npm run test:php -- --filter Tests_Load_WpStartScrapingEditedFileErrors

Use of AI Tools

  • Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The early-return tests need process isolation to prevent failures caused by constants defined by earlier tests.

1 open issue
What changed in this PR

Adds dedicated PHPUnit coverage for wp_start_scraping_edited_file_errors() as part of ticket #65819, without changing production code.

Changes:

  • Tests early returns for missing or empty request parameters and a missing transient.
  • Tests sandbox activation when the nonce matches.
File Description
tests/​phpunit/​tests/​load/​wpStartScrapingEditedFileErrors.php Adds four tests with request and transient cleanup.

Review effort: Balanced

Comment thread tests/phpunit/tests/load/wpStartScrapingEditedFileErrors.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The isolated tests cover the stated scenarios, with no blocking issues identified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 19, 2026 09:21
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25, mukesh27.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertions match wp_start_scraping_edited_file_errors(). Two points about process isolation inline.

*
* @group load
*
* @runTestsInSeparateProcesses

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the last test defines WP_SANDBOX_SCRAPING, and it already has @runInSeparateProcess. The first three tests assert that the constant is not defined, so they can run in the normal process. Could this class-level @runTestsInSeparateProcesses and @preserveGlobalState disabled be removed?

$_REQUEST['wp_scrape_key'] = $key;
$_REQUEST['wp_scrape_nonce'] = $nonce;

wp_start_scraping_edited_file_errors();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the nonce matches, this call registers wp_finalize_scraping_edited_file_errors() as a shutdown function. That function prints the scrape markers when the child process exits, after PHPUnit has written the test result. It works today, but it adds output to the child process result. Could the test remove that output, or note in a comment why it is safe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in latest commits.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The early-return tests need isolation to prevent false failures when earlier tests have already defined the sandbox constant.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues were identified in this focused test-only change; tests were not executed.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused test-only changes cover the stated scenarios with no identified blocking issues.

No open issues 🎉

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early-return cases preserve constant state, with process isolation limited to the successful registration case.

The unit-tests audit is complete. This class passed independently, and the ten-PR batch passed randomized single-site and multisite runs (61 tests, 95 assertions each). PHPCS passed. I also reviewed the fresh Copilot feedback.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 19, 2026
Cover early returns and successful registration in `wp_start_scraping_edited_file_errors()`. Isolate the case that defines a constant and registers a shutdown callback.

Developed in: #14483

Props shailu25, mukesh27.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64562 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 19, 2026
Cover early returns and successful registration in `wp_start_scraping_edited_file_errors()`. Isolate the case that defines a constant and registers a shutdown callback.

Developed in: WordPress/wordpress-develop#14483

Props shailu25, mukesh27.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64562


git-svn-id: http://core.svn.wordpress.org/trunk@63712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants