]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Module/NodeInfoTest.php
spelling: cached
[friendica.git] / tests / src / Module / NodeInfoTest.php
index 3464d7729f7d0595fcb8b3fd80fb3ac6faedadd6..96790b5a91ccf1b7774ea680f941366104497875 100644 (file)
@@ -1,34 +1,62 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Test\src\Module;
 
-use Friendica\Capabilities\IRespondToRequests;
+use Friendica\App;
+use Friendica\Capabilities\ICanCreateResponses;
 use Friendica\DI;
 use Friendica\Module\NodeInfo110;
 use Friendica\Module\NodeInfo120;
 use Friendica\Module\NodeInfo210;
-use Friendica\Module\Response;
+use Friendica\Module\Special\HTTPException;
 use Friendica\Test\FixtureTest;
+use Mockery\MockInterface;
 
 class NodeInfoTest extends FixtureTest
 {
-       public function testNodeInfo110()
+       /** @var MockInterface|HTTPException */
+       protected $httpExceptionMock;
+
+       protected function setUp(): void
        {
-               $response = new Response();
+               parent::setUp();
+
+               $this->httpExceptionMock = \Mockery::mock(HTTPException::class);
+       }
 
-               $nodeinfo = new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []);
-               $response = $nodeinfo->run();
+       public function testNodeInfo110()
+       {
+               $response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
+                       ->run($this->httpExceptionMock);
 
-               self::assertEquals(IRespondToRequests::TYPE_JSON, $response->getType());
-               self::assertJson($response->getContent());
-               self::assertEquals(['Content-type' => 'application/json'], $response->getHeaders());
+               self::assertJson($response->getBody());
+               self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
 
-               $json = json_decode($response->getContent());
+               $json = json_decode($response->getBody());
 
                self::assertEquals('1.0', $json->version);
 
                self::assertEquals('friendica', $json->software->name);
-               self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
+               self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
 
                self::assertIsArray($json->protocols->inbound);
                self::assertIsArray($json->protocols->outbound);
@@ -38,21 +66,18 @@ class NodeInfoTest extends FixtureTest
 
        public function testNodeInfo120()
        {
-               $response = new Response();
+               $response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
+                       ->run($this->httpExceptionMock);
 
-               $nodeinfo = new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []);
-               $response = $nodeinfo->run();
+               self::assertJson($response->getBody());
+               self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
 
-               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());
+               $json = json_decode($response->getBody());
 
                self::assertEquals('2.0', $json->version);
 
                self::assertEquals('friendica', $json->software->name);
-               self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
+               self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->software->version);
 
                self::assertIsArray($json->protocols);
                self::assertIsArray($json->services->inbound);
@@ -61,21 +86,18 @@ class NodeInfoTest extends FixtureTest
 
        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();
+               $response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), []))
+                       ->run($this->httpExceptionMock);
 
-               self::assertEquals(IRespondToRequests::TYPE_JSON, $response->getType());
-               self::assertJson($response->getContent());
-               self::assertEquals(['Content-type' => 'application/json; charset=utf-8'], $response->getHeaders());
+               self::assertJson($response->getBody());
+               self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());
 
-               $json = json_decode($response->getContent());
+               $json = json_decode($response->getBody());
 
                self::assertEquals('1.0', $json->version);
 
                self::assertEquals('friendica', $json->server->software);
-               self::assertEquals(FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, $json->server->version);
+               self::assertEquals(App::VERSION . '-' . DB_UPDATE_VERSION, $json->server->version);
 
                self::assertIsArray($json->protocols);
                self::assertIsArray($json->services->inbound);