2121class ContestControllerAdminTest extends ContestControllerTest
2222{
2323 protected ?string $ apiUser = 'admin ' ;
24+ protected static string $ testedRole = 'api_contest_change ' ;
2425
2526 private function parseSortYaml (string $ yamlString ): array
2627 {
@@ -29,7 +30,10 @@ private function parseSortYaml(string $yamlString): array
2930 return $ new ;
3031 }
3132
32- public function testAddYaml (): void
33+ /**
34+ * @dataProvider provideAllowedUsers
35+ */
36+ public function testAddYaml (string $ user , array $ newRoles ): void
3337 {
3438 $ yaml = <<<EOF
3539duration: 2:00:00
@@ -69,6 +73,8 @@ public function testAddYaml(): void
6973scoreboard_freeze_duration: 0:30:00
7074EOF ;
7175
76+ $ this ->roles = $ newRoles ;
77+ self ::setUp ();
7278 $ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
7379 $ tempYamlFile = tempnam (sys_get_temp_dir (), "/contest-yaml- " );
7480 file_put_contents ($ tempYamlFile , $ yaml );
@@ -89,7 +95,10 @@ public function testAddYaml(): void
8995 self ::assertNull ($ this ->getContest ($ cid )->getDeactivatetime ());
9096 }
9197
92- public function testAddJson (): void
98+ /**
99+ * @dataProvider provideAllowedUsers
100+ */
101+ public function testAddJson (string $ user , array $ newRoles ): void
93102 {
94103 $ json = <<<EOF
95104{
@@ -103,6 +112,8 @@ public function testAddJson(): void
103112}
104113EOF ;
105114
115+ $ this ->roles = $ newRoles ;
116+ self ::setUp ();
106117 $ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
107118 $ tempJsonFile = tempnam (sys_get_temp_dir (), "/contest-json- " );
108119 file_put_contents ($ tempJsonFile , $ json );
@@ -121,8 +132,13 @@ protected function getContest(int|string $cid): Contest
121132 return static ::getContainer ()->get (EntityManagerInterface::class)->getRepository (Contest::class)->findOneBy (['externalid ' => $ cid ]);
122133 }
123134
124- public function testBannerManagement (): void
135+ /**
136+ * @dataProvider provideAllowedUsers
137+ */
138+ public function testBannerManagement (string $ user , array $ newRoles ): void
125139 {
140+ $ this ->roles = $ newRoles ;
141+ self ::setUp ();
126142 // First, make sure we have no banner
127143 $ id = 1 ;
128144 if ($ this ->objectClassForExternalId !== null ) {
@@ -163,8 +179,13 @@ public function testBannerManagement(): void
163179 self ::assertArrayNotHasKey ('banner ' , $ object );
164180 }
165181
166- public function testProblemsetManagement (): void
182+ /**
183+ * @dataProvider provideAllowedUsers
184+ */
185+ public function testProblemsetManagement (string $ user , array $ newRoles ): void
167186 {
187+ $ this ->roles = $ newRoles ;
188+ self ::setUp ();
168189 // First, make sure we have no problemset document
169190 $ id = 1 ;
170191 if ($ this ->objectClassForExternalId !== null ) {
@@ -233,7 +254,10 @@ public function testChangeTimes(
233254 array $ extraFixtures = [],
234255 bool $ checkUnfreezeTime = false ,
235256 bool $ convertRelativeTimes = false ,
257+ array $ newRoles = [],
236258 ): void {
259+ $ this ->roles = $ newRoles ;
260+ self ::setUp ();
237261 $ this ->loadFixture (DemoPreStartContestFixture::class);
238262 $ this ->loadFixtures ($ extraFixtures );
239263 $ id = 1 ;
@@ -299,14 +323,18 @@ public function provideChangeTimes(): Generator
299323 yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' , 'force ' => true ], 204 , null , [DemoPostUnfreezeContestFixture::class], false , true ];
300324 yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' ], 204 , null , [], false , true ];
301325 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 ' ]];
302330 }
303331
304332 /**
305333 * @dataProvider provideNewContest
306334 */
307335 public function testActivateTimeContestYaml (
308336 string $ activateTime , string $ startTime , ?string $ deactivateTime ,
309- bool $ setActivate , bool $ setDeactivate
337+ bool $ setActivate , bool $ setDeactivate, array $ newRoles = [],
310338 ): void {
311339 $ yaml = <<<EOF
312340duration: 2:00:00
@@ -322,6 +350,8 @@ public function testActivateTimeContestYaml(
322350 id: anothereruption
323351EOF ;
324352
353+ $ this ->roles = $ newRoles ;
354+ self ::setUp ();
325355 if ($ setActivate ) {
326356 $ yaml = "activate_time: " .$ activateTime ."\n" .$ yaml ;
327357 }
0 commit comments