Tips for testing Wizard Steps?
How do you test a Wizard? Obviously you would need to be able to test validation at the step level and then a submit overall as well. Didn't see anything documented or really mentioned in discord lately either.
8 Replies
I know it's been a while, but I just ran into this same problem. What I ended up doing, at least for testing validation is to call my final submit call that does the validation (
$this->form->getState();
)
Then I just stick to normal ->assertHasFormErrors(['name' => 'required']);
style tests. I.e.,
I see the per-step issue will be next for me to figure out. Will report back if I find anything interesting. 🙂
- Wizard Tests
The wizard doesn't seem to matter too much when testing individual fields. As long as you're being specific you can test anywhere it seems. Just test as if all of the fields are on the same page.
When you are ready to test the entire form, just fillForm() completely to ensure it will succeed. Otherwise stick to specific fields like in my example above. Other fields will be throwing errors all over the place of course, but when you target with ['field' => 'validation_type'] you're isolating what is being tested.Yep, per step is the only issue
have you been able to find any solution for this?
I think you ahve to simply ->call('next') or something like that
have tried it. call('next') tries to find the method in the page itself.
I have a 3 step wizard I was testing and I think I just ended up testing as if it was a single form. Maybe I have a different level of complexity, but looking over my tests I don't think I ended up doing anything special, just treating it as a standard long form.
right, but a key part of wizard validation would be testing at each step. Could be able to get to step 2 until step 1 validates
I am talking about this scenerio as well