Skip to content

Commit

Permalink
[Live] Fix BatchActionController redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
6insanes authored and weaverryan committed Dec 1, 2023
1 parent 7989f27 commit 4f75d06
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ public function onKernelResponse(ResponseEvent $event): void
$request = $event->getRequest();
$response = $event->getResponse();

if (!$event->isMainRequest()) {
return;
}

if (!$this->isLiveComponentRequest($request)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,40 @@ public function testRedirect(): void
;
}

public function testRedirectWithAcceptHeader(): void
{
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_actions'));

$this->browser()
->throwExceptions()
->get('/_components/with_actions', ['query' => ['props' => json_encode($dehydrated->getProps())]])
->assertSuccessful()
->interceptRedirects()
->use(function (Crawler $crawler, KernelBrowser $browser) {
$rootElement = $crawler->filter('ul')->first();
$liveProps = json_decode($rootElement->attr('data-live-props-value'), true);

$browser->post('/_components/with_actions/_batch', [
'body' => [
'data' => json_encode([
'props' => $liveProps,
'actions' => [
['name' => 'redirect'],
['name' => 'exception'],
],
]),
],
'headers' => [
'Accept' => ['application/vnd.live-component+html'],
'X-CSRF-TOKEN' => $crawler->filter('ul')->first()->attr('data-live-csrf-value'),
],
]);
})
->assertStatus(204)
->assertHeaderContains('X-Live-Redirect', '1')
;
}

public function testException(): void
{
$dehydrated = $this->dehydrateComponent($this->mountComponent('with_actions'));
Expand Down

0 comments on commit 4f75d06

Please sign in to comment.