Skip to content

Expanded fixture paths inside compound file/image field values.#638

Merged
AlexSkrypnyk merged 5 commits into
mainfrom
feature/expand-compound-fixtures
May 19, 2026
Merged

Expanded fixture paths inside compound file/image field values.#638
AlexSkrypnyk merged 5 commits into
mainfrom
feature/expand-compound-fixtures

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Member

@AlexSkrypnyk AlexSkrypnyk commented May 19, 2026

Summary

HelperTrait::helperExpandEntityFieldsFixtures() previously assumed field values were either plain scalars or simple arrays, missing the modern drupal-extension compound parser shape where a file/image cell is written as target_id:"foo.jpg", alt:"A". As a result, fixture path expansion was silently skipped for any compound cell, forcing callers to supply absolute paths. This change adds two new code paths - one for raw compound strings (the node route, where the cell arrives before parseEntityFields() runs) and one for the already-parsed associative-array shape (the media route) - so fixture basenames are expanded correctly in both cases.

Changes

src/HelperTrait.php

  • Added helperLooksLikeCompoundCell() - detects raw compound cell strings matching the key:"..." or key:[...] pattern that EntityFieldParser uses to enter compound mode.
  • Added helperExpandCompoundCellFixtures() - rewrites the target_id:"basename" segment inside a raw compound string, leaving all other columns (e.g. alt, description) untouched.
  • Refactored the main field-expansion loop to handle three value shapes: raw compound string, parsed compound array ([['target_id' => 'foo.jpg', 'alt' => 'A']]), and the original plain scalar/simple array.

tests/behat/features/drupal_content.feature

  • Added scenario for a file field on a node using the compound cell syntax (target_id:"text.txt", description:"My document").
  • Added scenario for an image field on a node using the compound cell syntax (target_id:"image.png", alt:"My image").

Before / After

Before (compound cell - path expansion silently skipped):

  helperExpandEntityFieldsFixtures()
    |
    +-- value = 'target_id:"foo.jpg", alt:"A"'   (string, not an array)
    |
    +-- basename = 'target_id:"foo.jpg", alt:"A"' (the whole string)
    |
    +-- str_contains(basename, '"') == FALSE
    |   basename !== basename(basename)  => TRUE   <-- skips
    |
    => field left unchanged, Drupal receives bare basename, file not found


After (compound cell - path expansion applied correctly):

  helperExpandEntityFieldsFixtures()
    |
    +-- value = 'target_id:"foo.jpg", alt:"A"'
    |
    +-- helperLooksLikeCompoundCell() => TRUE
    |
    +-- helperExpandCompoundCellFixtures()
    |     preg_replace_callback on target_id:"..." segment
    |     => 'target_id:"/path/to/fixtures/foo.jpg", alt:"A"'
    |
    => field updated, Drupal receives full path, file found

Summary

This PR extends fixture path expansion to support compound entity field values in drupal-extension compound parser syntax, ensuring file/image compound cell values (e.g., target_id:"foo.jpg", alt:"A") are expanded to absolute fixture paths so Drupal receives full file paths.

Changes Made

src/HelperTrait.php

  • Added protected helperLooksLikeCompoundCell(string $value): bool to detect raw compound cell strings (patterns like key:"..." or key:[...]).
  • Added protected helperExpandCompoundCellFixtures(string $value, string $fixture_path): string to rewrite only the target_id:"basename" segment inside raw compound strings to an absolute fixture path.
  • Refactored protected helperExpandEntityFieldsFixtures(string $entity_type, EntityStubInterface $stub): void to handle three shapes:
    1. Raw compound strings (node-style) — in-string target_id rewriting.
    2. Parsed compound associative arrays (media-style) — mutate target_id values in the parsed structure.
    3. Plain scalars and simple arrays — original behavior preserved.
  • Expansion rules: only rewrite basenames that contain no path separators, are not already backed by managed files (helperManagedFileExists), and resolve to actual files under the fixtures directory.
  • Fixes handling of multi-value scalar lists so the correct element(s) are expanded.

