]> git.mxchange.org Git - friendica.git/blob - tests/src/Factory/Api/Twitter/UserTest.php
Merge pull request #12697 from MrPetovan/bug/deprecated
[friendica.git] / tests / src / Factory / Api / Twitter / UserTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Factory\Api\Twitter;
23
24 use Friendica\DI;
25 use Friendica\Factory\Api\Twitter\User;
26 use Friendica\Test\FixtureTest;
27 use Friendica\Test\src\Module\Api\ApiTest;
28
29 class UserTest extends FixtureTest
30 {
31         /**
32          * Assert that an user array contains expected keys.
33          *
34          * @return void
35          */
36         protected function assertSelfUser(array $user)
37         {
38                 self::assertEquals(ApiTest::SELF_USER['id'], $user['uid']);
39                 self::assertEquals(ApiTest::SELF_USER['id'], $user['cid']);
40                 self::assertEquals('DFRN', $user['location']);
41                 self::assertEquals(ApiTest::SELF_USER['name'], $user['name']);
42                 self::assertEquals(ApiTest::SELF_USER['nick'], $user['screen_name']);
43                 self::assertTrue($user['verified']);
44         }
45
46         /**
47          * Test the api_get_user() function.
48          *
49          * @return void
50          */
51         public function testApiGetUser()
52         {
53                 $user = (new User(DI::logger(), DI::twitterStatus()))
54                         ->createFromUserId(ApiTest::SELF_USER['id'])
55                         ->toArray();
56
57                 $this->assertSelfUser($user);
58         }
59
60         /**
61          * Test the api_get_user() function with a Frio schema.
62          *
63          * @return void
64          */
65         public function testApiGetUserWithFrioSchema()
66         {
67                 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
68
69                 /*
70                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', 'red');
71
72                 $userFactory = new User(DI::logger(), DI::twitterStatus());
73                 $user        = $userFactory->createFromUserId(42);
74
75                 $this->assertSelfUser($user->toArray());
76                 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
77                 self::assertEquals('6fdbe8', $user['profile_link_color']);
78                 self::assertEquals('ededed', $user['profile_background_color']);
79                 */
80         }
81
82         /**
83          * Test the api_get_user() function with an empty Frio schema.
84          *
85          * @return void
86          */
87         public function testApiGetUserWithEmptyFrioSchema()
88         {
89                 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
90
91                 /*
92                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---');
93
94                 $userFactory = new User(DI::logger(), DI::twitterStatus());
95                 $user        = $userFactory->createFromUserId(42);
96
97                 $this->assertSelfUser($user->toArray());
98                 self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
99                 self::assertEquals('6fdbe8', $user['profile_link_color']);
100                 self::assertEquals('ededed', $user['profile_background_color']);
101                 */
102         }
103
104         /**
105          * Test the api_get_user() function with a custom Frio schema.
106          *
107          * @return void
108          */
109         public function testApiGetUserWithCustomFrioSchema()
110         {
111                 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
112
113                 /*
114                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---');
115                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'nav_bg', '#123456');
116                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'link_color', '#123456');
117                 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'background_color', '#123456');
118
119                 $userFactory = new User(DI::logger(), DI::twitterStatus());
120                 $user        = $userFactory->createFromUserId(42);
121
122                 $this->assertSelfUser($user->toArray());
123                 self::assertEquals('123456', $user['profile_sidebar_fill_color']);
124                 self::assertEquals('123456', $user['profile_link_color']);
125                 self::assertEquals('123456', $user['profile_background_color']);
126                 */
127         }
128
129         /**
130          * Test the api_get_user() function with a wrong user ID in a GET parameter.
131          *
132          * @return void
133          */
134         public function testApiGetUserWithWrongGetId()
135         {
136                 $user = (new User(DI::logger(), DI::twitterStatus()))
137                         ->createFromUserId(-1)
138                         ->toArray();
139
140                 self::assertEquals(0, $user['id']);
141                 self::assertEquals(0, $user['uid']);
142                 self::assertEquals(0, $user['cid']);
143                 self::assertEquals(0, $user['pid']);
144                 self::assertEmpty($user['name']);
145         }
146
147         /**
148          * Test the api_user() function with an unallowed user.
149          *
150          * @return void
151          */
152         public function testApiUserWithUnallowedUser()
153         {
154                 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
155
156                 // self::assertEquals(false, api_user());
157         }
158 }