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