Skip to content

Commit 25add0b

Browse files
committed
Add utility function to check page response and follow redirect.
Fixes #3068
1 parent c3ca09e commit 25add0b

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

webapp/tests/Unit/BaseTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,13 @@ protected function setupShadowMode(bool $shadowMode): void
318318
$dj = self::getContainer()->get(DOMJudgeService::class);
319319
$config->saveChanges(['shadow_mode'=>$shadowMode], $eventLog, $dj, treatMissingBooleansAsFalse: false);
320320
}
321+
322+
protected function checkStatusAndFollowRedirect(): Crawler
323+
{
324+
static::assertLessThan(
325+
400, $this->client->getInternalResponse()->getStatusCode(),
326+
$this->client->getInternalResponse()->getContent()
327+
);
328+
return $this->client->followRedirect();
329+
}
321330
}

webapp/tests/Unit/Controller/Jury/ClarificationControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testClarificationRequestComposeForm(): void
111111
'jury_clarification[message]' => 'This is a clarification',
112112
]);
113113

114-
$this->client->followRedirect();
114+
$this->checkStatusAndFollowRedirect();
115115

116116
self::assertSelectorTextContains('div.col-sm strong', 'All');
117117
self::assertSelectorTextContains('span.clarification-subject',

webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,8 @@ public function testCheckAddEntityAdmin(array $element, array $expected): void
299299
$this->logIn();
300300
$this->verifyPageResponse('GET', static::$baseUrl, 200);
301301
if (static::$add !== '') {
302-
$response = $this->helperSubmitFields($element);
303-
static::assertLessThan(400, $this->client->getInternalResponse()->getStatusCode(),
304-
$this->client->getInternalResponse()->getContent());
305-
$this->client->followRedirect();
302+
$this->helperSubmitFields($element);
303+
$this->checkStatusAndFollowRedirect();
306304
foreach ($element as $key => $value) {
307305
if (!is_array($value) && !in_array($key, static::$overviewSingleNotShown)) {
308306
self::assertSelectorExists('body:contains("' . $value . '")');

webapp/tests/Unit/Controller/Jury/TeamControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testAddWithoutUserThenEdit(): void
105105
$this->logIn();
106106
$this->verifyPageResponse('GET', static::$baseUrl, 200);
107107
$this->helperSubmitFields($teamToAdd);
108-
$viewPage = $this->client->followRedirect()->getUri();
108+
$viewPage = $this->checkStatusAndFollowRedirect()->getUri();
109109
$editPage = $viewPage . static::$edit;
110110
$this->verifyPageResponse('GET', $editPage, 200);
111111
$formFields = [

webapp/tests/Unit/Controller/Team/MiscControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testChangeContest(bool $withReferrer): void
162162
// $this->client->request('GET', '/team/change-contest/' . $contest->getCid());
163163
// }
164164
//
165-
// $this->client->followRedirect();
165+
// $this->client->checkStatusAndFollowRedirect();
166166
//
167167
// // Check that we are still on the scoreboard.
168168
// if ($withReferrer) {

0 commit comments

Comments
 (0)