Skip to content

Commit 846a2f3

Browse files
committed
minor #7579 Add regression test for CollectionField::renderExpanded() on nested CRUD forms (lacatoire)
This PR was merged into the 5.x branch. Discussion ---------- Add regression test for CollectionField::renderExpanded() on nested CRUD forms Following issue #7529, I wasn't able to reproduce the bug on current `5.x`: `renderExpanded(true)` does propagate to the accordion (the `show` class lands on `.accordion-collapse` and `collapsed` is stripped from `.accordion-button`). This PR adds a functional test pinning that behaviour so we catch any future regression. Happy to extend the coverage or dig further if you can share a reproducer that still fails, I may have missed a specific setup. Fixes #7529 Commits ------- aec3d5a add regression test covering CollectionField renderExpanded on nested CRUD forms
2 parents d2a308d + aec3d5a commit 846a2f3

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

tests/Functional/Apps/DefaultApp/src/Controller/NestedCrudForm/ProjectWithNestedIssuesCrudController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function configureFields(string $pageName): iterable
3636
// ProjectIssueNestedCrudController. This controller accesses $context->getEntity()
3737
// in its configureFields(), which tests the bug fix
3838
yield CollectionField::new('projectIssues', 'Issues')
39+
->renderExpanded(true)
3940
->useEntryCrudForm(ProjectIssueNestedCrudController::class);
4041
}
4142
}

tests/Functional/Fields/Collection/NestedCrudFormTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,39 @@ public function testEditFormLoadsWithNestedCrudForm(): void
8686
static::assertStringContainsString('Test Issue 2', $html, 'Second issue should be visible');
8787
}
8888

89+
/**
90+
* Tests that renderExpanded(true) on CollectionField renders entries with the
91+
* accordion already expanded (Bootstrap "show" class on the collapse wrapper and
92+
* no "collapsed" class on the toggle button).
93+
*/
94+
public function testRenderExpandedOnCollectionField(): void
95+
{
96+
$project = $this->createProjectWithIssues();
97+
98+
$crawler = $this->client->request('GET', $this->generateEditFormUrl($project->getId()));
99+
100+
static::assertResponseIsSuccessful();
101+
102+
$collapseWrappers = $crawler->filter('.field-collection .accordion-collapse');
103+
static::assertGreaterThan(0, $collapseWrappers->count(), 'At least one accordion-collapse wrapper should be rendered');
104+
105+
foreach ($collapseWrappers as $wrapper) {
106+
static::assertStringContainsString(
107+
'show',
108+
$wrapper->getAttribute('class'),
109+
'renderExpanded(true) should add the "show" class on .accordion-collapse',
110+
);
111+
}
112+
113+
foreach ($crawler->filter('.field-collection .accordion-button') as $button) {
114+
static::assertStringNotContainsString(
115+
'collapsed',
116+
$button->getAttribute('class'),
117+
'renderExpanded(true) should not add the "collapsed" class on .accordion-button',
118+
);
119+
}
120+
}
121+
89122
/**
90123
* Creates a Project with ProjectIssue entities for testing.
91124
*/

0 commit comments

Comments
 (0)