Skip to content

fix: resolve 3 PHPUnit failures + 1 error on trunk test code#4

Closed
epeicher wants to merge 1 commit into
fix/php-testsfrom
fix/php-tests-assertions
Closed

fix: resolve 3 PHPUnit failures + 1 error on trunk test code#4
epeicher wants to merge 1 commit into
fix/php-testsfrom
fix/php-tests-assertions

Conversation

@epeicher
Copy link
Copy Markdown
Collaborator

Depends on #2 for the working vendor/bin/phpunit + WP test-suite install. Once the CI infra from #2 started actually running PHPUnit, four real issues became visible in trunk's code/tests. Each fix below is targeted and explains why rather than re-stating what.

Fixes

1. WpDesktopBuildDockItems::test_placement_distinguishes_core_from_plugin_menus — ERROR

Undefined array key "menu-index-php".

The test helper make_menu_row built synthetic hooknames as 'menu-' . sanitize_key( $slug ). sanitize_key strips . entirely, so index.phpindexphp, producing dock id menu-indexphp. The assertion expects menu-index-php (the real WP hookname style that normalizes dots to dashes).

Fix: pre-replace .- in the slug before passing it to sanitize_key inside the helper.

2+3. Security::test_data_uri_rejected and WpDesktopBuildDockItems::test_icon_data_svg_rejected — FAILURES

Both expect every data: URI (including data:image/svg+xml;base64,…) to fall back to dashicons-admin-generic. wpdm_sanitize_dock_icon carried a special-case branch that accepted base64-encoded SVG data URIs, directly contradicting its own @since 0.11.0 Rejects data: URIs outright docstring.

Fix: drop the branch so every data: URI falls through to the fallback, matching the documented Phase-11 intent.

4. WpDesktopSession::test_save_session_accepts_equal_timestamp — FAILURE

Failed asserting that false is true. on the second save.

wpdm_sanitize_session always stamped $clean['updated'] = time() before the save logic ran, overwriting whatever updated the client sent. That meant the stale-write guard compared incoming against a server-time stored, so equal-timestamp writes looked strictly-older and got rejected.

Fix: preserve the client's updated when valid, fall back to time() only when missing or invalid. test_save_session_rejects_stale_write and test_save_session_accepts_missing_timestamp continue to pass under the same logic.

Test plan

  • CI: Tests: 331, Assertions: 698, Errors: 0, Failures: 0 on both PHP 8.1 and 8.2 matrix legs
  • js lane: still green

Pre-existing trunk issues that became visible once the PHP test
infra on fix/php-tests started actually running phpunit in CI.

1. wpDesktopBuildDockItems::test_placement_distinguishes_core_from_plugin_menus
   (ERROR: Undefined array key "menu-index-php")

   The test helper `make_menu_row` built synthetic hooknames via
   `'menu-' . sanitize_key( $slug )`. `sanitize_key` strips `.`
   entirely, so `index.php` became `indexphp`, producing dock item
   id `menu-indexphp` — but the test asserted `menu-index-php`.
   Real WP hooknames normalize dots to dashes; pre-replace in the
   helper so synthetic ids match what the tests assert.

2+3. Security::test_data_uri_rejected and
   WpDesktopBuildDockItems::test_icon_data_svg_rejected

   `wpdm_sanitize_dock_icon` carried a special-case branch that
   accepted `data:image/svg+xml;base64,<valid-base64>` values,
   directly contradicting its own JSDoc ("@SInCE 0.11.0 Rejects
   `data:` URIs outright; previously accepted `data:image/svg+xml`
   values"). Drop the branch so every data: URI falls through to
   the fallback dashicon, matching the documented Phase-11 intent.

4. WpDesktopSession::test_save_session_accepts_equal_timestamp
   (Failed asserting that false is true.)

   `wpdm_sanitize_session` always stamped `$clean['updated'] =
   time()` before the save logic ran, overwriting whatever
   timestamp the client sent. That meant the stale-write guard in
   `wpdm_save_session` compared `incoming` against a server-time
   `stored`, so equal-timestamp writes (the scenario the test
   covers) looked strictly-older and got rejected. Preserve the
   client's `updated` when valid, fall back to `time()` only when
   missing or invalid.
@epeicher
Copy link
Copy Markdown
Collaborator Author

Closed in favour of #7

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.

1 participant