]> git.mxchange.org Git - friendica.git/commitdiff
Add NodeInfo Module test as an example
authorPhilipp <admin@philipp.info>
Sun, 21 Nov 2021 21:07:23 +0000 (22:07 +0100)
committerPhilipp <admin@philipp.info>
Sat, 27 Nov 2021 11:40:56 +0000 (12:40 +0100)
src/Module/NodeInfo210.php
tests/src/Module/NodeInfoTest.php [new file with mode: 0644]

index a354046254d5394127a411135a3d5bc1c3107de8..7501f26c083e8c711d6d649da953616504d648f2 100644 (file)
@@ -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 (file)
index 0000000..3464d77
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+namespace Friendica\Test\src\Module;
+
+use Friendica\Capabilities\IRespondToRequests;
+use Friendica\DI;
+use Friendica\Module\NodeInfo110;
+use Friendica\Module\NodeInfo120;
+use Friendica\Module\NodeInfo210;
+use Friendica\Module\Response;
+use Friendica\Test\FixtureTest;
+
+class NodeInfoTest extends FixtureTest
+{
+       public function testNodeInfo110()
+       {
+               $response = new Response();
+
+               $nodeinfo = new NodeInfo110(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'], $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);
+       }
+}