Make WordPress Core

Opened 7 months ago

Last modified 11 days ago

#65136 new enhancement

Unit Tests: Add tests for extract_from_markers() and stop empty values being returned

Reported by: pbearne Owned by:
Priority: normal Milestone: Awaiting Review
Component: Administration Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: tests

Description

The function extract_from_markers() in src/wp-admin/includes/misc.php lacks unit tests. This PR adds tests to ensure it correctly extracts content between markers in a file, handling missing files, different markers, and comments.

Change History (5)

This ticket was mentioned in ​PR #11658 on ​WordPress/wordpress-develop by ​@pbearne.


7 months ago
#1

  • Keywords has-patch has-unit-tests added

…sc.php

Reference: https://core.trac.wordpress.org/ticket/65136

This PR adds unit tests for the extract_from_markers() function in src/wp-admin/includes/misc.php.
The tests cover:

  • Extraction from a standard WordPress .htaccess block.
  • Handling of comments within markers.
  • Multiple marker blocks.
  • Non-existent files and missing markers.

Trac ticket: https://core.trac.wordpress.org/ticket/65136

## Use of AI Tools
AI assistance: Yes
Tool(s): Junie (JetBrains)
Model(s): gemini-3-flash-preview
Used for: Generating test cases, implementing set_up/tear_down for temporary file management, and validating extraction logic.

#2 @pbearne
7 months ago

  • Keywords has-patch has-unit-tests removed
  • Summary Unit Tests: Add tests for extract_from_markers() → Unit Tests: Add tests for extract_from_markers() and stop empty values being returned

In testing, I found that empty lines where beeing return in the array of values

Add code to stop this

#3 @pbearne
7 months ago

  • Keywords has-patch has-unit-tests added

#4 @desrosj
6 months ago

  • Focuses tests added

Adding the tests focus, which is used to indicate a ticket is solely focused on adding tests.

​@lancewillett commented on ​PR #11658:


11 days ago
#5

The blank-line removal is intentional in Trac comment 2, so a test-only split is not required. @desrosj could you review that returned-array contract before we land it? @pbearne please also fix the provider docblock indentation reported by PHPCS. Optional: a short blank-line fixture would show the behavior more clearly than the full .htaccess sample.

<sub>AI review · <code>gpt-6</code></sub>

Note: See TracTickets for help on using tickets.