tests/behat/features/drupal_content.feature

  • Added scenarios validating file and image fields specified using compound fixture syntax (e.g., target_id:"text.txt", description:"..."; target_id:"image.png", alt:"...") to ensure fixture resolution and resulting content assertions.

tests/phpunit/src/HelperTraitTest.php

  • New PHPUnit tests covering helperLooksLikeCompoundCell() and helperExpandCompoundCellFixtures(), with temporary fixture creation and managed-file existence stubbing via a test implementation wrapper.
  • Added tests exercising the expanded helperExpandEntityFieldsFixtures behavior across scalar, list and compound shapes.

composer.json

  • Updated drupal/drupal-driver dependency to dev-feature/normalise-public as 3.0 to obtain compound-shape support required by the parsing/expansion logic.

API / Public Surface

  • New protected methods in HelperTrait:
    • helperLooksLikeCompoundCell(string): bool
    • helperExpandCompoundCellFixtures(string, string): string
  • helperExpandEntityFieldsFixtures(...) behaviour updated (signature unchanged).

Step Definition Compliance (per CONTRIBUTING.md)

I reviewed CONTRIBUTING.md and the modified Behat feature file. The new scenarios follow the repository's step-definition formatting rules (no new step definitions introduced; tuple-format placeholders and phrasing preserved). No step-definition format violations were found. No Critical issues detected.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 53858e9f-9a36-4d92-bd57-28548003f49a

📥 Commits

Reviewing files that changed from the base of the PR and between 5264174 and ebb1af4.

📒 Files selected for processing (2)
  • src/HelperTrait.php
  • tests/phpunit/src/HelperTraitTest.php

Walkthrough

Entity stub fixture handling now detects compound field values (raw strings or parsed structures), extracts a target_id basename, and rewrites that basename to an absolute fixture path when a matching fixture exists and no managed file with the same basename is present. Two helper methods and unit/acceptance tests were added; composer constraint updated.

Changes

Compound fixture value handling

Layer / File(s) Summary
Fixture expansion logic for compound values
src/HelperTrait.php
helperExpandEntityFieldsFixtures() now branches on raw compound cell strings vs parsed compound values, extracts candidate basenames from target_id (or first-element fallback), checks managed-file presence and fixture file existence, and rewrites only the target_id/first-element entry. Adds helperLooksLikeCompoundCell() and helperExpandCompoundCellFixtures() for detection and in-string target_id replacement via regex.
Unit tests for helper methods
tests/phpunit/src/HelperTraitTest.php
Adds HelperTraitTest and HelperTraitTestImplementation to test helperLooksLikeCompoundCell(), helperExpandCompoundCellFixtures(), and helperExpandEntityFieldsFixtures() using temporary fixture files and an in-memory stub for managed basenames.
Acceptance test scenarios for compound fixtures
tests/behat/features/drupal_content.feature
Two @api scenarios validate that compound fixture specs for a file and an image field (e.g., target_id:"text.txt") resolve to fixture content and appear in responses with the expected extension/title.

Dependency constraint update

Layer / File(s) Summary
Composer drupal-driver constraint change
composer.json
drupal/drupal-driver requirement changed from ^3.0@RC to dev-feature/normalise-public as 3.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • drevops/behat-steps#634: Related updates to HelperTrait::helperExpandEntityFieldsFixtures() and fixture expansion wiring.

Poem

🐇 I sniffed the basenames in twilight light,

I nudged each target_id into its bright path,
Compound cells revealed their hidden name,
Tests hum softly as fixtures find their place,
A rabbit hops off, content, with a happy face.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The linked issue #39 title 'Fix array variable set' is vague and provides insufficient context to validate whether code changes meet specific requirements. Review the full linked issue #39 details to confirm the PR addresses the intended array variable set requirements.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: expanding fixture paths within compound file/image field values, which aligns with the core functionality added in HelperTrait.php.
Out of Scope Changes check ✅ Passed All changes focus on fixture path expansion for compound field values: core logic in HelperTrait, test coverage for the helpers, Behat scenarios demonstrating the feature, and a dependency update supporting the feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/expand-compound-fixtures

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/behat/features/drupal_content.feature (1)

375-393: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add coverage for the parsed compound/media path.

