mirror of
https://github.com/friendica/friendica
synced 2024-12-23 00:40:15 +00:00
Add NodeInfo Module test as an example
This commit is contained in:
parent
537b74f307
commit
78c45bd142
2 changed files with 87 additions and 1 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
84
tests/src/Module/NodeInfoTest.php
Normal file
84
tests/src/Module/NodeInfoTest.php
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue