]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/UserTest.php
Set test data
[friendica.git] / tests / src / Model / UserTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Model;
23
24 use Friendica\Model\User;
25 use Friendica\Test\MockedTest;
26 use Friendica\Test\Util\DBAMockTrait;
27
28 /**
29  * @runTestsInSeparateProcesses
30  * @preserveGlobalState disabled
31  */
32 class UserTest extends MockedTest
33 {
34         use DBAMockTrait;
35
36         private $parent;
37         private $child;
38         private $manage;
39
40         protected function setUp()
41         {
42                 parent::setUp();
43
44                 $this->parent = [
45                         'uid'        => 1,
46                         'username'   => 'maxmuster',
47                         'nickname'   => 'Max Muster'
48                 ];
49
50                 $this->child = [
51                         'uid'        => 2,
52                         'username'   => 'johndoe',
53                         'nickname'   => 'John Doe'
54                 ];
55
56                 $this->manage = [
57                         'uid'        => 3,
58                         'username'   => 'janesmith',
59                         'nickname'   => 'Jane Smith'
60                 ];
61         }
62
63         public function testIdentitiesEmpty()
64         {
65                 $this->mockSelectFirst('user',
66                         ['uid', 'nickname', 'username', 'parent-uid'],
67                         ['uid' => $this->parent['uid']],
68                         $this->parent,
69                         1
70                 );
71                 $this->mockIsResult($this->parent, false, 1);
72
73                 $record = User::identities($this->parent['uid']);
74
75                 self::assertEquals([], $record);
76         }
77
78         public function testIdentitiesAsParent()
79         {
80                 $parentSelect = $this->parent;
81                 $parentSelect['parent-uid'] = 0;
82
83                 // Select the user itself (=parent)
84                 $this->mockSelectFirst('user',
85                         ['uid', 'nickname', 'username', 'parent-uid'],
86                         ['uid' => $this->parent['uid']],
87                         $parentSelect,
88                         1
89                 );
90                 $this->mockIsResult($parentSelect, true, 1);
91
92                 // Select one child
93                 $this->mockSelect('user',
94                         ['uid', 'username', 'nickname'],
95                         [
96                                 'parent-uid' => $this->parent['uid'],
97                                 'account_removed' => false
98                         ],
99                         'objectReturn',
100                         1
101                 );
102                 $this->mockIsResult('objectReturn', true, 1);
103                 $this->mockToArray('objectReturn', [ $this->child ], 1);
104
105                 // Select the manage
106                 $this->mockP(null, 'objectTwo', 1);
107                 $this->mockIsResult('objectTwo', true, 1);
108                 $this->mockToArray('objectTwo', [ $this->manage ], 1);
109
110                 $record = User::identities($this->parent['uid']);
111
112                 self::assertEquals([
113                         $this->parent,
114                         $this->child,
115                         $this->manage
116                 ], $record);
117         }
118
119         public function testIdentitiesAsChild()
120         {
121                 $childSelect = $this->child;
122                 $childSelect['parent-uid'] = $this->parent['uid'];
123
124                 // Select the user itself (=child)
125                 $this->mockSelectFirst('user',
126                         ['uid', 'nickname', 'username', 'parent-uid'],
127                         ['uid' => $this->child['uid']],
128                         $childSelect,
129                         1
130                 );
131                 $this->mockIsResult($childSelect, true, 1);
132
133                 // Select the parent
134                 $this->mockSelect('user',
135                         ['uid', 'username', 'nickname'],
136                         [
137                                 'uid' => $this->parent['uid'],
138                                 'account_removed' => false
139                         ],
140                         'objectReturn',
141                         1
142                 );
143                 $this->mockIsResult('objectReturn', true, 1);
144                 $this->mockToArray('objectReturn', [ $this->parent ], 1);
145
146                 // Select the childs (user & manage)
147                 $this->mockSelect('user',
148                         ['uid', 'username', 'nickname'],
149                         [
150                                 'parent-uid' => $this->parent['uid'],
151                                 'account_removed' => false
152                         ],
153                         'objectReturn',
154                         1
155                 );
156                 $this->mockIsResult('objectReturn', true, 1);
157                 $this->mockToArray('objectReturn', [ $this->child, $this->manage ], 1);
158
159                 // Select the manage
160                 $this->mockP(null, 'objectTwo', 1);
161                 $this->mockIsResult('objectTwo', false, 1);
162
163                 $record = User::identities($this->child['uid']);
164
165                 self::assertEquals([
166                         $this->parent,
167                         $this->child,
168                         $this->manage
169                 ], $record);
170         }
171 }