Skip to content

Commit c9fc4a4

Browse files
committed
add unittest to test that the problems page does not show page, statement, sample data before contest start.
1 parent 2d6f4ff commit c9fc4a4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\Problem;
66
use App\Entity\Testcase;
7+
use App\Entity\Contest;
78
use App\Tests\Unit\BaseTestCase;
89
use Doctrine\ORM\EntityManagerInterface;
910
use Generator;
@@ -183,4 +184,41 @@ public function testInteractiveSamples(): void
183184
$response = $this->client->getResponse();
184185
self::assertEquals(404, $response->getStatusCode());
185186
}
187+
188+
/**
189+
* Test that the problems page does not show page, statement, sample data before contest start.
190+
*/
191+
public function testAccessProblemBeforeContestStarts(): void
192+
{
193+
/** @var EntityManagerInterface $em */
194+
$em = self::getContainer()->get(EntityManagerInterface::class);
195+
196+
$contest = $em->getRepository(Contest::class)->findOneBy(['shortname' => 'demo']);
197+
$originalStartTime = $contest->getStarttimeString();
198+
199+
$lastSpacePosition = strrpos($originalStartTime, ' ');
200+
$datetime = substr($originalStartTime, 0, $lastSpacePosition);
201+
$timezone = substr($originalStartTime, $lastSpacePosition + 1);
202+
$contest->setStarttimeString(date('Y-m-d H:i:s', strtotime('+3600 seconds', strtotime($datetime))) . ' ' . $timezone)->updateTimes();
203+
204+
$this->withChangedConfiguration('public_access_before_contest', true, function () {
205+
$this->client->request('GET', '/public/problems');
206+
static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
207+
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');
208+
209+
for ($i = 1; $i <= 3; $i++) {
210+
$endpoints = [
211+
"/team/problems/{$i}/statement",
212+
"/team/problems/{$i}/samples.zip"
213+
];
214+
215+
foreach ($endpoints as $endpoint) {
216+
$this->client->request('GET', $endpoint);
217+
$statusCode = $this->client->getResponse()->getStatusCode();
218+
static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}");
219+
}
220+
}
221+
});
222+
$contest->setStarttimeString($originalStartTime)->updateTimes();
223+
}
186224
}

0 commit comments

Comments
 (0)