Skip to content

chore: Add unit tests for MediaSharing and REST modules - Phase 3#137

Open
sabbir1991 wants to merge 3 commits into
chore/php-unit-testing-phase-2from
chore/php-unit-testing-phase-3
Open

chore: Add unit tests for MediaSharing and REST modules - Phase 3#137
sabbir1991 wants to merge 3 commits into
chore/php-unit-testing-phase-2from
chore/php-unit-testing-phase-3

Conversation

@sabbir1991

@sabbir1991 sabbir1991 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

What

Adds unit test coverage for the OneMedia MediaSharing and REST modules.

Why

This PR improves PHPUnit coverage for recently added MediaSharing and REST functionality, focusing on safe unit-testable paths and keeping the same test style used in the previous unit testing phases.

Related Issue(s):

  • Part of unit test coverage improvements for OneMedia.

How

This PR adds and expands PHPUnit tests for:

  • MediaSharing admin hook registration and safe admin output paths.
  • MediaSharing attachment sync status, version, and health-check validation behavior.
  • MediaSharing UI sync column rendering and row action filtering.
  • MediaSharing media protection edit/delete guard behavior.
  • MediaSharing media action helper methods and invalid request handling.
  • Media replacement behavior for post content and attachment metadata.
  • REST permission handling in the abstract REST controller.
  • Basic options REST controller settings behavior.
  • Media sharing REST controller validation and local metadata/update branches.

The tests avoid remote sync, upload, and AJAX exit-heavy success paths, and use WordPress test helpers/factories where possible.

Testing Instructions

  1. Check out this branch.

  2. Start the test environment with coverage enabled:

    npm run wp-env:test -- start --xdebug=coverage
  3. Run the PHP test suite:

    npm run test:php
  4. Start the default wp-env environment if needed for linting:

    npm run wp-env -- start
  5. Run PHP linting:

    npm run lint:php

Expected result:

  • PHPUnit passes successfully.
  • PHP linting passes successfully.

Screenshots

N/A. This PR only adds automated test coverage.

Additional Info

Last verified locally:

  • npm run test:php
    • Passed: 153 tests, 257 assertions
  • npm run lint:php

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • My code is tested to the best of my abilities.
  • My code passes all lints (ESLint etc.).
  • My code has detailed inline documentation.
  • I have updated the project documentation as needed.
  • I have added a changeset for this PR using npm run changeset.
Open WordPress Playground Preview

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.41%. Comparing base (b6f74f0) to head (d57e30b).

Additional details and impacted files
@@                          Coverage Diff                          @@
##             chore/php-unit-testing-phase-2     #137       +/-   ##
=====================================================================
+ Coverage                             17.97%   39.41%   +21.43%     
  Complexity                              666      666               
=====================================================================
  Files                                    22       22               
  Lines                                  2748     2748               
=====================================================================
+ Hits                                    494     1083      +589     
+ Misses                                 2254     1665      -589     
Flag Coverage Δ
unit 39.41% <ø> (+21.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants