]> git.mxchange.org Git - friendica.git/commitdiff
Move ApiResponse & Twitter Status tests
authorPhilipp <admin@philipp.info>
Thu, 30 Dec 2021 21:08:46 +0000 (22:08 +0100)
committerPhilipp <admin@philipp.info>
Thu, 30 Dec 2021 21:08:46 +0000 (22:08 +0100)
tests/legacy/ApiTest.php
tests/src/Factory/Api/Twitter/ActvitiesTest.php [new file with mode: 0644]
tests/src/Module/Api/ApiResponseTest.php

index bc2837225f3bc5171d30602a540f1d062af147bc..e4427c91945bd1ab584d5a018b50a97cdaa3c8f0 100644 (file)
@@ -8,7 +8,6 @@ namespace Friendica\Test\legacy;
 use Friendica\App;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\DI;
-use Friendica\Module\Api\ApiResponse;
 use Friendica\Module\BaseApi;
 use Friendica\Security\BasicAuth;
 use Friendica\Test\FixtureTest;
@@ -536,107 +535,7 @@ class ApiTest extends FixtureTest
                );
        }
 
-       /**
-        * Test the BaseApi::reformatXML() function.
-        *
-        * @return void
-        */
-       public function testApiReformatXml()
-       {
-               $item = true;
-               $key  = '';
-               self::assertTrue(ApiResponse::reformatXML($item, $key));
-               self::assertEquals('true', $item);
-       }
-
-       /**
-        * Test the BaseApi::reformatXML() function with a statusnet_api key.
-        *
-        * @return void
-        */
-       public function testApiReformatXmlWithStatusnetKey()
-       {
-               $item = '';
-               $key  = 'statusnet_api';
-               self::assertTrue(ApiResponse::reformatXML($item, $key));
-               self::assertEquals('statusnet:api', $key);
-       }
-
-       /**
-        * Test the BaseApi::reformatXML() function with a friendica_api key.
-        *
-        * @return void
-        */
-       public function testApiReformatXmlWithFriendicaKey()
-       {
-               $item = '';
-               $key  = 'friendica_api';
-               self::assertTrue(ApiResponse::reformatXML($item, $key));
-               self::assertEquals('friendica:api', $key);
-       }
 
-       /**
-        * Test the BaseApi::createXML() function.
-        *
-        * @return void
-        */
-       public function testApiCreateXml()
-       {
-               self::assertEquals(
-                       '<?xml version="1.0"?>' . "\n" .
-                       '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
-                       'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
-                       'xmlns:georss="http://www.georss.org/georss">' . "\n" .
-                       '  <data>some_data</data>' . "\n" .
-                       '</root_element>' . "\n",
-                       DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
-               );
-       }
-
-       /**
-        * Test the BaseApi::createXML() function without any XML namespace.
-        *
-        * @return void
-        */
-       public function testApiCreateXmlWithoutNamespaces()
-       {
-               self::assertEquals(
-                       '<?xml version="1.0"?>' . "\n" .
-                       '<ok>' . "\n" .
-                       '  <data>some_data</data>' . "\n" .
-                       '</ok>' . "\n",
-                       DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
-               );
-       }
-
-       /**
-        * Test the BaseApi::formatData() function.
-        *
-        * @return void
-        */
-       public function testApiFormatData()
-       {
-               $data = ['some_data'];
-               self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
-       }
-
-       /**
-        * Test the BaseApi::formatData() function with an XML result.
-        *
-        * @return void
-        */
-       public function testApiFormatDataWithXml()
-       {
-               self::assertEquals(
-                       '<?xml version="1.0"?>' . "\n" .
-                       '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
-                       'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
-                       'xmlns:georss="http://www.georss.org/georss">' . "\n" .
-                       '  <data>some_data</data>' . "\n" .
-                       '</root_element>' . "\n",
-                       DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
-               );
-       }
 
        /**
         * Test the api_format_items_embeded_images() function.
@@ -653,38 +552,6 @@ class ApiTest extends FixtureTest
                */
        }
 
-       /**
-        * Test the api_format_items_activities() function.
-        *
-        * @return void
-        */
-       public function testApiFormatItemsActivities()
-       {
-               $item   = ['uid' => 0, 'uri-id' => 1];
-               $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
-               self::assertArrayHasKey('like', $result);
-               self::assertArrayHasKey('dislike', $result);
-               self::assertArrayHasKey('attendyes', $result);
-               self::assertArrayHasKey('attendno', $result);
-               self::assertArrayHasKey('attendmaybe', $result);
-       }
-
-       /**
-        * Test the api_format_items_activities() function with an XML result.
-        *
-        * @return void
-        */
-       public function testApiFormatItemsActivitiesWithXml()
-       {
-               $item   = ['uid' => 0, 'uri-id' => 1];
-               $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
-               self::assertArrayHasKey('friendica:like', $result);
-               self::assertArrayHasKey('friendica:dislike', $result);
-               self::assertArrayHasKey('friendica:attendyes', $result);
-               self::assertArrayHasKey('friendica:attendno', $result);
-               self::assertArrayHasKey('friendica:attendmaybe', $result);
-       }
-
        /**
         * Test the api_format_items() function.
         * @doesNotPerformAssertions
diff --git a/tests/src/Factory/Api/Twitter/ActvitiesTest.php b/tests/src/Factory/Api/Twitter/ActvitiesTest.php
new file mode 100644 (file)
index 0000000..d213843
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace Friendica\Test\src\Factory\Api\Twitter;
+
+use Friendica\DI;
+use Friendica\Factory\Api\Friendica\Activities;
+use Friendica\Test\FixtureTest;
+
+class ActvitiesTest extends FixtureTest
+{
+       /**
+        * Test the api_format_items_activities() function.
+        *
+        * @return void
+        */
+       public function testApiFormatItemsActivities()
+       {
+               $item = ['uid' => 0, 'uri-id' => 1];
+
+               $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser());
+               $result                 = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid']);
+
+               self::assertArrayHasKey('like', $result);
+               self::assertArrayHasKey('dislike', $result);
+               self::assertArrayHasKey('attendyes', $result);
+               self::assertArrayHasKey('attendno', $result);
+               self::assertArrayHasKey('attendmaybe', $result);
+       }
+
+       /**
+        * Test the api_format_items_activities() function with an XML result.
+        *
+        * @return void
+        */
+       public function testApiFormatItemsActivitiesWithXml()
+       {
+               $item = ['uid' => 0, 'uri-id' => 1];
+
+               $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser());
+               $result                 = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid'], 'xml');
+
+               self::assertArrayHasKey('friendica:like', $result);
+               self::assertArrayHasKey('friendica:dislike', $result);
+               self::assertArrayHasKey('friendica:attendyes', $result);
+               self::assertArrayHasKey('friendica:attendno', $result);
+               self::assertArrayHasKey('friendica:attendmaybe', $result);
+       }
+}
index 99e3a8d5da0b2ad3af22ddd336f0549c435a4022..3599b8f4134804f466927f81355af34f9e50c776 100644 (file)
@@ -113,4 +113,150 @@ class ApiResponseTest extends MockedTest
 
                self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', $response->getContent());
        }
