|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\User; |
|
8
|
|
|
use Application\Repository\UserRepository; |
|
9
|
|
|
use ApplicationTest\Traits\LimitedAccessSubQuery; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @group Repository |
|
13
|
|
|
*/ |
|
14
|
|
|
class UserRepositoryTest extends AbstractRepositoryTest |
|
15
|
|
|
{ |
|
16
|
|
|
use LimitedAccessSubQuery; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var UserRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
private $repository; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
$this->repository = $this->getEntityManager()->getRepository(User::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function providerGetAccessibleSubQuery(): array |
|
30
|
|
|
{ |
|
31
|
|
|
$all = range(1000, 1013); |
|
32
|
|
|
|
|
33
|
|
|
return [ |
|
34
|
|
|
['anonymous', []], |
|
35
|
|
|
['bookingonly', $all], |
|
36
|
|
|
['individual', $all], |
|
37
|
|
|
['member', $all], |
|
38
|
|
|
['trainer', $all], |
|
39
|
|
|
['responsible', $all], |
|
40
|
|
|
['administrator', $all], |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGetOneByLoginPassword(): void |
|
45
|
|
|
{ |
|
46
|
|
|
self::assertNull($this->repository->getOneByLoginPassword('foo', 'bar'), 'wrong user'); |
|
47
|
|
|
self::assertNull($this->repository->getOneByLoginPassword('administrator', 'bar'), 'wrong password'); |
|
48
|
|
|
|
|
49
|
|
|
$user = $this->repository->getOneByLoginPassword('administrator', 'administrator'); |
|
50
|
|
|
self::assertNotNull($user); |
|
51
|
|
|
self::assertSame(1000, $user->getId()); |
|
52
|
|
|
|
|
53
|
|
|
$hash = $this->getEntityManager()->getConnection()->query('SELECT password FROM `user` WHERE id = 1000')->fetchColumn(); |
|
54
|
|
|
self::assertStringStartsWith('$', $hash, 'password should have been re-hashed automatically'); |
|
|
|
|
|
|
55
|
|
|
self::assertNotSame(md5('administrator'), $hash, 'password should have been re-hashed automatically'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testGetOneByLogin(): void |
|
59
|
|
|
{ |
|
60
|
|
|
self::assertNull($this->repository->getOneById(1), 'wrong user'); |
|
61
|
|
|
|
|
62
|
|
|
$user = $this->repository->getOneById(1000); |
|
63
|
|
|
self::assertNotNull($user); |
|
64
|
|
|
self::assertSame(1000, $user->getId()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGetAllAdministratorsToNotify(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$actual = $this->repository->getAllAdministratorsToNotify(); |
|
70
|
|
|
self::assertCount(1, $actual); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGetAllToQueueBalanceMessage(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$actual = $this->repository->getAllToQueueBalanceMessage(); |
|
76
|
|
|
self::assertCount(2, $actual); |
|
77
|
|
|
|
|
78
|
|
|
$actualBookings = []; |
|
79
|
|
|
foreach ($actual[0]->getBookings() as $booking) { |
|
80
|
|
|
$actualBookings[] = $booking->getId(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$expected = [4004, 4005, 4015]; |
|
84
|
|
|
self::assertSame($expected, $actualBookings, 'must have pre-loaded only the bookings that we are interested in'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testGetAllToQueueBalanceMessageNegative(): void |
|
88
|
|
|
{ |
|
89
|
|
|
$actual = $this->repository->getAllToQueueBalanceMessage(true); |
|
90
|
|
|
self::assertCount(0, $actual); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|