3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Factory\Api\Twitter;
25 use Friendica\Factory\Api\Twitter\User;
26 use Friendica\Test\FixtureTest;
27 use Friendica\Test\src\Module\Api\ApiTest;
29 class UserTest extends FixtureTest
32 * Assert that an user array contains expected keys.
36 protected function assertSelfUser(array $user)
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']);
47 * Test the api_get_user() function.
51 public function testApiGetUser()
53 $user = (new User(DI::logger(), DI::twitterStatus()))
54 ->createFromUserId(ApiTest::SELF_USER['id'])
57 $this->assertSelfUser($user);
61 * Test the api_get_user() function with a Frio schema.
65 public function testApiGetUserWithFrioSchema()
67 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
70 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', 'red');
72 $userFactory = new User(DI::logger(), DI::twitterStatus());
73 $user = $userFactory->createFromUserId(42);
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']);
83 * Test the api_get_user() function with an empty Frio schema.
87 public function testApiGetUserWithEmptyFrioSchema()
89 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
92 DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---');
94 $userFactory = new User(DI::logger(), DI::twitterStatus());
95 $user = $userFactory->createFromUserId(42);
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']);
105 * Test the api_get_user() function with a custom Frio schema.
109 public function testApiGetUserWithCustomFrioSchema()
111 $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.');
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');
119 $userFactory = new User(DI::logger(), DI::twitterStatus());
120 $user = $userFactory->createFromUserId(42);
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']);
130 * Test the api_get_user() function with a wrong user ID in a GET parameter.
134 public function testApiGetUserWithWrongGetId()
136 $user = (new User(DI::logger(), DI::twitterStatus()))
137 ->createFromUserId(-1)
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']);
148 * Test the api_user() function with an unallowed user.
152 public function testApiUserWithUnallowedUser()
154 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
156 // self::assertEquals(false, api_user());