35
35
use Civi \Funding \Fixtures \FundingProgramFixture ;
36
36
use Civi \Funding \Fixtures \GroupContactFixture ;
37
37
use Civi \Funding \Fixtures \GroupFixture ;
38
+ use Civi \Funding \Permission \ContactRelation \Types \ContactTypeAndGroup ;
39
+ use Civi \Funding \Permission \ContactRelation \Types \Relationship as RelationshipType ;
38
40
39
41
/**
40
42
* @covers \Civi\Funding\EventSubscriber\FundingCase\FundingCasePermissionsCacheClearSubscriber
@@ -107,14 +109,15 @@ public function testOnPreGroup(): void {
107
109
108
110
$ group1 = GroupFixture::addFixture ();
109
111
$ group2 = GroupFixture::addFixture ();
112
+ $ group3 = GroupFixture::addFixture ();
110
113
111
114
$ fundingCase = FundingCaseFixture::addFixture (
112
115
$ fundingProgram ->getId (),
113
116
$ fundingCaseType ->getId (),
114
117
$ contact ['id ' ],
115
118
$ contact ['id ' ]
116
119
);
117
- FundingCaseContactRelationFixture::addFixture ($ fundingCase ->getId (), Relationship:: getEntityName () , [
120
+ FundingCaseContactRelationFixture::addFixture ($ fundingCase ->getId (), RelationshipType:: NAME , [
118
121
'relationshipTypeIds ' => [],
119
122
'contactTypeIds ' => [],
120
123
'groupIds ' => [$ group1 ['id ' ]],
@@ -146,6 +149,16 @@ public function testOnPreGroup(): void {
146
149
// Deleting group should affect cache.
147
150
Group::delete (FALSE )->addWhere ('id ' , '= ' , $ group1 ['id ' ])->execute ();
148
151
static ::assertNull (FundingCasePermissionsCache::get (FALSE )->execute ()->single ()['permissions ' ]);
152
+
153
+ // Deleting group should affect cache when there is no group restriction.
154
+ FundingCaseContactRelationFixture::addFixture ($ fundingCase ->getId (), ContactTypeAndGroup::NAME , [
155
+ 'contactTypeIds ' => [],
156
+ 'groupIds ' => [],
157
+ ], ['permission ' ]);
158
+ FundingCasePermissionsCache::delete (FALSE )->addWhere ('id ' , 'IS NOT NULL ' )->execute ();
159
+ FundingCasePermissionsCacheFixture::add ($ fundingCase ->getId (), $ contact ['id ' ], FALSE , ['test ' ]);
160
+ Group::delete (FALSE )->addWhere ('id ' , '= ' , $ group3 ['id ' ])->execute ();
161
+ static ::assertNull (FundingCasePermissionsCache::get (FALSE )->execute ()->single ()['permissions ' ]);
149
162
}
150
163
151
164
public function testOnPreGroupContact (): void {
@@ -156,6 +169,7 @@ public function testOnPreGroupContact(): void {
156
169
157
170
$ group1 = GroupFixture::addFixture ();
158
171
$ group2 = GroupFixture::addFixture ();
172
+ $ group3 = GroupFixture::addFixture ();
159
173
160
174
$ fundingCase1 = FundingCaseFixture::addFixture (
161
175
$ fundingProgram ->getId (),
@@ -169,12 +183,12 @@ public function testOnPreGroupContact(): void {
169
183
$ contact1 ['id ' ],
170
184
$ contact1 ['id ' ]
171
185
);
172
- FundingCaseContactRelationFixture::addFixture ($ fundingCase1 ->getId (), Relationship:: getEntityName () , [
186
+ FundingCaseContactRelationFixture::addFixture ($ fundingCase1 ->getId (), RelationshipType:: NAME , [
173
187
'relationshipTypeIds ' => [],
174
188
'contactTypeIds ' => [],
175
189
'groupIds ' => [$ group1 ['id ' ]],
176
190
], ['permission ' ]);
177
- FundingCaseContactRelationFixture::addFixture ($ fundingCase2 ->getId (), Relationship:: getEntityName () , [
191
+ FundingCaseContactRelationFixture::addFixture ($ fundingCase2 ->getId (), RelationshipType:: NAME , [
178
192
'relationshipTypeIds ' => [],
179
193
'contactTypeIds ' => [],
180
194
'groupIds ' => [$ group2 ['id ' ]],
@@ -207,6 +221,16 @@ public function testOnPreGroupContact(): void {
207
221
GroupContact::update (FALSE )->setValues ($ groupContact )->execute ();
208
222
209
223
static ::assertSame ([NULL , NULL ], FundingCasePermissionsCache::get (FALSE )->execute ()->column ('permissions ' ));
224
+
225
+ // Adding GroupContact should affect cache when there is no group restriction.
226
+ FundingCaseContactRelationFixture::addFixture ($ fundingCase1 ->getId (), ContactTypeAndGroup::NAME , [
227
+ 'contactTypeIds ' => [],
228
+ 'groupIds ' => [],
229
+ ], ['permission ' ]);
230
+ FundingCasePermissionsCache::delete (FALSE )->addWhere ('id ' , 'IS NOT NULL ' )->execute ();
231
+ FundingCasePermissionsCacheFixture::add ($ fundingCase1 ->getId (), $ contact1 ['id ' ], FALSE , ['test ' ]);
232
+ GroupContactFixture::addFixtureWithGroupId ($ group1 ['id ' ], $ contact1 ['id ' ]);
233
+ static ::assertNull (FundingCasePermissionsCache::get (FALSE )->execute ()->single ()['permissions ' ]);
210
234
}
211
235
212
236
public function testOnPreFundingCaseContactRelation (): void {
0 commit comments