]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Special/OptionsTest.php
Merge pull request #12920 from annando/issue-12701
[friendica.git] / tests / src / Module / Special / OptionsTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Module\Special;
23
24 use Friendica\App\Router;
25 use Friendica\Capabilities\ICanCreateResponses;
26 use Friendica\DI;
27 use Friendica\Module\Special\HTTPException;
28 use Friendica\Module\Special\Options;
29 use Friendica\Test\FixtureTest;
30 use Mockery\MockInterface;
31
32 class OptionsTest extends FixtureTest
33 {
34         /** @var MockInterface|HTTPException */
35         protected $httpExceptionMock;
36
37         protected function setUp(): void
38         {
39                 parent::setUp();
40
41                 $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
42         }
43
44         public function testOptionsAll()
45         {
46                 $this->useHttpMethod(Router::OPTIONS);
47
48                 $response = (new Options(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))->run($this->httpExceptionMock);
49
50                 self::assertEmpty((string)$response->getBody());
51                 self::assertEquals(204, $response->getStatusCode());
52                 self::assertEquals('No Content', $response->getReasonPhrase());
53                 self::assertEquals([
54                         'Allow'                       => [implode(',', Router::ALLOWED_METHODS)],
55                         ICanCreateResponses::X_HEADER => ['blank'],
56                 ], $response->getHeaders());
57                 self::assertEquals(implode(',', Router::ALLOWED_METHODS), $response->getHeaderLine('Allow'));
58         }
59
60         public function testOptionsSpecific()
61         {
62                 $this->useHttpMethod(Router::OPTIONS);
63
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);
67
68                 self::assertEmpty((string)$response->getBody());
69                 self::assertEquals(204, $response->getStatusCode());
70                 self::assertEquals('No Content', $response->getReasonPhrase());
71                 self::assertEquals([
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'));
76         }
77 }