Only 1 test file exists: PathFileEntityUiTest.php covering basic CRUD operations through the UI.
Key Areas Lacking Coverage
1. Access control - Published vs unpublished, permissions, anonymous access
2. File delivery - Controller, missing files, MIME types
3. Entity methods - getName(), getFid(), isPublished(), owner methods
4. Configuration - Settings form, allowed extensions changes
5. Path aliases - Custom paths, dual path access
Recommendation
Implement the tests first for ~70-80% functional coverage:
- PathFileEntityAccessTest (security)
- PathFileEntityTest (data integrity)
- PathFileControllerTest (core functionality)
Missing user_id base field definition
During test creations this problem occurred:
PathFileEntity implements EntityOwnerInterface and defines owner methods (getOwner(), setOwner(), etc.), but the user_id base field was never defined in baseFieldDefinitions(). This causes a fatal error when any code attempts to access the owner:
InvalidArgumentException: Field user_id is unknown.
Fix:
1. Added EntityOwnerTrait which provides the owner methods and getDefaultEntityOwner callback
2. Added user_id base field definition with entity reference to user
3. Added "owner" = "user_id" to entity keys (required by the trait)
4. Removed redundant manual owner method implementations and preCreate()
5. Added update hook path_file_update_10003() to install the field on existing sites
Changes:
- src/Entity/PathFileEntity.php - Added trait, field definition, entity key
- path_file.install - Added update hook to install field and set existing entities to uid 1
Issue fork path_file-3532777
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
batigolixWith the help of Claude code I created a functional test that creates a path file entity.
It fails on D 11, but that is expected because the D 11 compatibility is not released yet.
Comment #4
batigolixComment #5
batigolixComment #6
arjenk commentedReviewed and ran MR !15 locally on Drupal 11, looks good, all tests pass, pipeline green.
One observation: in tests/src/Functional/PathFileEntityUiTest.php, the edit and delete assertions (lines 127–161) are wrapped in
if (preg_match('/path-file\/(\d+)$/', $current_url)), which only matches /path-file/{id} URL. But PathFileEntityForm::save() (line 140) always redirects to the collection (entity.path_file_entity.collection), so that condition is never true and the edit/delete assertions never run.The non-test changes look good: replacing the owner methods with core's EntityOwnerTrait, adding the user_id base field + "owner" entity key, and dropping the NodeInterface::PUBLISHED dependency in favour of 1/0 all make sense, and path_file_update_10003() correctly installs the field and updates existing rows).
Small concern: This will not work together with MR !13 and !16, but since this ticket holds the unittests, i'd suggest to merge this first, and then fix 13/16.
Comment #7
batigolixI addressed the feedback in the last commits. Please have another look
Comment #8
arjenk commentedRe-tested the updated MR on on Drupal 11.3 — the unreachable edit/delete fix now works.
Code + fix look good; pipeline green. RTBC.
Comment #9
batigolix