@@ -29,7 +29,10 @@ private function parseSortYaml(string $yamlString): array
29
29
return $ new ;
30
30
}
31
31
32
- public function testAddYaml (): void
32
+ /**
33
+ * @dataProvider provideAllowedUsers
34
+ */
35
+ public function testAddYaml (string $ user , array $ newRoles ): void
33
36
{
34
37
$ yaml = <<<EOF
35
38
duration: 2:00:00
@@ -69,6 +72,8 @@ public function testAddYaml(): void
69
72
scoreboard_freeze_duration: 0:30:00
70
73
EOF ;
71
74
75
+ $ this ->roles = $ newRoles ;
76
+ self ::setUp ();
72
77
$ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
73
78
$ tempYamlFile = tempnam (sys_get_temp_dir (), "/contest-yaml- " );
74
79
file_put_contents ($ tempYamlFile , $ yaml );
@@ -89,7 +94,10 @@ public function testAddYaml(): void
89
94
self ::assertNull ($ this ->getContest ($ cid )->getDeactivatetime ());
90
95
}
91
96
92
- public function testAddJson (): void
97
+ /**
98
+ * @dataProvider provideAllowedUsers
99
+ */
100
+ public function testAddJson (string $ user , array $ newRoles ): void
93
101
{
94
102
$ json = <<<EOF
95
103
{
@@ -103,6 +111,8 @@ public function testAddJson(): void
103
111
}
104
112
EOF ;
105
113
114
+ $ this ->roles = $ newRoles ;
115
+ self ::setUp ();
106
116
$ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
107
117
$ tempJsonFile = tempnam (sys_get_temp_dir (), "/contest-json- " );
108
118
file_put_contents ($ tempJsonFile , $ json );
@@ -121,8 +131,13 @@ protected function getContest(int|string $cid): Contest
121
131
return static ::getContainer ()->get (EntityManagerInterface::class)->getRepository (Contest::class)->findOneBy (['externalid ' => $ cid ]);
122
132
}
123
133
124
- public function testBannerManagement (): void
134
+ /**
135
+ * @dataProvider provideAllowedUsers
136
+ */
137
+ public function testBannerManagement (string $ user , array $ newRoles ): void
125
138
{
139
+ $ this ->roles = $ newRoles ;
140
+ self ::setUp ();
126
141
// First, make sure we have no banner
127
142
$ id = 1 ;
128
143
if ($ this ->objectClassForExternalId !== null ) {
@@ -163,8 +178,13 @@ public function testBannerManagement(): void
163
178
self ::assertArrayNotHasKey ('banner ' , $ object );
164
179
}
165
180
166
- public function testProblemsetManagement (): void
181
+ /**
182
+ * @dataProvider provideAllowedUsers
183
+ */
184
+ public function testProblemsetManagement (string $ user , array $ newRoles ): void
167
185
{
186
+ $ this ->roles = $ newRoles ;
187
+ self ::setUp ();
168
188
// First, make sure we have no problemset document
169
189
$ id = 1 ;
170
190
if ($ this ->objectClassForExternalId !== null ) {
@@ -233,7 +253,10 @@ public function testChangeTimes(
233
253
array $ extraFixtures = [],
234
254
bool $ checkUnfreezeTime = false ,
235
255
bool $ convertRelativeTimes = false ,
256
+ array $ newRoles = [],
236
257
): void {
258
+ $ this ->roles = $ newRoles ;
259
+ self ::setUp ();
237
260
$ this ->loadFixture (DemoPreStartContestFixture::class);
238
261
$ this ->loadFixtures ($ extraFixtures );
239
262
$ id = 1 ;
@@ -299,14 +322,18 @@ public function provideChangeTimes(): Generator
299
322
yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' , 'force ' => true ], 204 , null , [DemoPostUnfreezeContestFixture::class], false , true ];
300
323
yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' ], 204 , null , [], false , true ];
301
324
yield [['id ' => 1 , 'scoreboard_thaw_time ' => '-15 seconds ' ], 200 , 'Demo contest ' , [], true , true ];
325
+
326
+ // Show that this works for both roles
327
+ yield [['id ' => 1 , 'scoreboard_thaw_time ' => '-14 seconds ' ], 200 , 'Demo contest ' , [], true , true , ['admin ' ]];
328
+ yield [['id ' => 1 , 'scoreboard_thaw_time ' => '-13 seconds ' ], 200 , 'Demo contest ' , [], true , true , ['api_contest_change ' ]];
302
329
}
303
330
304
331
/**
305
332
* @dataProvider provideNewContest
306
333
*/
307
334
public function testActivateTimeContestYaml (
308
335
string $ activateTime , string $ startTime , ?string $ deactivateTime ,
309
- bool $ setActivate , bool $ setDeactivate
336
+ bool $ setActivate , bool $ setDeactivate, array $ newRoles = [],
310
337
): void {
311
338
$ yaml = <<<EOF
312
339
duration: 2:00:00
@@ -322,6 +349,8 @@ public function testActivateTimeContestYaml(
322
349
id: anothereruption
323
350
EOF ;
324
351
352
+ $ this ->roles = $ newRoles ;
353
+ self ::setUp ();
325
354
if ($ setActivate ) {
326
355
$ yaml = "activate_time: " .$ activateTime ."\n" .$ yaml ;
327
356
}
0 commit comments