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