diff --git a/src/Module/NodeInfo210.php b/src/Module/NodeInfo210.php index a354046254..7501f26c08 100644 --- a/src/Module/NodeInfo210.php +++ b/src/Module/NodeInfo210.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\App; use Friendica\BaseModule; +use Friendica\Capabilities\IRespondToRequests; use Friendica\Core\Addon; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; @@ -88,6 +89,7 @@ class NodeInfo210 extends BaseModule $nodeinfo['services']['inbound'][] = 'imap'; } - System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + $this->response->setType(IRespondToRequests::TYPE_JSON, 'application/json; charset=utf-8'); + $this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } } diff --git a/tests/src/Module/NodeInfoTest.php b/tests/src/Module/NodeInfoTest.php new file mode 100644 index 0000000000..3464d7729f --- /dev/null +++ b/tests/src/Module/NodeInfoTest.php @@ -0,0 +1,84 @@ +run(); + + self::assertEquals(IRespondToRequests::TYPE_JSON, $response->getType()); + self::assertJson($response->getContent()); + self::assertEquals(['Content-type' => 'application/json'], $response->getHeaders()); + + $json = json_decode($response->getContent()); + + self::assertEquals('1.0', $json->version); + + self::assertEquals('friendica', $json->software->name); + self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->software->version); + + self::assertIsArray($json->protocols->inbound); + self::assertIsArray($json->protocols->outbound); + self::assertIsArray($json->services->inbound); + self::assertIsArray($json->services->outbound); + } + + public function testNodeInfo120() + { + $response = new Response(); + + $nodeinfo = new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []); + $response = $nodeinfo->run(); + + self::assertEquals(IRespondToRequests::TYPE_JSON, $response->getType()); + self::assertJson($response->getContent()); + self::assertEquals(['Content-type' => 'application/json; charset=utf-8'], $response->getHeaders()); + + $json = json_decode($response->getContent()); + + self::assertEquals('2.0', $json->version); + + self::assertEquals('friendica', $json->software->name); + self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->software->version); + + self::assertIsArray($json->protocols); + self::assertIsArray($json->services->inbound); + self::assertIsArray($json->services->outbound); + } + + public function testNodeInfo210() + { + $response = new Response(); + + $nodeinfo = new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []); + $response = $nodeinfo->run(); + + self::assertEquals(IRespondToRequests::TYPE_JSON, $response->getType()); + self::assertJson($response->getContent()); + self::assertEquals(['Content-type' => 'application/json; charset=utf-8'], $response->getHeaders()); + + $json = json_decode($response->getContent()); + + self::assertEquals('1.0', $json->version); + + self::assertEquals('friendica', $json->server->software); + self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->server->version); + + self::assertIsArray($json->protocols); + self::assertIsArray($json->services->inbound); + self::assertIsArray($json->services->outbound); + } +}