]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/NodeInfoTest.php
Just commit config transactions if something changed
[friendica.git] / tests / src / Module / NodeInfoTest.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;
23
24 use Friendica\App;
25 use Friendica\Capabilities\ICanCreateResponses;
26 use Friendica\DI;
27 use Friendica\Module\NodeInfo110;
28 use Friendica\Module\NodeInfo120;
29 use Friendica\Module\NodeInfo210;
30 use Friendica\Module\Special\HTTPException;
31 use Friendica\Test\FixtureTest;
32 use Mockery\MockInterface;
33
34 class NodeInfoTest extends FixtureTest
35 {
36         /** @var MockInterface|HTTPException */
37         protected $httpExceptionMock;
38
39         protected function setUp(): void
40         {
41                 parent::setUp();
42
43                 $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
44         }
45
46         public function testNodeInfo110()
47         {
48                 $response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
49                         ->run($this->httpExceptionMock);
50
51                 self::assertJson($response->getBody());
52                 self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
53
54                 $json = json_decode($response->getBody());
55
56                 self::assertEquals('1.0', $json->version);
57
58                 self::assertEquals('friendica', $json->software->name);
59                 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
60
61                 self::assertIsArray($json->protocols->inbound);
62                 self::assertIsArray($json->protocols->outbound);
63                 self::assertIsArray($json->services->inbound);
64                 self::assertIsArray($json->services->outbound);
65         }
66
67         public function testNodeInfo120()
68         {
69                 $response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
70                         ->run($this->httpExceptionMock);
71
72                 self::assertJson($response->getBody());
73                 self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
74
75                 $json = json_decode($response->getBody());
76
77                 self::assertEquals('2.0', $json->version);
78
79                 self::assertEquals('friendica', $json->software->name);
80                 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
81
82                 self::assertIsArray($json->protocols);
83                 self::assertIsArray($json->services->inbound);
84                 self::assertIsArray($json->services->outbound);
85         }
86
87         public function testNodeInfo210()
88         {
89                 $response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
90                         ->run($this->httpExceptionMock);
91
92                 self::assertJson($response->getBody());
93                 self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
94
95                 $json = json_decode($response->getBody());
96
97                 self::assertEquals('1.0', $json->version);
98
99                 self::assertEquals('friendica', $json->server->software);
100                 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->server->version);
101
102                 self::assertIsArray($json->protocols);
103                 self::assertIsArray($json->services->inbound);
104                 self::assertIsArray($json->services->outbound);
105         }
106 }