3 * @copyright Copyright (C) 2020, Friendica
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\Model;
24 use Friendica\Model\User;
25 use Friendica\Test\MockedTest;
26 use Friendica\Test\Util\DBAMockTrait;
29 * @runTestsInSeparateProcesses
30 * @preserveGlobalState disabled
32 class UserTest extends MockedTest
40 protected function setUp()
46 'username' => 'maxmuster',
47 'nickname' => 'Max Muster'
52 'username' => 'johndoe',
53 'nickname' => 'John Doe'
58 'username' => 'janesmith',
59 'nickname' => 'Jane Smith'
63 public function testIdentitiesEmpty()
65 $this->mockSelectFirst('user',
66 ['uid', 'nickname', 'username', 'parent-uid'],
67 ['uid' => $this->parent['uid']],
71 $this->mockIsResult($this->parent, false, 1);
73 $record = User::identities($this->parent['uid']);
75 self::assertEquals([], $record);
78 public function testIdentitiesAsParent()
80 $parentSelect = $this->parent;
81 $parentSelect['parent-uid'] = 0;
83 // Select the user itself (=parent)
84 $this->mockSelectFirst('user',
85 ['uid', 'nickname', 'username', 'parent-uid'],
86 ['uid' => $this->parent['uid']],
90 $this->mockIsResult($parentSelect, true, 1);
93 $this->mockSelect('user',
94 ['uid', 'username', 'nickname'],
96 'parent-uid' => $this->parent['uid'],
97 'account_removed' => false
102 $this->mockIsResult('objectReturn', true, 1);
103 $this->mockToArray('objectReturn', [ $this->child ], 1);
106 $this->mockP(null, 'objectTwo', 1);
107 $this->mockIsResult('objectTwo', true, 1);
108 $this->mockToArray('objectTwo', [ $this->manage ], 1);
110 $record = User::identities($this->parent['uid']);
119 public function testIdentitiesAsChild()
121 $childSelect = $this->child;
122 $childSelect['parent-uid'] = $this->parent['uid'];
124 // Select the user itself (=child)
125 $this->mockSelectFirst('user',
126 ['uid', 'nickname', 'username', 'parent-uid'],
127 ['uid' => $this->child['uid']],
131 $this->mockIsResult($childSelect, true, 1);
134 $this->mockSelect('user',
135 ['uid', 'username', 'nickname'],
137 'uid' => $this->parent['uid'],
138 'account_removed' => false
143 $this->mockIsResult('objectReturn', true, 1);
144 $this->mockToArray('objectReturn', [ $this->parent ], 1);
146 // Select the childs (user & manage)
147 $this->mockSelect('user',
148 ['uid', 'username', 'nickname'],
150 'parent-uid' => $this->parent['uid'],
151 'account_removed' => false
156 $this->mockIsResult('objectReturn', true, 1);
157 $this->mockToArray('objectReturn', [ $this->child, $this->manage ], 1);
160 $this->mockP(null, 'objectTwo', 1);
161 $this->mockIsResult('objectTwo', false, 1);
163 $record = User::identities($this->child['uid']);