|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\DBAL\Types\ProductTypeType; |
|
8
|
|
|
use Application\Model\Organization; |
|
9
|
|
|
use Application\Repository\OrganizationRepository; |
|
10
|
|
|
|
|
11
|
|
|
class OrganizationRepositoryTest extends AbstractRepositoryTest |
|
12
|
|
|
{ |
|
13
|
|
|
private OrganizationRepository $repository; |
|
14
|
|
|
|
|
15
|
|
|
protected function setUp(): void |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
$this->repository = _em()->getRepository(Organization::class); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @dataProvider providerApplyOrganizationAccesses |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testApplyOrganizationAccesses(array $users): void |
|
25
|
|
|
{ |
|
26
|
|
|
// Insert all test users |
|
27
|
|
|
$connection = $this->getEntityManager()->getConnection(); |
|
28
|
|
|
foreach ($users as $email => $data) { |
|
29
|
|
|
$user = $data[0]; |
|
30
|
|
|
$user['email'] = $email; |
|
31
|
|
|
$connection->delete('user', ['email' => $email]); |
|
32
|
|
|
$connection->insert('user', $user); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$this->repository->applyOrganizationAccesses(); |
|
36
|
|
|
|
|
37
|
|
|
// Assert each user |
|
38
|
|
|
foreach ($users as $email => $data) { |
|
39
|
|
|
$sql = 'SELECT subscription_last_review_id, subscription_type FROM user WHERE user.email = :email'; |
|
40
|
|
|
$actual = $connection->fetchAssoc($sql, ['email' => $email]); |
|
41
|
|
|
|
|
42
|
|
|
self::assertEquals($data[1], $actual); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function providerApplyOrganizationAccesses(): array |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'no matching org, no subscription' => [ |
|
50
|
|
|
[ |
|
51
|
|
|
'[email protected]' => [ |
|
52
|
|
|
['subscription_last_review_id' => null, 'subscription_type' => null], |
|
53
|
|
|
['subscription_last_review_id' => null, 'subscription_type' => null], |
|
54
|
|
|
], |
|
55
|
|
|
], |
|
56
|
|
|
], |
|
57
|
|
|
'no matching org, with subscription' => [ |
|
58
|
|
|
[ |
|
59
|
|
|
'[email protected]' => [ |
|
60
|
|
|
['subscription_last_review_id' => 3001, 'subscription_type' => ProductTypeType::DIGITAL], |
|
61
|
|
|
['subscription_last_review_id' => 3001, 'subscription_type' => ProductTypeType::DIGITAL], |
|
62
|
|
|
], |
|
63
|
|
|
], |
|
64
|
|
|
], |
|
65
|
|
|
'matching org, no subscription' => [ |
|
66
|
|
|
[ |
|
67
|
|
|
'[email protected]' => [ |
|
68
|
|
|
['subscription_last_review_id' => null, 'subscription_type' => null], |
|
69
|
|
|
['subscription_last_review_id' => 3000, 'subscription_type' => ProductTypeType::DIGITAL], |
|
70
|
|
|
], |
|
71
|
|
|
], |
|
72
|
|
|
], |
|
73
|
|
|
'matching org, with subscription should upgrade type' => [ |
|
74
|
|
|
[ |
|
75
|
|
|
'[email protected]' => [ |
|
76
|
|
|
['subscription_last_review_id' => 3000, 'subscription_type' => ProductTypeType::PAPER], |
|
77
|
|
|
['subscription_last_review_id' => 3000, 'subscription_type' => ProductTypeType::BOTH], |
|
78
|
|
|
], |
|
79
|
|
|
], |
|
80
|
|
|
], |
|
81
|
|
|
'matching better org, with subscription should upgrade everything' => [ |
|
82
|
|
|
[ |
|
83
|
|
|
'[email protected]' => [ |
|
84
|
|
|
['subscription_last_review_id' => 3000, 'subscription_type' => ProductTypeType::PAPER], |
|
85
|
|
|
['subscription_last_review_id' => 3001, 'subscription_type' => ProductTypeType::BOTH], |
|
86
|
|
|
], |
|
87
|
|
|
], |
|
88
|
|
|
], |
|
89
|
|
|
'matching worse org, with subscription should not downgrade' => [ |
|
90
|
|
|
[ |
|
91
|
|
|
'[email protected]' => [ |
|
92
|
|
|
['subscription_last_review_id' => 3001, 'subscription_type' => ProductTypeType::DIGITAL], |
|
93
|
|
|
['subscription_last_review_id' => 3001, 'subscription_type' => ProductTypeType::DIGITAL], |
|
94
|
|
|
], |
|
95
|
|
|
], |
|
96
|
|
|
], |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|