Skip to content
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

Merged

Conversation

jordisala1991
Copy link
Member

@jordisala1991 jordisala1991 commented Aug 11, 2022

Subject

There are a ton of errors to fix :)

@jordisala1991 jordisala1991 force-pushed the hotfix/more-crud-form-tests branch from cf40f54 to 8264f9d Compare August 11, 2022 20:09
return $this->sharedBlockAdmin->getFormContractor()->getFormBuilder(
$this->sharedBlockAdmin->getUniqId(),
['data_class' => $this->sharedBlockAdmin->getClass()]
)->create('blockId', ModelListType::class, [
Copy link
Member Author

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:

  1. Field description didn't had association admin, and it break on a template from sonataAdmin, fixed line 157.
  2. 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.

Copy link
Member

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is:

  1. Some of our bundles define blocks (and they do require block bundle) 👍
  2. Some of that blocks are EditableBlocks (an interface defined on block bundle) 👍
  3. That interface is only testable HERE, because those editableBlocks are for SonataPageBundle 👎
  4. 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) 👎
  5. 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.

Copy link
Member Author

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.

@jordisala1991
Copy link
Member Author

jordisala1991 commented Aug 11, 2022

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.

@VincentLanglet
Copy link
Member

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', [
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Can it be fix ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

'shared_block[settings][class]' => 'custom_class',
]];

// yield 'Create Shared Block - Breadcrumb' => ['/admin/tests/app/sonatapageblock/shared/create', [
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Can it be fix ?

Copy link
Member Author

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:

2.x: https://github.com/sonata-project/SonataSeoBundle/blob/2.x/src/Block/Breadcrumb/BaseBreadcrumbMenuBlockService.php#L29

Here the class extends MenuBlockService which implements EditableBlockService 👍

3.x: https://github.com/sonata-project/SonataSeoBundle/blob/3.x/src/Block/Breadcrumb/BaseBreadcrumbMenuBlockService.php#L29

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Contributor

@eerison eerison Aug 12, 2022

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 😢

Copy link
Member Author

Choose a reason for hiding this comment

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

@jordisala1991 jordisala1991 marked this pull request as ready for review August 12, 2022 07:18
@jordisala1991 jordisala1991 force-pushed the hotfix/more-crud-form-tests branch from f2e516e to eb43569 Compare August 12, 2022 07:26
'shared_block[settings][translation_domain]' => 'SonataPageBundle',
'shared_block[settings][icon]' => 'fa fa-home',
'shared_block[settings][current]' => 1,
// 'shared_block[settings][pageId]' => 1,
Copy link
Member

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 ?

Copy link
Member Author

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', [
Copy link
Member

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', [
Copy link
Member

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, [
Copy link
Member

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);
Copy link
Member

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)

Copy link
Member Author

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?

@jordisala1991 jordisala1991 force-pushed the hotfix/more-crud-form-tests branch from a02dce0 to bdde78e Compare August 12, 2022 08:15
@jordisala1991 jordisala1991 merged commit 6304bc8 into sonata-project:4.x Aug 12, 2022
@jordisala1991 jordisala1991 deleted the hotfix/more-crud-form-tests branch August 12, 2022 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants