]> git.mxchange.org Git - friendica.git/blobdiff - tests/include/ApiTest.php
Rename class for PSR-0
[friendica.git] / tests / include / ApiTest.php
index e8e148d43493008f14312d324018c1e8484c4cf2..ceeaac6f6fdcd4c3e8dca4c68561a5f6c254c5b5 100644 (file)
@@ -5,20 +5,12 @@
 
 namespace Friendica\Test;
 
-use Dice\Dice;
 use Friendica\App;
 use Friendica\Core\Config\IConfig;
 use Friendica\Core\PConfig\IPConfig;
 use Friendica\Core\Protocol;
-use Friendica\Core\Session;
-use Friendica\Core\Session\ISession;
-use Friendica\Core\System;
-use Friendica\Database\Database;
-use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\Contact;
 use Friendica\Network\HTTPException;
-use Friendica\Test\Util\Database\StaticDatabase;
 use Friendica\Util\Temporal;
 use Monolog\Handler\TestHandler;
 
@@ -30,7 +22,7 @@ require_once __DIR__ . '/../../include/api.php';
  * Functions that use header() need to be tested in a separate process.
  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
  */
-class ApiTest extends DatabaseTest
+class ApiTest extends FixtureTest
 {
        /**
         * @var TestHandler Can handle log-outputs
@@ -52,9 +44,6 @@ class ApiTest extends DatabaseTest
        /** @var IConfig */
        protected $config;
 
-       /** @var Dice */
-       protected $dice;
-
        /**
         * Create variables used by tests.
         */
@@ -62,15 +51,6 @@ class ApiTest extends DatabaseTest
        {
                parent::setUp();
 
-               $this->dice = (new Dice())
-                       ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
-                       ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
-                       ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
-               DI::init($this->dice);
-
-               /** @var Database $dba */
-               $dba = $this->dice->create(Database::class);
-
                /** @var IConfig $config */
                $this->config = $this->dice->create(IConfig::class);
 
@@ -85,8 +65,6 @@ class ApiTest extends DatabaseTest
                $this->config->set('system', 'throttle_limit_month', 100);
                $this->config->set('system', 'theme', 'system_theme');
 
-               // Load the API dataset for the whole API
-               $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
 
                /** @var App app */
                $this->app = DI::app();
@@ -839,38 +817,38 @@ class ApiTest extends DatabaseTest
        }
 
        /**
-        * Test the api_get_user() function with a custom Frio schema.
+        * Test the api_get_user() function with an empty Frio schema.
         *
         * @return void
         */
-       public function testApiGetUserWithCustomFrioSchema()
+       public function testApiGetUserWithEmptyFrioSchema()
        {
                $pConfig = $this->dice->create(IPConfig::class);
                $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
-               $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
                $user = api_get_user($this->app);
                $this->assertSelfUser($user);
-               $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
-               $this->assertEquals('123456', $user['profile_link_color']);
-               $this->assertEquals('123456', $user['profile_background_color']);
+               $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
+               $this->assertEquals('6fdbe8', $user['profile_link_color']);
+               $this->assertEquals('ededed', $user['profile_background_color']);
        }
 
        /**
-        * Test the api_get_user() function with an empty Frio schema.
+        * Test the api_get_user() function with a custom Frio schema.
         *
         * @return void
         */
-       public function testApiGetUserWithEmptyFrioSchema()
+       public function testApiGetUserWithCustomFrioSchema()
        {
                $pConfig = $this->dice->create(IPConfig::class);
                $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
+               $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
+               $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
+               $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
                $user = api_get_user($this->app);
                $this->assertSelfUser($user);
-               $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
-               $this->assertEquals('6fdbe8', $user['profile_link_color']);
-               $this->assertEquals('ededed', $user['profile_background_color']);
+               $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
+               $this->assertEquals('123456', $user['profile_link_color']);
+               $this->assertEquals('123456', $user['profile_background_color']);
        }
 
        /**
@@ -2489,102 +2467,6 @@ class ApiTest extends DatabaseTest
                $this->assertArrayHasKey('friendica:attendmaybe', $result);
        }
 
-       /**
-        * Test the api_format_items_profiles() function.
-        *
-        * @return void
-        */
-       public function testApiFormatItemsProfiles()
-       {
-               $profile_row = [
-                       'id'           => 'profile_id',
-                       'profile-name' => 'profile_name',
-                       'is-default'   => true,
-                       'hide-friends' => true,
-                       'photo'        => 'profile_photo',
-                       'thumb'        => 'profile_thumb',
-                       'publish'      => true,
-                       'net-publish'  => true,
-                       'pdesc'        => 'description',
-                       'dob'          => 'date_of_birth',
-                       'address'      => 'address',
-                       'locality'     => 'city',
-                       'region'       => 'region',
-                       'postal-code'  => 'postal_code',
-                       'country-name' => 'country',
-                       'hometown'     => 'hometown',
-                       'gender'       => 'gender',
-                       'marital'      => 'marital',
-                       'with'         => 'marital_with',
-                       'howlong'      => 'marital_since',
-                       'sexual'       => 'sexual',
-                       'politic'      => 'politic',
-                       'religion'     => 'religion',
-                       'pub_keywords' => 'public_keywords',
-                       'prv_keywords' => 'private_keywords',
-
-                       'likes'     => 'likes',
-                       'dislikes'  => 'dislikes',
-                       'about'     => 'about',
-                       'music'     => 'music',
-                       'book'      => 'book',
-                       'tv'        => 'tv',
-                       'film'      => 'film',
-                       'interest'  => 'interest',
-                       'romance'   => 'romance',
-                       'work'      => 'work',
-                       'education' => 'education',
-                       'contact'   => 'social_networks',
-                       'homepage'  => 'homepage'
-               ];
-               $result      = api_format_items_profiles($profile_row);
-               $this->assertEquals(
-                       [
-                               'profile_id'       => 'profile_id',
-                               'profile_name'     => 'profile_name',
-                               'is_default'       => true,
-                               'hide_friends'     => true,
-                               'profile_photo'    => 'profile_photo',
-                               'profile_thumb'    => 'profile_thumb',
-                               'publish'          => true,
-                               'net_publish'      => true,
-                               'description'      => 'description',
-                               'date_of_birth'    => 'date_of_birth',
-                               'address'          => 'address',
-                               'city'             => 'city',
-                               'region'           => 'region',
-                               'postal_code'      => 'postal_code',
-                               'country'          => 'country',
-                               'hometown'         => 'hometown',
-                               'gender'           => 'gender',
-                               'marital'          => 'marital',
-                               'marital_with'     => 'marital_with',
-                               'marital_since'    => 'marital_since',
-                               'sexual'           => 'sexual',
-                               'politic'          => 'politic',
-                               'religion'         => 'religion',
-                               'public_keywords'  => 'public_keywords',
-                               'private_keywords' => 'private_keywords',
-
-                               'likes'           => 'likes',
-                               'dislikes'        => 'dislikes',
-                               'about'           => 'about',
-                               'music'           => 'music',
-                               'book'            => 'book',
-                               'tv'              => 'tv',
-                               'film'            => 'film',
-                               'interest'        => 'interest',
-                               'romance'         => 'romance',
-                               'work'            => 'work',
-                               'education'       => 'education',
-                               'social_networks' => 'social_networks',
-                               'homepage'        => 'homepage',
-                               'users'           => null
-                       ],
-                       $result
-               );
-       }
-
        /**
         * Test the api_format_items() function.
         *
@@ -2944,61 +2826,6 @@ class ApiTest extends DatabaseTest
                $this->assertEquals('0.9.7', $result['version']);
        }
 
-       /**
-        * Test the api_ff_ids() function.
-        *
-        * @return void
-        */
-       public function testApiFfIds()
-       {
-               $result = api_ff_ids('json', Contact::FOLLOWER);
-               $this->assertEquals(['id' => []], $result);
-       }
-
-       /**
-        * Test the api_ff_ids() function with a result.
-        *
-        * @return void
-        */
-       public function testApiFfIdsWithResult()
-       {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * Test the api_ff_ids() function without an authenticated user.
-        *
-        * @return void
-        * @expectedException Friendica\Network\HTTPException\ForbiddenException
-        */
-       public function testApiFfIdsWithoutAuthenticatedUser()
-       {
-               $_SESSION['authenticated'] = false;
-               api_ff_ids('json', Contact::FOLLOWER);
-       }
-
-       /**
-        * Test the api_friends_ids() function.
-        *
-        * @return void
-        */
-       public function testApiFriendsIds()
-       {
-               $result = api_friends_ids('json');
-               $this->assertEquals(['id' => []], $result);
-       }
-
-       /**
-        * Test the api_followers_ids() function.
-        *
-        * @return void
-        */
-       public function testApiFollowersIds()
-       {
-               $result = api_followers_ids('json');
-               $this->assertEquals(['id' => []], $result);
-       }
-
        /**
         * Test the api_direct_messages_new() function.
         *
@@ -3042,6 +2869,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiDirectMessagesNewWithScreenName()
        {
+               $this->app->user    = ['nickname' => $this->selfUser['nick']];
                $_POST['text']        = 'message_text';
                $_POST['screen_name'] = $this->friendUser['nick'];
                $result               = api_direct_messages_new('json');
@@ -3057,6 +2885,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiDirectMessagesNewWithTitle()
        {
+               $this->app->user    = ['nickname' => $this->selfUser['nick']];
                $_POST['text']        = 'message_text';
                $_POST['screen_name'] = $this->friendUser['nick'];
                $_REQUEST['title']    = 'message_title';
@@ -3074,6 +2903,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiDirectMessagesNewWithRss()
        {
+               $this->app->user    = ['nickname' => $this->selfUser['nick']];
                $_POST['text']        = 'message_text';
                $_POST['screen_name'] = $this->friendUser['nick'];
                $result               = api_direct_messages_new('rss');
@@ -3945,7 +3775,7 @@ class ApiTest extends DatabaseTest
                $assertXml=<<<XML
 <?xml version="1.0"?>
 <notes>
-  <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
+  <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" uri-id="" link="http://localhost/notification/1" iid="4" parent="0" parent-uri-id="" seen="0" verb="" otype="item" name_cache="Reply to" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
 </notes>
 XML;
                $this->assertXmlStringEqualsXmlString($assertXml, $result);
@@ -3994,58 +3824,6 @@ XML;
                $this->markTestIncomplete();
        }
 
-       /**
-        * Test the api_friendica_profile_show() function.
-        *
-        * @return void
-        */
-       public function testApiFriendicaProfileShow()
-       {
-               $result = api_friendica_profile_show('json');
-               // We can't use assertSelfUser() here because the user object is missing some properties.
-               $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
-               $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
-               $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
-               $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
-               $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
-               $this->assertTrue($result['$result']['friendica_owner']['verified']);
-               $this->assertFalse($result['$result']['multi_profiles']);
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function with a profile ID.
-        *
-        * @return void
-        */
-       public function testApiFriendicaProfileShowWithProfileId()
-       {
-               $this->markTestIncomplete('We need to add a dataset for this.');
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function with a wrong profile ID.
-        *
-        * @return void
-        * @expectedException Friendica\Network\HTTPException\BadRequestException
-        */
-       public function testApiFriendicaProfileShowWithWrongProfileId()
-       {
-               $_REQUEST['profile_id'] = 666;
-               api_friendica_profile_show('json');
-       }
-
-       /**
-        * Test the api_friendica_profile_show() function without an authenticated user.
-        *
-        * @return void
-        * @expectedException Friendica\Network\HTTPException\ForbiddenException
-        */
-       public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
-       {
-               $_SESSION['authenticated'] = false;
-               api_friendica_profile_show('json');
-       }
-
        /**
         * Test the api_saved_searches_list() function.
         *