From 857338ee1e0627c7dd76faea23080dcf20723d08 Mon Sep 17 00:00:00 2001 From: as6325400 Date: Fri, 25 Oct 2024 01:32:02 +0800 Subject: [PATCH] add unittest to test that the problems page does not show page, statement, sample data before contest start. --- .../Controller/Team/ProblemControllerTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/webapp/tests/Unit/Controller/Team/ProblemControllerTest.php b/webapp/tests/Unit/Controller/Team/ProblemControllerTest.php index 1817a6136c..aecb994012 100644 --- a/webapp/tests/Unit/Controller/Team/ProblemControllerTest.php +++ b/webapp/tests/Unit/Controller/Team/ProblemControllerTest.php @@ -2,6 +2,9 @@ namespace App\Tests\Unit\Controller\Team; +use App\DataFixtures\Test\DemoAboutToStartContestFixture; +use App\Entity\Contest; +use App\Entity\ContestProblem; use App\Entity\Problem; use App\Entity\Testcase; use App\Tests\Unit\BaseTestCase; @@ -183,4 +186,43 @@ public function testInteractiveSamples(): void $response = $this->client->getResponse(); self::assertEquals(404, $response->getStatusCode()); } + + /** + * Test that the problems page does not show page, statement, sample data before contest start. + */ + public function testAccessProblemBeforeContestStarts(): void + { + $this->loadFixtures([DemoAboutToStartContestFixture::class]); + + /** @var EntityManagerInterface $em */ + $em = self::getContainer()->get(EntityManagerInterface::class); + $problems = $em->createQueryBuilder() + ->select('p.probid') + ->from(ContestProblem::class, 'cp') + ->join('cp.problem', 'p') + ->join('cp.contest', 'c') + ->where('c.shortname = :shortname') + ->setParameter('shortname', 'demo') + ->getQuery() + ->getResult(); + $probids = array_column($problems, 'probid'); + + $this->client->request('GET', '/public/problems'); + static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems'); + static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.'); + + foreach ($probids as $id) { + $endpoints = [ + "/team/problems/{$id}", + "/team/problems/{$id}/statement", + "/team/problems/{$id}/samples.zip" + ]; + + foreach ($endpoints as $endpoint) { + $this->client->request('GET', $endpoint); + $statusCode = $this->client->getResponse()->getStatusCode(); + static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}"); + } + } + } }