+
+       /**
+        * Test the BaseApi::reformatXML() function.
+        *
+        * @return void
+        */
+       public function testApiReformatXml()
+       {
+               $item = true;
+               $key  = '';
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
+               self::assertEquals('true', $item);
+       }
+
+       /**
+        * Test the BaseApi::reformatXML() function with a statusnet_api key.
+        *
+        * @return void
+        */
+       public function testApiReformatXmlWithStatusnetKey()
+       {
+               $item = '';
+               $key  = 'statusnet_api';
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
+               self::assertEquals('statusnet:api', $key);
+       }
+
+       /**
+        * Test the BaseApi::reformatXML() function with a friendica_api key.
+        *
+        * @return void
+        */
+       public function testApiReformatXmlWithFriendicaKey()
+       {
+               $item = '';
+               $key  = 'friendica_api';
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
+               self::assertEquals('friendica:api', $key);
+       }
+
+       /**
+        * Test the BaseApi::createXML() function.
+        *
+        * @return void
+        */
+       public function testApiCreateXml()
+       {
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) {
+                       return $args;
+               });
+               $args = \Mockery::mock(Arguments::class);
+               $args->shouldReceive('getQueryString')->andReturn('');
+               $baseUrl     = \Mockery::mock(BaseURL::class);
+               $twitterUser = \Mockery::mock(User::class);
+
+               $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
+
+               self::assertEquals(
+                       '<?xml version="1.0"?>' . "\n" .
+                       '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
+                       'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
+                       'xmlns:georss="http://www.georss.org/georss">' . "\n" .
+                       '  <data>some_data</data>' . "\n" .
+                       '</root_element>' . "\n",
+                       $response->createXML(['data' => ['some_data']], 'root_element')
+               );
+       }
+
+       /**
+        * Test the BaseApi::createXML() function without any XML namespace.
+        *
+        * @return void
+        */
+       public function testApiCreateXmlWithoutNamespaces()
+       {
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) {
+                       return $args;
+               });
+               $args = \Mockery::mock(Arguments::class);
+               $args->shouldReceive('getQueryString')->andReturn('');
+               $baseUrl     = \Mockery::mock(BaseURL::class);
+               $twitterUser = \Mockery::mock(User::class);
+
+               $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
+
+               self::assertEquals(
+                       '<?xml version="1.0"?>' . "\n" .
+                       '<ok>' . "\n" .
+                       '  <data>some_data</data>' . "\n" .
+                       '</ok>' . "\n",
+                       $response->createXML(['data' => ['some_data']], 'ok')
+               );
+       }
+
+       /**
+        * Test the BaseApi::formatData() function.
+        *
+        * @return void
+        */
+       public function testApiFormatData()
+       {
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) {
+                       return $args;
+               });
+               $args = \Mockery::mock(Arguments::class);
+               $args->shouldReceive('getQueryString')->andReturn('');
+               $baseUrl     = \Mockery::mock(BaseURL::class);
+               $twitterUser = \Mockery::mock(User::class);
+
+               $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
+
+               $data = ['some_data'];
+               self::assertEquals($data, $response->formatData('root_element', 'json', $data));
+       }
+
+       /**
+        * Test the BaseApi::formatData() function with an XML result.
+        *
+        * @return void
+        */
+       public function testApiFormatDataWithXml()
+       {
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) {
+                       return $args;
+               });
+               $args = \Mockery::mock(Arguments::class);
+               $args->shouldReceive('getQueryString')->andReturn('');
+               $baseUrl     = \Mockery::mock(BaseURL::class);
+               $twitterUser = \Mockery::mock(User::class);
+
+               $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
+
+               self::assertEquals(
+                       '<?xml version="1.0"?>' . "\n" .
+                       '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
+                       'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
+                       'xmlns:georss="http://www.georss.org/georss">' . "\n" .
+                       '  <data>some_data</data>' . "\n" .
+                       '</root_element>' . "\n",
+                       $response->formatData('root_element', 'xml', ['data' => ['some_data']])
+               );
+       }
 }