@@ -29,7 +29,10 @@ private function parseSortYaml(string $yamlString): array
2929 return $ new ;
3030 }
3131
32- public function testAddYaml (): void
32+ /**
33+ * @dataProvider provideAllowedUsers
34+ */
35+ public function testAddYaml (string $ user , array $ newRoles ): void
3336 {
3437 $ yaml = <<<EOF
3538duration: 2:00:00
@@ -69,6 +72,8 @@ public function testAddYaml(): void
6972scoreboard_freeze_duration: 0:30:00
7073EOF ;
7174
75+ $ this ->roles = $ newRoles ;
76+ self ::setUp ();
7277 $ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
7378 $ tempYamlFile = tempnam (sys_get_temp_dir (), "/contest-yaml- " );
7479 file_put_contents ($ tempYamlFile , $ yaml );
@@ -89,7 +94,10 @@ public function testAddYaml(): void
8994 self ::assertNull ($ this ->getContest ($ cid )->getDeactivatetime ());
9095 }
9196
92- public function testAddJson (): void
97+ /**
98+ * @dataProvider provideAllowedUsers
99+ */
100+ public function testAddJson (string $ user , array $ newRoles ): void
93101 {
94102 $ json = <<<EOF
95103{
@@ -103,6 +111,8 @@ public function testAddJson(): void
103111}
104112EOF ;
105113
114+ $ this ->roles = $ newRoles ;
115+ self ::setUp ();
106116 $ url = $ this ->helperGetEndpointURL ($ this ->apiEndpoint );
107117 $ tempJsonFile = tempnam (sys_get_temp_dir (), "/contest-json- " );
108118 file_put_contents ($ tempJsonFile , $ json );
@@ -121,8 +131,13 @@ protected function getContest(int|string $cid): Contest
121131 return static ::getContainer ()->get (EntityManagerInterface::class)->getRepository (Contest::class)->findOneBy (['externalid ' => $ cid ]);
122132 }
123133
124- public function testBannerManagement (): void
134+ /**
135+ * @dataProvider provideAllowedUsers
136+ */
137+ public function testBannerManagement (string $ user , array $ newRoles ): void
125138 {
139+ $ this ->roles = $ newRoles ;
140+ self ::setUp ();
126141 // First, make sure we have no banner
127142 $ id = 1 ;
128143 if ($ this ->objectClassForExternalId !== null ) {
@@ -163,8 +178,13 @@ public function testBannerManagement(): void
163178 self ::assertArrayNotHasKey ('banner ' , $ object );
164179 }
165180
166- public function testProblemsetManagement (): void
181+ /**
182+ * @dataProvider provideAllowedUsers
183+ */
184+ public function testProblemsetManagement (string $ user , array $ newRoles ): void
167185 {
186+ $ this ->roles = $ newRoles ;
187+ self ::setUp ();
168188 // First, make sure we have no problemset document
169189 $ id = 1 ;
170190 if ($ this ->objectClassForExternalId !== null ) {
@@ -233,7 +253,10 @@ public function testChangeTimes(
233253 array $ extraFixtures = [],
234254 bool $ checkUnfreezeTime = false ,
235255 bool $ convertRelativeTimes = false ,
256+ array $ newRoles = [],
236257 ): void {
258+ $ this ->roles = $ newRoles ;
259+ self ::setUp ();
237260 $ this ->loadFixture (DemoPreStartContestFixture::class);
238261 $ this ->loadFixtures ($ extraFixtures );
239262 $ id = 1 ;
@@ -299,14 +322,18 @@ public function provideChangeTimes(): Generator
299322 yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' , 'force ' => true ], 204 , null , [DemoPostUnfreezeContestFixture::class], false , true ];
300323 yield [['id ' => 1 , 'scoreboard_thaw_time ' => '+15 seconds ' ], 204 , null , [], false , true ];
301324 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 ' ]];
302329 }
303330
304331 /**
305332 * @dataProvider provideNewContest
306333 */
307334 public function testActivateTimeContestYaml (
308335 string $ activateTime , string $ startTime , ?string $ deactivateTime ,
309- bool $ setActivate , bool $ setDeactivate
336+ bool $ setActivate , bool $ setDeactivate, array $ newRoles = [],
310337 ): void {
311338 $ yaml = <<<EOF
312339duration: 2:00:00
@@ -322,6 +349,8 @@ public function testActivateTimeContestYaml(
322349 id: anothereruption
323350EOF ;
324351
352+ $ this ->roles = $ newRoles ;
353+ self ::setUp ();
325354 if ($ setActivate ) {
326355 $ yaml = "activate_time: " .$ activateTime ."\n" .$ yaml ;
327356 }
0 commit comments