2022-01-02 20:28:28 +00:00
|
|
|
<?php
|
2022-01-06 20:54:40 +00:00
|
|
|
/**
|
2022-01-06 22:08:00 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2022-01-06 20:54:40 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2022-01-02 20:28:28 +00:00
|
|
|
|
|
|
|
namespace Friendica\Test\src\Module\Special;
|
|
|
|
|
|
|
|
use Friendica\App\Router;
|
|
|
|
use Friendica\Capabilities\ICanCreateResponses;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Module\Special\Options;
|
|
|
|
use Friendica\Test\FixtureTest;
|
|
|
|
|
|
|
|
class OptionsTest extends FixtureTest
|
|
|
|
{
|
2022-01-03 18:19:47 +00:00
|
|
|
public function testOptionsAll()
|
2022-01-02 20:28:28 +00:00
|
|
|
{
|
2022-01-02 21:51:16 +00:00
|
|
|
$this->useHttpMethod(Router::OPTIONS);
|
|
|
|
|
|
|
|
$response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run();
|
2022-01-02 20:28:28 +00:00
|
|
|
|
|
|
|
self::assertEmpty((string)$response->getBody());
|
|
|
|
self::assertEquals(204, $response->getStatusCode());
|
|
|
|
self::assertEquals('No Content', $response->getReasonPhrase());
|
|
|
|
self::assertEquals([
|
|
|
|
'Allow' => [implode(',', Router::ALLOWED_METHODS)],
|
2022-01-03 18:55:47 +00:00
|
|
|
ICanCreateResponses::X_HEADER => ['blank'],
|
2022-01-02 20:28:28 +00:00
|
|
|
], $response->getHeaders());
|
|
|
|
self::assertEquals(implode(',', Router::ALLOWED_METHODS), $response->getHeaderLine('Allow'));
|
|
|
|
}
|
2022-01-03 18:19:47 +00:00
|
|
|
|
|
|
|
public function testOptionsSpecific()
|
|
|
|
{
|
|
|
|
$this->useHttpMethod(Router::OPTIONS);
|
|
|
|
|
|
|
|
$response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
|
|
|
|
'AllowedMethods' => [Router::GET, Router::POST],
|
|
|
|
]))->run();
|
|
|
|
|
|
|
|
self::assertEmpty((string)$response->getBody());
|
|
|
|
self::assertEquals(204, $response->getStatusCode());
|
|
|
|
self::assertEquals('No Content', $response->getReasonPhrase());
|
|
|
|
self::assertEquals([
|
|
|
|
'Allow' => [implode(',', [Router::GET, Router::POST])],
|
2022-01-03 18:55:47 +00:00
|
|
|
ICanCreateResponses::X_HEADER => ['blank'],
|
2022-01-03 18:19:47 +00:00
|
|
|
], $response->getHeaders());
|
|
|
|
self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow'));
|
|
|
|
}
|
2022-01-02 20:28:28 +00:00
|
|
|
}
|