3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Module\Special;
24 use Friendica\App\Router;
25 use Friendica\Capabilities\ICanCreateResponses;
27 use Friendica\Module\Special\HTTPException;
28 use Friendica\Module\Special\Options;
29 use Friendica\Test\FixtureTest;
30 use Mockery\MockInterface;
32 class OptionsTest extends FixtureTest
34 /** @var MockInterface|HTTPException */
35 protected $httpExceptionMock;
37 protected function setUp(): void
41 $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
44 public function testOptionsAll()
46 $this->useHttpMethod(Router::OPTIONS);
48 $response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run($this->httpExceptionMock);
50 self::assertEmpty((string)$response->getBody());
51 self::assertEquals(204, $response->getStatusCode());
52 self::assertEquals('No Content', $response->getReasonPhrase());
54 'Allow' => [implode(',', Router::ALLOWED_METHODS)],
55 ICanCreateResponses::X_HEADER => ['blank'],
56 ], $response->getHeaders());
57 self::assertEquals(implode(',', Router::ALLOWED_METHODS), $response->getHeaderLine('Allow'));
60 public function testOptionsSpecific()
62 $this->useHttpMethod(Router::OPTIONS);
64 $response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
65 'AllowedMethods' => [Router::GET, Router::POST],
66 ]))->run($this->httpExceptionMock);
68 self::assertEmpty((string)$response->getBody());
69 self::assertEquals(204, $response->getStatusCode());
70 self::assertEquals('No Content', $response->getReasonPhrase());
72 'Allow' => [implode(',', [Router::GET, Router::POST])],
73 ICanCreateResponses::X_HEADER => ['blank'],
74 ], $response->getHeaders());
75 self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow'));