Skip to content

Commit 6e60680

Browse files
committed
Fix ComponentGroup location/reference to match Nuxt module conventions
The module looks up component groups by reference = "{slot}_{ownerIri}" and sets location = ownerIri when auto-creating groups. Fixture-created groups must use the same format so the module finds and renders them instead of creating new empty groups over the top.
1 parent 967058d commit 6e60680

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/Fixture/CwaFixtureBuilder.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,11 @@ private function phaseOne(): void
296296

297297
private function createAndLinkComponentGroup(GroupBuilder $groupBuilder, Layout|Page $owner): void
298298
{
299-
$componentGroup = new ComponentGroup();
300-
$componentGroup->location = $groupBuilder->getName();
299+
$ownerIri = $this->iriConverter->getIriFromResource($owner);
301300

302-
if ($owner instanceof Layout) {
303-
$componentGroup->reference = \sprintf('layout:%s/%s', $owner->reference, $groupBuilder->getName());
304-
} else {
305-
$componentGroup->reference = \sprintf('page:%s/%s', $owner->reference ?? $owner->getTitle(), $groupBuilder->getName());
306-
}
301+
$componentGroup = new ComponentGroup();
302+
$componentGroup->location = $ownerIri;
303+
$componentGroup->reference = $groupBuilder->getName() . '_' . $ownerIri;
307304

308305
foreach ($groupBuilder->getAllowedClasses() as $class) {
309306
$componentGroup->addAllowedComponent(
@@ -318,6 +315,12 @@ private function createAndLinkComponentGroup(GroupBuilder $groupBuilder, Layout|
318315
$this->timestampedPersister->persistTimestampedFields($componentGroup, true);
319316
// Add to the owning side BEFORE the first flush so Doctrine writes the join table.
320317
$owner->getComponentGroups()->add($componentGroup);
318+
// Sync the inverse side for in-memory consistency (Doctrine populates it from DB on load).
319+
if ($owner instanceof Layout) {
320+
$componentGroup->layouts->add($owner);
321+
} else {
322+
$componentGroup->pages->add($owner);
323+
}
321324
$this->componentGroupMap[spl_object_id($groupBuilder)] = $componentGroup;
322325
$this->manager->persist($componentGroup);
323326
}

tests/Fixture/CwaFixtureBuilderTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ public function test_layout_group_creates_component_group_with_correct_propertie
170170
$em = $this->collectingEm($persisted);
171171

172172
$iriConverter = $this->createStub(IriConverterInterface::class);
173-
$iriConverter->method('getIriFromResource')->willReturn('/_/some_components'); // any call returns the stub IRI
173+
$iriConverter->method('getIriFromResource')->willReturnCallback(
174+
static fn ($resource) => is_string($resource) ? '/_/some_components' : '/_api/_/layouts/test-uuid'
175+
);
174176

175177
$builder = $this->makeBuilder($em, iriConverter: $iriConverter);
176178
$builder->layout('main', 'CwaLayoutPrimary')->group('nav', allow: [\stdClass::class]);
@@ -180,8 +182,8 @@ public function test_layout_group_creates_component_group_with_correct_propertie
180182
$layouts = array_values(array_filter($persisted, static fn ($e) => $e instanceof Layout));
181183

182184
$this->assertCount(1, $groups);
183-
$this->assertSame('layout:main/nav', $groups[0]->reference);
184-
$this->assertSame('nav', $groups[0]->location);
185+
$this->assertSame('nav_/_api/_/layouts/test-uuid', $groups[0]->reference);
186+
$this->assertSame('/_api/_/layouts/test-uuid', $groups[0]->location);
185187
$this->assertSame(['/_/some_components'], $groups[0]->allowedComponents);
186188

187189
$this->assertCount(1, $layouts);
@@ -196,7 +198,10 @@ public function test_page_group_creates_component_group_linked_to_page(): void
196198
$persisted = [];
197199
$em = $this->collectingEm($persisted);
198200

199-
$builder = $this->makeBuilder($em);
201+
$iriConverter = $this->createStub(IriConverterInterface::class);
202+
$iriConverter->method('getIriFromResource')->willReturn('/_api/_/pages/test-uuid');
203+
204+
$builder = $this->makeBuilder($em, iriConverter: $iriConverter);
200205
$builder->layout('main', 'CwaLayoutPrimary');
201206
$builder->page('home', 'PrimaryPageTemplate', layout: 'main', isTemplate: true)
202207
->group('primary');
@@ -206,8 +211,8 @@ public function test_page_group_creates_component_group_linked_to_page(): void
206211
$pages = array_values(array_filter($persisted, static fn ($e) => $e instanceof Page));
207212

208213
$this->assertCount(1, $groups);
209-
$this->assertSame('page:home/primary', $groups[0]->reference);
210-
$this->assertSame('primary', $groups[0]->location);
214+
$this->assertSame('primary_/_api/_/pages/test-uuid', $groups[0]->reference);
215+
$this->assertSame('/_api/_/pages/test-uuid', $groups[0]->location);
211216
$this->assertNull($groups[0]->allowedComponents);
212217

213218
$this->assertCount(1, $pages);

0 commit comments

Comments
 (0)