Skip to content

[Testing] CollectionType file upload #10809

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

Closed
wants to merge 4 commits into from
Closed

Conversation

Guikingone
Copy link
Contributor

Hi everyone,

Recently, I've been blocked by a CollectionType which define a child form (using VichUploaderBundle but the logic stay the same for default FileType), I wasn't able to test it during functional tests, I've found a way to do it and I think it can a good idea to improve the doc in order to explain how to do it.

Thanks for the feedback 😊

PS: Some work must be done in the sentences

@Guikingone Guikingone changed the title [TESTING] CollectionType file upload [Testing] CollectionType file upload Dec 27, 2018

namespace App\Form;

use App\Entity\Entity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Entity\Entity - I think it's bag example. You can use User or Task or another entity used in other documentation articles.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about App\Entity\Album with a pictures property?

if no data are passed by default, sometimes, you need to upload multiple files (using this CollectionType),
keeping in mind this logic, it can be hard to handle the upload.

Let's imagine a simple form which define a collection of FileType::
Copy link
Contributor

Choose a reason for hiding this comment

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

defines

}
}

Testing this type can be hard as explained earlier, trying to use UploadedFile isn't possible
Copy link
Contributor

Choose a reason for hiding this comment

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

can be hard ... isn't possible - to many restrictions, I think.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

@Guikingone thanks for this contribution. Before reviewing it I wonder if we could solve the underlying problem instead of documenting it. Specifically, can we solve this in some way?

By default, a CollectionType isn't available in the form
during functional tests if no data are passed by default.

Ping @HeahDude. Thanks!

@Guikingone
Copy link
Contributor Author

@javiereguiluz I think it can be solved (maybe via a default_entry option in the CollectionType which generate a default entry in the FormView, as far as I've seen from here, I'm not sure about the implementation but @HeahDude can easily help us to see if it's a lack of documentation or a missing feature :)

@Guikingone
Copy link
Contributor Author

@javiereguiluz After discussing this PR with @HeahDude, it's not a bug, it's more a special case I was blocked by, if it's not a problem for you, I can keep this PR in order to improve the documentation for the usage of $_FILES when using Client, I can work on this improvement this week-end :)

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thanks @Guikingone for opening that PR. But wouldn't it be some kind of duplicate of #10527.


namespace App\Form;

use App\Entity\Entity;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about App\Entity\Album with a pictures property?

use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FileType;

class DefaultUploadType extends AbstractType
Copy link
Contributor

Choose a reason for hiding this comment

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

That would make it a GalleryType


public function getBlockPrefix()
{
return 'some_type';
Copy link
Contributor

Choose a reason for hiding this comment

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

and this app_gallery

@HeahDude HeahDude added this to the 3.4 milestone Feb 7, 2020
@Guikingone
Copy link
Contributor Author

I'll take a look at the linked PR and see if it worth the work to improve this one 🙂

@wouterj
Copy link
Member

wouterj commented Oct 3, 2020

Hi @Guikingone!

#10527 (the other PR) was just closed, based on @xabbuh's comment: "IMO when your functional test requires JavaScript to be executed you should use a real browser in the background (for example using Panther) instead."

It seems like the solution proposed in this PR is just as fragile as the solution in the other PR (i.e. it relies on implementation details of the Form component that are not under the control of the application). Do you agree with this conclusion? And if you don't, do you have time to further work on this PR?
The alternative outcome would be to create an issue to add some docs on how to use Panther to test collection form types I think.

@Guikingone
Copy link
Contributor Author

Hi @wouterj 👋

Yes, I agree with this conclusion, with time, I agree that every time that you need to test a JS-dependant interface, you should use tools like Panther, Cypress, etc, the default Bridge is great but not enough for advanced use cases.

As discussed with @javiereguiluz, I also think that the documentation need to add pages about using Panther (maybe in the Testing category?) in order to explain how to use/install it in a Symfony project and test specific use cases (CollectionType's could be part of this refactoring IMO).

So 👍 for me on your proposal.

@wouterj wouterj mentioned this pull request Oct 16, 2020
@wouterj
Copy link
Member

wouterj commented Oct 16, 2020

Alright, I've reopened #12200 (an issue of yours 😄 ) and will close this one then.

Thanks for your reply!

@wouterj wouterj closed this Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants