-
-
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
Conversation
cf40f54
to
8264f9d
Compare
return $this->sharedBlockAdmin->getFormContractor()->getFormBuilder( | ||
$this->sharedBlockAdmin->getUniqId(), | ||
['data_class' => $this->sharedBlockAdmin->getClass()] | ||
)->create('blockId', ModelListType::class, [ |
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:
- Field description didn't had association admin, and it break on a template from sonataAdmin, fixed line 157.
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:
- Some of our bundles define blocks (and they do require block bundle) 👍
- Some of that blocks are EditableBlocks (an interface defined on block bundle) 👍
- That interface is only testable HERE, because those editableBlocks are for SonataPageBundle 👎
- When we move for example SonataMediaBundle from 3.x to 4.x we migrated those blocks to newer SonataBlock version, but we didn't test those because of point 3. (and we didn't try to unit test AFAIK, will need to check) 👎
- Now that we are migrating this bundle, some errors appear.
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.
It should work with second commit, but the solution I don't like it a lot, AND I need to add more test because other kind of blocks are broken too. Edit: nice it works on my computer, but not on github actions, for some reason, will need to take a deeper look. |
You have a great computer :p |
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
And this PR: sonata-project/SonataBlockBundle#1098
'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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
To fix this we will need to BC break, but it should be accepted IMO, because that block is completely unusable.
Yeah, I agree
we can create an issue or something.
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 comment
The 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.
Create an issue to check it's fine!
But this breadcrumb menu
is a bit trick! I'm still struggling with this in #1497 😢
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.
One for this: sonata-project/SonataSeoBundle#685
f2e516e
to
eb43569
Compare
'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 comment
The 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 comment
The 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...
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be fix ?
'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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be fix ?
return $this->sharedBlockAdmin->getFormContractor()->getFormBuilder( | ||
$this->sharedBlockAdmin->getUniqId(), | ||
['data_class' => $this->sharedBlockAdmin->getClass()] | ||
)->create('blockId', ModelListType::class, [ |
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 ?
$this->sharedBlockAdmin->getUniqId(), | ||
['data_class' => $this->sharedBlockAdmin->getClass()] | ||
)->create('blockId', ModelListType::class, [ | ||
\assert($form instanceof AdminFormMapper); |
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.
I don't like the assert here.
Nothing is preventing
configureEditForm
to be called with another FormMapper.
I would change this too
private function getBlockBuilder(AdminFormMapper $form): FormBuilderInterface
and
public function configureEditForm(FormMapper $form, BlockInterface $block): void
{
if (!$form instanceof AdminFormMapper) {
throw new \InvalidArgumentException();
}
(And we can consider later to make the EditableBlockService generics)
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 do you think now?
a02dce0
to
bdde78e
Compare
Subject
There are a ton of errors to fix :)