-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add more CRUD form tests #1552
Add more CRUD form tests #1552
Changes from 5 commits
8264f9d
d40cf30
9a48a2f
fcc9daa
28f87f0
eb43569
d922ffe
bdde78e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,151 @@ public function testCrudUrls(string $url, array $parameters = []): void | |
public static function provideCrudUrlsCases(): iterable | ||
{ | ||
yield 'List Block' => ['/admin/tests/app/sonatapageblock/shared/list']; | ||
yield 'Create Block' => ['/admin/tests/app/sonatapageblock/shared/create']; | ||
yield 'List Block types' => ['/admin/tests/app/sonatapageblock/shared/create']; | ||
|
||
yield 'Create Block' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'type' => 'sonata.page.block.shared_block', | ||
]]; | ||
|
||
yield 'Edit Block' => ['/admin/tests/app/sonatapageblock/shared/1/edit']; | ||
yield 'Remove Block' => ['/admin/tests/app/sonatapageblock/shared/1/delete']; | ||
} | ||
|
||
/** | ||
* @dataProvider provideFormUrlsCases | ||
* | ||
* @param array<string, mixed> $parameters | ||
* @param array<string, mixed> $fieldValues | ||
*/ | ||
public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void | ||
{ | ||
$client = self::createClient(); | ||
|
||
$this->prepareData(); | ||
|
||
$client->request('GET', $url, $parameters); | ||
$client->submitForm($button, $fieldValues); | ||
$client->followRedirect(); | ||
|
||
self::assertResponseIsSuccessful(); | ||
} | ||
|
||
/** | ||
* @return iterable<array<string|array<string, mixed>>> | ||
* | ||
* @phpstan-return iterable<array{0: string, 1: array<string, mixed>, 2: string, 3?: array<string, mixed>}> | ||
*/ | ||
public static function provideFormUrlsCases(): iterable | ||
{ | ||
// Blocks From SonataBlockBundle | ||
// yield 'Create Shared Block - Container' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is broken on SonataBlockBundle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be fix ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this PR: sonata-project/SonataBlockBundle#1098 |
||
// 'uniqid' => 'shared_block', | ||
// 'type' => 'sonata.block.service.container', | ||
// ], 'btn_create_and_list', [ | ||
// 'shared_block[name]' => 'Name', | ||
// 'shared_block[enabled]' => 1, | ||
// 'shared_block[settings][code]' => 'code', | ||
// 'shared_block[settings][layout]' => '{{ CONTENT }}', | ||
// 'shared_block[settings][class]' => 'custom_class', | ||
// 'shared_block[settings][template]' => '@SonataPage/Block/block_container.html.twig', | ||
// 'shared_block[children]' => '', | ||
// ]]; | ||
|
||
yield 'Create Shared Block - Text' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.block.service.text', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][content]' => 'Text', | ||
]]; | ||
|
||
yield 'Create Shared Block - Template' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.block.service.template', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][template]' => '@SonataBlock/Block/block_template.html.twig', | ||
]]; | ||
|
||
yield 'Create Shared Block - Menu' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.block.service.menu', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][title]' => 'Title', | ||
'shared_block[settings][menu_name]' => 'sonata_admin_sidebar', | ||
'shared_block[settings][safe_labels]' => 1, | ||
'shared_block[settings][current_class]' => 'active', | ||
'shared_block[settings][first_class]' => 'first', | ||
'shared_block[settings][last_class]' => 'last', | ||
'shared_block[settings][menu_class]' => 'menu_sonata', | ||
'shared_block[settings][children_class]' => 'children', | ||
'shared_block[settings][menu_template]' => '@SonataBlock/Block/block_core_menu.html.twig', | ||
]]; | ||
|
||
yield 'Create Shared Block - RSS' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.block.service.rss', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][url]' => 'https://sonata-project.org', | ||
'shared_block[settings][title]' => 'Title', | ||
'shared_block[settings][translation_domain]' => 'SonataPageBundle', | ||
'shared_block[settings][icon]' => 'fa fa-home', | ||
'shared_block[settings][class]' => 'custom_class', | ||
]]; | ||
|
||
// Blocks From SonataPageBundle | ||
yield 'Create Shared Block - Children Pages' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.page.block.children_pages', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][title]' => 'Title', | ||
'shared_block[settings][translation_domain]' => 'SonataPageBundle', | ||
'shared_block[settings][icon]' => 'fa fa-home', | ||
'shared_block[settings][current]' => 1, | ||
// 'shared_block[settings][pageId]' => 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove this line or uncomment it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a pageId on the settings, but not sure how to make it populate with pages, because it needs a page on the block. I leave it commented to not forget to think about it... |
||
'shared_block[settings][class]' => 'custom_class', | ||
]]; | ||
|
||
// yield 'Create Shared Block - Breadcrumb' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is broken on SonataSeoBundle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be fix ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is a bit problematic... Take a look at the class: Here the class extends MenuBlockService which implements EditableBlockService 👍 Here the class does not extend MenuBlockService, and does not implement EditableBlockService 👎 To fix this we will need to BC break, but it should be accepted IMO, because that block is completely unusable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe @eerison or other users of this bundle could help us with it. IMHO we should not block this PR for it, because it will need some thinking, we can create an issue or something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree
Can you create an issue with the list of things to fix then ? Then we'll merge this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Create an issue to check it's fine! But this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One for this: sonata-project/SonataSeoBundle#685 |
||
// 'uniqid' => 'shared_block', | ||
// 'type' => 'sonata.page.block.breadcrumb', | ||
// ], 'btn_create_and_list', [ | ||
// ]]; | ||
|
||
yield 'Create Shared Block - Shared Block' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.page.block.shared_block', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][blockId]' => 1, | ||
]]; | ||
|
||
yield 'Create Shared Block - Page List' => ['/admin/tests/app/sonatapageblock/shared/create', [ | ||
'uniqid' => 'shared_block', | ||
'type' => 'sonata.page.block.pagelist', | ||
], 'btn_create_and_list', [ | ||
'shared_block[name]' => 'Name', | ||
'shared_block[enabled]' => 1, | ||
'shared_block[settings][title]' => 'Title', | ||
'shared_block[settings][translation_domain]' => 'SonataPageBundle', | ||
'shared_block[settings][icon]' => 'fa fa-home', | ||
'shared_block[settings][class]' => 'custom_class', | ||
'shared_block[settings][mode]' => 'form.choice_public', | ||
]]; | ||
|
||
yield 'Edit Shared Block' => ['/admin/tests/app/sonatapageblock/shared/1/edit', [], 'btn_update_and_list', []]; | ||
yield 'Remove Shared Block' => ['/admin/tests/app/sonatapageblock/shared/1/delete', [], 'btn_delete']; | ||
} | ||
|
||
/** | ||
* @return class-string<KernelInterface> | ||
*/ | ||
|
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.
This kind of fix should be applied to other bundles. There is still a lot of code to write to do such fields.
There were 2 problems:
getFormBuilder
does a lot of things, it instantiate al the form for that admin, and it needs a subject, so it breaks. I picked the first lines where it creates de form builder. There are other options to fix this too. One of them is use the original $form from above, but we are wrapping it on a PageFormMapper (For no reason).IMO we might refactor this further, and remove PageFormMapper too, it is not needed.
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.
What's the issue ? And in which bundle should we apply the same fix ?
It was never reported before
I would say that PageFormMapper was maybe needed prior to sonata-project/SonataBlockBundle@cd2f8f3. But now the AdminFormMapper implements the BlockBundle FormMapper it's not needed.
Does removing this class (in this PR) would simplify your bugfix ?
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.
The problem is:
Those are other examples of the same problem:
https://github.com/sonata-project/SonataMediaBundle/blob/4.x/src/Block/MediaBlockService.php#L210-L226
I don't know if there are a lot of them (I think not), but this kind of dependencies are hard to test.
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.
Take a look at my last commit, not using PageFormMapper, allows to \assert for AdminFormMapper and we have getFormBuilder there.