These scenarios only exercise the raw node-cell branch (target_id:"..." before parseEntityFields() runs). helperExpandEntityFieldsFixtures() now also mutates already-parsed compound arrays on the media route, and that new branch is still untested here. Please add one media file/image scenario so regressions in the parsed-shape handling are caught too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/behat/features/drupal_content.feature` around lines 375 - 393, Add a
new Behat scenario that covers the parsed-shape branch for media/compound fields
so helperExpandEntityFieldsFixtures()’s mutation of already-parsed compound
arrays is exercised. Specifically, add one scenario similar to the existing
"Compound fixture file" or "Compound fixture image" cases but using the
parsed/media-shaped fixture input that parseEntityFields() would produce (the
shape your tests use for media routes), visit the corresponding content edit
page and assert the expected filename/alt/description appears; this ensures the
code paths in helperExpandEntityFieldsFixtures() and parseEntityFields() are
both covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/behat/features/drupal_content.feature`:
- Around line 375-393: Add a new Behat scenario that covers the parsed-shape
branch for media/compound fields so helperExpandEntityFieldsFixtures()’s
mutation of already-parsed compound arrays is exercised. Specifically, add one
scenario similar to the existing "Compound fixture file" or "Compound fixture
image" cases but using the parsed/media-shaped fixture input that
parseEntityFields() would produce (the shape your tests use for media routes),
visit the corresponding content edit page and assert the expected
filename/alt/description appears; this ensures the code paths in
helperExpandEntityFieldsFixtures() and parseEntityFields() are both covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cbc49947-3ff1-4a82-b522-eaf40da8be3f

📥 Commits

Reviewing files that changed from the base of the PR and between 2dedcbf and 276a105.

📒 Files selected for processing (2)
  • src/HelperTrait.php
  • tests/behat/features/drupal_content.feature

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/HelperTrait.php`:
- Around line 260-302: The loop currently treats any array of scalars like
['a.jpg','b.jpg'] as a single compound record because $is_compound is only set
when the first element is itself an array; update the logic around
$is_compound/$records so that plain numeric-indexed lists of scalars are
detected and handled element-by-element (i.e. treat a list of scalars as
compound), iterate each scalar entry and replace its basename with $fixture_path
. $basename when appropriate (using helperManagedFileExists() and is_file()
checks), and finally call $stub->setValue($name, $is_compound ? $records :
$records[0]) as before; refer to $is_compound, $records, $value, $record,
helperManagedFileExists(), $fixture_path, and $stub->setValue() when making the
change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2783de7d-4b9e-4d72-a054-737371bb8ae5

📥 Commits

Reviewing files that changed from the base of the PR and between 1947973 and 4a2fbbb.

📒 Files selected for processing (2)
  • src/HelperTrait.php
  • tests/phpunit/src/HelperTraitTest.php

Comment thread src/HelperTrait.php Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@composer.json`:
- Line 23: The composer dependency "drupal/drupal-driver":
"dev-feature/normalise-public as 3.0" references a non-existent branch; locate
the correct branch or fork in the drupal-driver repo (or the intended fork) and
update the composer requirement to point to that existing branch, or replace the
dev-branch alias with a specific commit hash (e.g., dev-branch@<commit> or
"vX.Y.Z") or a forked repository reference if the branch lives elsewhere, and
add a brief comment in composer.json/README documenting the temporary workaround
and rationale for the chosen reference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: accc341c-3f2d-4982-8c5d-ecea6a3f6874

📥 Commits

Reviewing files that changed from the base of the PR and between 4a2fbbb and 5264174.

📒 Files selected for processing (1)
  • composer.json

Comment thread composer.json
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.93%. Comparing base (2dedcbf) to head (ebb1af4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/HelperTrait.php 89.74% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #638      +/-   ##
==========================================
- Coverage   96.94%   96.93%   -0.01%     
==========================================
  Files          43       43              
  Lines        3040     3068      +28     
==========================================
+ Hits         2947     2974      +27     
- Misses         93       94       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@AlexSkrypnyk AlexSkrypnyk merged commit 2f4ad7d into main May 19, 2026
14 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/expand-compound-fixtures branch May 19, 2026 04:46
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