-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
[LiveComponent] Testing combining user login and actions is not working as expected #2338
Comments
I'm getting rid of the error when adding the following configuration globally: when@test:
framework:
csrf_protection: false But I still have issues with the |
Same thing if you call actingAs() before any actions (render, setter, ..)? $testComponent = $this->createLiveComponent(
name: 'MyAwesomeComponent',
data: ['hotel' => $repository->find(1)],
);
- $this->assertStringContainsString('Select a contract model', $testComponent->render());
- $testComponent->set('contractModel', 2);
// askForDocument is protected and requires special rights
$testComponent->actingAs($adminUser->_real(), 'admin');
+ $testComponent->render(); |
@smnandre indeed my actingAs was in the wrong place (it was not obvious because of project-related issues). No issue here. The CSRF token generation failing is however a thing. I tried to render before my call and it still do not work (without my trick). Also I notice the document seems to stand something wrong about CSRF being disabled in test env.
|
How would you rearrange the documentation to make this more explicit ?
Arf indeed... it will be released in the next version (mid/late november). You can test it pulling the "2.x-dev" branch if you want. We do not have versioning for documentation so it has been deployed a bit early, sorry for that. |
Nothing to be done here! (except more than a class for the testing section maybe 😉 , but it's good enough yet)
Okkkkkk. That explains a lot 😅 . I guess the release will fix this issue then. |
I'm testing my component, and the test looks like this:
I assume the CSRF protection emulation for tests (in the
TestLiveComponent::request()
) does not work as expected. It makes sense because here is what's happening under the hood:It's somehow connected to #1150
Notice: No, I cannot set the user in the first statement of the test because the session is not kept during the process, a way to fix this issue may be to keep it.
The text was updated successfully, but these errors were encountered: