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;
25 use Friendica\Capabilities\ICanCreateResponses;
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;
34 class NodeInfoTest extends FixtureTest
36 /** @var MockInterface|HTTPException */
37 protected $httpExceptionMock;
39 protected function setUp(): void
43 $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
46 public function testNodeInfo110()
48 $response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
49 ->run($this->httpExceptionMock);
51 self::assertJson($response->getBody());
52 self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
54 $json = json_decode($response->getBody());
56 self::assertEquals('1.0', $json->version);
58 self::assertEquals('friendica', $json->software->name);
59 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
61 self::assertIsArray($json->protocols->inbound);
62 self::assertIsArray($json->protocols->outbound);
63 self::assertIsArray($json->services->inbound);
64 self::assertIsArray($json->services->outbound);
67 public function testNodeInfo120()
69 $response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
70 ->run($this->httpExceptionMock);
72 self::assertJson($response->getBody());
73 self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
75 $json = json_decode($response->getBody());
77 self::assertEquals('2.0', $json->version);
79 self::assertEquals('friendica', $json->software->name);
80 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
82 self::assertIsArray($json->protocols);
83 self::assertIsArray($json->services->inbound);
84 self::assertIsArray($json->services->outbound);
87 public function testNodeInfo210()
89 $response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
90 ->run($this->httpExceptionMock);
92 self::assertJson($response->getBody());
93 self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
95 $json = json_decode($response->getBody());
97 self::assertEquals('1.0', $json->version);
99 self::assertEquals('friendica', $json->server->software);
100 self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->server->version);
102 self::assertIsArray($json->protocols);
103 self::assertIsArray($json->services->inbound);
104 self::assertIsArray($json->services->outbound);