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
|
|
|
public function setUp(): void |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
$this->repository = _em()->getRepository(User::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function providerGetAccessibleSubQuery(): array |
30
|
|
|
{ |
31
|
|
|
$all = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011]; |
32
|
|
|
|
33
|
|
|
return [ |
34
|
|
|
['anonymous', []], |
35
|
|
|
['bookingonly', $all], |
36
|
|
|
['individual', $all], |
37
|
|
|
['member', $all], |
38
|
|
|
['responsible', $all], |
39
|
|
|
['administrator', $all], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetByLoginPassword(): void |
44
|
|
|
{ |
45
|
|
|
self::assertNull($this->repository->getByLoginPassword('foo', 'bar'), 'wrong user'); |
46
|
|
|
self::assertNull($this->repository->getByLoginPassword('administrator', 'bar'), 'wrong password'); |
47
|
|
|
|
48
|
|
|
$user = $this->repository->getByLoginPassword('administrator', 'administrator'); |
49
|
|
|
self::assertNotNull($user); |
50
|
|
|
self::assertSame(1000, $user->getId()); |
51
|
|
|
|
52
|
|
|
$hash = _em()->getConnection()->query('SELECT password FROM `user` WHERE id = 1000')->fetchColumn(); |
53
|
|
|
self::assertStringStartsWith('$', $hash, 'password should have been re-hashed automatically'); |
|
|
|
|
54
|
|
|
self::assertNotSame(md5('administrator'), $hash, 'password should have been re-hashed automatically'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetByLogin(): void |
58
|
|
|
{ |
59
|
|
|
self::assertNull($this->repository->getOneById(1), 'wrong user'); |
60
|
|
|
|
61
|
|
|
$user = $this->repository->getOneById(1000); |
62
|
|
|
self::assertNotNull($user); |
63
|
|
|
self::assertSame(1000, $user->getId()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetAllAdministratorsToNotify(): void |
67
|
|
|
{ |
68
|
|
|
$actual = $this->repository->getAllAdministratorsToNotify(); |
69
|
|
|
self::assertCount(1, $actual); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|