Skip to content

Commit

Permalink
Fix silverstripe#11087: Improve handling of nonexistent actions in de…
Browse files Browse the repository at this point in the history
…legateToMultipleHandlers

This commit addresses issue silverstripe#11087 by enhancing the error handling in the delegateToMultipleHandlers method of the Security class. Previously, attempting a nonexistent action would generate a generic warning. With this modification, the method now checks for the presence of an HTTPResponse in the results array and returns it directly, providing a more informative error message.
  • Loading branch information
martin-lechene committed Dec 13, 2023
1 parent c714599 commit be17c09
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/php/Security/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
Expand Down Expand Up @@ -820,4 +821,30 @@ protected function getValidationResult()
}
return null;
}


/**
* Test for DelegateToMultipleHandlers() in Security.php
* @return void
*/
protected function testDelegateToMultipleHandlers()
{
$security = new Security(); // Assurez-vous d'adapter le namespace et la classe selon votre projet
$handler1 = $this->getMockBuilder(RequestHandler::class)->getMock();
$handler2 = $this->getMockBuilder(RequestHandler::class)->getMock();

// Simulation of HTTPResponse
$handler2->expects($this->once())
->method('handleRequest')
->willReturn(new HTTPResponse('This is an HTTPResponse', 404));

$result = $security->delegateToMultipleHandlers([$handler1, $handler2], 'Test Title', ['template'], function ($results) {
return 'Aggregated Result';
});

$this->assertInstanceOf(HTTPResponse::class, $result);
$this->assertEquals('This is an HTTPResponse', $result->getBody());
$this->assertEquals(404, $result->getStatusCode());
}

}

0 comments on commit be17c09

Please sign in to comment.