-
Notifications
You must be signed in to change notification settings - Fork 80
Follow[ers|ing]: Avoid errors when getting avatar url #2088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add comprehensive test class for WP_Admin\Table\Followers - Test column_username method with ActivityPub actor icon objects - Simulate realistic data processing from icon object to URL extraction - Include proper WordPress screen mocking and setup - Verify HTML output formatting and escaping
- Use Followers::add_follower() to create actual follower relationships - Mock remote actor metadata using pre_get_remote_metadata_by_actor filter - Test complete data flow: add_follower → prepare_items → column_username - Verify ActivityPub icon object processing through object_to_uri() - Test confirms icon object {type: 'Image', url: '...'} → URL string conversion - All tests pass with real integration of components
- Create test class for Following table column_username method - Use Actors::upsert() and Following::follow() for real data setup - Mock remote actor metadata using pre_get_remote_metadata_by_actor filter - Test complete data flow: upsert → follow → prepare_items → column_username - Verify ActivityPub icon object processing through object_to_uri() - Test confirms icon object {type: 'Image', url: '...'} → URL string conversion - Mirrors Followers table test structure for consistency
- Fix Following table to use object_to_uri() for consistent icon processing like Followers table - Clean up Following test formatting and import organization - Remove unnecessary test assertions for cleaner test structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive unit tests for the Followers and Following table classes to address a critical TypeError reported on WordPress support forums where avatar data processing was failing when handling ActivityPub icon objects.
- Adds unit tests for both Followers and Following table classes with proper ActivityPub icon object handling
- Fixes inconsistent icon processing in the Following table to use
object_to_uri()
like the Followers table - Tests verify complete data flow from ActivityPub actor creation through table rendering to ensure proper icon object conversion
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/includes/wp-admin/table/class-test-following.php | New comprehensive unit tests for Following table class with ActivityPub icon object handling |
tests/includes/wp-admin/table/class-test-followers.php | New comprehensive unit tests for Followers table class with ActivityPub icon object handling |
includes/wp-admin/table/class-following.php | Fixed icon processing to use object_to_uri() consistently with Followers table |
includes/wp-admin/table/class-followers.php | Context showing existing object_to_uri() usage for icon processing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
It would be useful to have the option to configure a default image that is displayed when a remote profile has no avatar. |
@@ -223,7 +223,7 @@ public function prepare_items() { | |||
|
|||
$this->items[] = array( | |||
'id' => $follower->ID, | |||
'icon' => $actor->get_icon()['url'] ?? '', | |||
'icon' => object_to_uri( $actor->get_icon() ?? '' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, nice solution! never thought about using it here!
For posterity, the icon object for the actor mentioned in the support forum looked like this: "icon": {
"url": [
"https://queef.in/storage/profile.webp"
],
"type": "Image",
"mediaType": "image/webp"
}, |
Add unit test to verify that actors with icon objects containing arrays of URLs are handled correctly by the Following table. Currently this test will fail as the object_to_uri function doesn't fully process nested arrays in Image objects.
Update object_to_uri function to properly handle Image objects where the url property is an array of URLs. This fixes the Following table display when actors have icon objects with multiple URL fallbacks. The fix recursively processes Image url arrays to extract the first URL, matching the ActivityStreams vocabulary specification.
@@ -730,7 +730,8 @@ function object_to_uri( $data ) { | |||
// Return part of Object that makes most sense. | |||
switch ( $type ) { | |||
case 'Image': | |||
$data = $data['url']; | |||
// See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image. | |||
$data = object_to_uri( $data['url'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wanted to suggest that :)
nice 👍
See https://wordpress.org/support/topic/critical-error-on-this-website-on-followerspage-page-1-page-2-works/
Proposed changes:
This PR adds comprehensive unit tests for the Followers and Following table classes in response to a critical error reported on the WordPress support forums where avatar data processing was failing with a TypeError.
Changes made:
tests/includes/wp-admin/table/class-test-followers.php
)tests/includes/wp-admin/table/class-test-following.php
)object_to_uri()
consistently like the Followers tablecolumn_username
method with ActivityPub icon objectsprepare_items()
methods and proper ActivityPub actor creation to verify the complete data flowBug context:
The tests were created in response to this WordPress support topic where users experienced a PHP Fatal TypeError with
ltrim()
when processing avatar data that was an array instead of a string. The tests ensure proper handling of ActivityPub actor icon objects throughout the data processing pipeline.Other information:
Testing instructions:
Running the new tests:
npm run env-start
Verifying the fix:
type
andurl
properties)prepare_items()
methods to process this dataobject_to_uri()
Manual testing (optional):
Changelog entry
Changelog Entry Details
Significance
Type
Message
Add comprehensive unit tests for Followers and Following table classes with proper ActivityPub icon object handling.