Skip to content

Commit 38b4ab7

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 38b4ab7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace App\Tests\Unit\Controller\Team;
44

5+
use App\DataFixtures\Test\DemoAboutToStartContestFixture;
6+
use App\Entity\Contest;
7+
use App\Entity\ContestProblem;
58
use App\Entity\Problem;
69
use App\Entity\Testcase;
710
use App\Tests\Unit\BaseTestCase;
@@ -183,4 +186,43 @@ public function testInteractiveSamples(): void
183186
$response = $this->client->getResponse();
184187
self::assertEquals(404, $response->getStatusCode());
185188
}
189+
190+
/**
191+
* Test that the problems page does not show page, statement, sample data before contest start.
192+
*/
193+
public function testAccessProblemBeforeContestStarts(): void
194+
{
195+
$this->loadFixtures([DemoAboutToStartContestFixture::class]);
196+
197+
/** @var EntityManagerInterface $em */
198+
$em = self::getContainer()->get(EntityManagerInterface::class);
199+
$problemCount = $em->createQueryBuilder()
200+
->select('COUNT(cp.problem)')
201+
->from(ContestProblem::class, 'cp')
202+
->join('cp.contest', 'c')
203+
->where('c.shortname = :shortname')
204+
->setParameter('shortname', 'demo')
205+
->getQuery()
206+
->getSingleScalarResult();
207+
208+
$this->withChangedConfiguration('public_access_before_contest', true, function () use ($problemCount) {
209+
$this->client->request('GET', '/public/problems');
210+
static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
211+
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');
212+
213+
for ($i = 1; $i <= $problemCount; $i++) {
214+
$endpoints = [
215+
"/team/problems/{$i}",
216+
"/team/problems/{$i}/statement",
217+
"/team/problems/{$i}/samples.zip"
218+
];
219+
220+
foreach ($endpoints as $endpoint) {
221+
$this->client->request('GET', $endpoint);
222+
$statusCode = $this->client->getResponse()->getStatusCode();
223+
static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}");
224+
}
225+
}
226+
});
227+
}
186228
}

0 commit comments

Comments
 (0)