]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/UserTest.php
6655575f87e2f2d95247a1a9f4d4d4a10e6aa002
[friendica.git] / tests / src / Model / UserTest.php
1 <?php
2
3 namespace Friendica\Test\Object;
4
5 use Friendica\Model\User;
6 use Friendica\Test\MockedTest;
7 use Friendica\Test\Util\DBAMockTrait;
8
9 class UserTest extends MockedTest
10 {
11         use DBAMockTrait;
12
13         private $parent;
14         private $child;
15         private $manage;
16
17         protected function setUp()
18         {
19                 parent::setUp();
20
21                 $this->parent = [
22                         'uid'        => 1,
23                         'username'   => 'maxmuster',
24                         'nickname'   => 'Max Muster'
25                 ];
26
27                 $this->child = [
28                         'uid'        => 2,
29                         'username'   => 'johndoe',
30                         'nickname'   => 'John Doe'
31                 ];
32
33                 $this->manage = [
34                         'uid'        => 3,
35                         'username'   => 'janesmith',
36                         'nickname'   => 'Jane Smith'
37                 ];
38         }
39
40         public function testIdentitiesEmpty()
41         {
42                 $this->mockSelectFirst('user',
43                         ['uid', 'nickname', 'username', 'parent-uid'],
44                         ['uid' => $this->parent['uid']],
45                         $this->parent,
46                         1
47                 );
48                 $this->mockIsResult($this->parent, false, 1);
49
50                 $record = User::identities($this->parent['uid']);
51
52                 $this->assertEquals([], $record);
53         }
54
55         public function testIdentitiesAsParent()
56         {
57                 $parentSelect = $this->parent;
58                 $parentSelect['parent-uid'] = 0;
59
60                 // Select the user itself (=parent)
61                 $this->mockSelectFirst('user',
62                         ['uid', 'nickname', 'username', 'parent-uid'],
63                         ['uid' => $this->parent['uid']],
64                         $parentSelect,
65                         1
66                 );
67                 $this->mockIsResult($parentSelect, true, 1);
68
69                 // Select one child
70                 $this->mockSelect('user',
71                         ['uid', 'username', 'nickname'],
72                         [
73                                 'parent-uid' => $this->parent['uid'],
74                                 'account_removed' => false
75                         ],
76                         'objectReturn',
77                         1
78                 );
79                 $this->mockIsResult('objectReturn', true, 1);
80                 $this->mockToArray('objectReturn', [ $this->child ], 1);
81
82                 // Select the manage
83                 $this->mockP(null, 'objectTwo', 1);
84                 $this->mockIsResult('objectTwo', true, 1);
85                 $this->mockToArray('objectTwo', [ $this->manage ], 1);
86
87                 $record = User::identities($this->parent['uid']);
88
89                 $this->assertEquals([
90                         $this->parent,
91                         $this->child,
92                         $this->manage
93                 ], $record);
94         }
95
96         public function testIdentitiesAsChild()
97         {
98                 $childSelect = $this->child;
99                 $childSelect['parent-uid'] = $this->parent['uid'];
100
101                 // Select the user itself (=child)
102                 $this->mockSelectFirst('user',
103                         ['uid', 'nickname', 'username', 'parent-uid'],
104                         ['uid' => $this->child['uid']],
105                         $childSelect,
106                         1
107                 );
108                 $this->mockIsResult($childSelect, true, 1);
109
110                 // Select the parent
111                 $this->mockSelect('user',
112                         ['uid', 'username', 'nickname'],
113                         [
114                                 'uid' => $this->parent['uid'],
115                                 'account_removed' => false
116                         ],
117                         'objectReturn',
118                         1
119                 );
120                 $this->mockIsResult('objectReturn', true, 1);
121                 $this->mockToArray('objectReturn', [ $this->parent ], 1);
122
123                 // Select the childs (user & manage)
124                 $this->mockSelect('user',
125                         ['uid', 'username', 'nickname'],
126                         [
127                                 'parent-uid' => $this->parent['uid'],
128                                 'account_removed' => false
129                         ],
130                         'objectReturn',
131                         1
132                 );
133                 $this->mockIsResult('objectReturn', true, 1);
134                 $this->mockToArray('objectReturn', [ $this->child, $this->manage ], 1);
135
136                 // Select the manage
137                 $this->mockP(null, 'objectTwo', 1);
138                 $this->mockIsResult('objectTwo', false, 1);
139
140                 $record = User::identities($this->child['uid']);
141
142                 $this->assertEquals([
143                         $this->parent,
144                         $this->child,
145                         $this->manage
146                 ], $record);
147         }
148 }