3 * @copyright Copyright (C) 2010-2022, 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\Model;
25 use Friendica\Database\Database;
27 use Friendica\Model\User;
28 use Friendica\Test\MockedTest;
29 use Mockery\MockInterface;
31 class UserTest extends MockedTest
37 /** @var Database|MockInterface */
40 protected function setUp(): void
44 $this->dbMock = \Mockery::mock(Database::class);
46 $diceMock = \Mockery::mock(Dice::class)->makePartial();
47 /** @var Dice|MockInterface $diceMock */
48 $diceMock = $diceMock->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
49 $diceMock->shouldReceive('create')->withArgs([Database::class])->andReturn($this->dbMock);
54 'username' => 'maxmuster',
55 'nickname' => 'Max Muster'
60 'username' => 'johndoe',
61 'nickname' => 'John Doe'
66 'username' => 'janesmith',
67 'nickname' => 'Jane Smith'
71 public function testIdentitiesEmpty()
73 $this->dbMock->shouldReceive('selectFirst')->with('user',
74 ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($this->parent)->once();
75 $this->dbMock->shouldReceive('isResult')->with($this->parent)->andReturn(false)->once();
77 $record = User::identities($this->parent['uid']);
79 self::assertEquals([], $record);
82 public function testIdentitiesAsParent()
84 $parentSelect = $this->parent;
85 $parentSelect['parent-uid'] = 0;
87 // Select the user itself (=parent)
88 $this->dbMock->shouldReceive('selectFirst')->with('user',
89 ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->parent['uid']], [])->andReturn($parentSelect)->once();
90 $this->dbMock->shouldReceive('isResult')->with($parentSelect)->andReturn(true)->once();
93 $this->dbMock->shouldReceive('select')->with('user',
94 ['uid', 'username', 'nickname'],
96 'parent-uid' => $this->parent['uid'],
97 'account_removed' => false
98 ], [])->andReturn('objectReturn')->once();
99 $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
100 $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child])->once();
103 $this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once();
104 $this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(true)->once();
105 $this->dbMock->shouldReceive('toArray')->with('objectTwo', true, 0)->andReturn([$this->manage])->once();
107 $record = User::identities($this->parent['uid']);
116 public function testIdentitiesAsChild()
118 $childSelect = $this->child;
119 $childSelect['parent-uid'] = $this->parent['uid'];
121 // Select the user itself (=child)
122 $this->dbMock->shouldReceive('selectFirst')->with('user',
123 ['uid', 'nickname', 'username', 'parent-uid'],['uid' => $this->child['uid']], [])->andReturn($childSelect)->once();
124 $this->dbMock->shouldReceive('isResult')->with($childSelect)->andReturn(true)->once();
127 $this->dbMock->shouldReceive('select')->with('user',
128 ['uid', 'username', 'nickname'],
130 'uid' => $this->parent['uid'],
131 'account_removed' => false
132 ], [])->andReturn('objectReturn')->once();
133 $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
134 $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->parent])->once();
136 // Select the childs (user & manage)
137 $this->dbMock->shouldReceive('select')->with('user',
138 ['uid', 'username', 'nickname'],
140 'parent-uid' => $this->parent['uid'],
141 'account_removed' => false
142 ], [])->andReturn('objectReturn')->once();
143 $this->dbMock->shouldReceive('isResult')->with('objectReturn')->andReturn(true)->once();
144 $this->dbMock->shouldReceive('toArray')->with('objectReturn', true, 0)->andReturn([$this->child, $this->manage])->once();
147 $this->dbMock->shouldReceive('p')->withAnyArgs()->andReturn('objectTwo')->once();
148 $this->dbMock->shouldReceive('isResult')->with('objectTwo')->andReturn(false)->once();
150 $record = User::identities($this->child['uid']);