2016-03-24 09:29:55 -04:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
declare(strict_types=1);
|
2016-03-24 09:29:55 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-03-24 09:29:55 -04:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\DAV;
|
2016-03-24 09:29:55 -04:00
|
|
|
|
2024-10-30 07:25:26 -04:00
|
|
|
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
2025-05-27 17:36:08 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-03-24 09:29:55 -04:00
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2017-10-24 18:03:28 -04:00
|
|
|
use Sabre\HTTP\Response;
|
2016-03-24 09:29:55 -04:00
|
|
|
|
2024-10-30 07:25:26 -04:00
|
|
|
class BrowserErrorPagePluginTest extends \Test\TestCase {
|
2016-03-24 09:29:55 -04:00
|
|
|
|
2026-01-07 08:21:48 -05:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'providesExceptions')]
|
2025-05-27 17:36:08 -04:00
|
|
|
public function test(int $expectedCode, \Throwable $exception): void {
|
|
|
|
|
/** @var BrowserErrorPagePlugin&MockObject $plugin */
|
|
|
|
|
$plugin = $this->getMockBuilder(BrowserErrorPagePlugin::class)->onlyMethods(['sendResponse', 'generateBody'])->getMock();
|
2016-03-24 09:29:55 -04:00
|
|
|
$plugin->expects($this->once())->method('generateBody')->willReturn(':boom:');
|
|
|
|
|
$plugin->expects($this->once())->method('sendResponse');
|
2025-05-27 17:36:08 -04:00
|
|
|
/** @var \Sabre\DAV\Server&MockObject $server */
|
|
|
|
|
$server = $this->createMock('Sabre\DAV\Server');
|
2016-03-24 09:29:55 -04:00
|
|
|
$server->expects($this->once())->method('on');
|
2025-05-27 17:36:08 -04:00
|
|
|
$httpResponse = $this->createMock(Response::class);
|
2016-03-24 09:29:55 -04:00
|
|
|
$httpResponse->expects($this->once())->method('addHeaders');
|
|
|
|
|
$httpResponse->expects($this->once())->method('setStatus')->with($expectedCode);
|
|
|
|
|
$httpResponse->expects($this->once())->method('setBody')->with(':boom:');
|
|
|
|
|
$server->httpResponse = $httpResponse;
|
|
|
|
|
$plugin->initialize($server);
|
|
|
|
|
$plugin->logException($exception);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
public static function providesExceptions(): array {
|
2016-03-24 09:29:55 -04:00
|
|
|
return [
|
|
|
|
|
[ 404, new NotFound()],
|
|
|
|
|
[ 500, new \RuntimeException()],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|