Skip to content

Commit a829a31

Browse files
as6325400vmcj
authored andcommitted
add unittest to test that the problems page does not show page, statement, sample data before contest start.
1 parent fb67ba7 commit a829a31

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+
$problems = $em->createQueryBuilder()
200+
->select('p.probid')
201+
->from(ContestProblem::class, 'cp')
202+
->join('cp.problem', 'p')
203+
->join('cp.contest', 'c')
204+
->where('c.shortname = :shortname')
205+
->setParameter('shortname', 'demo')
206+
->getQuery()
207+
->getResult();
208+
$probids = array_column($problems, 'probid');
209+
210+
$this->client->request('GET', '/public/problems');
211+
static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
212+
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');
213+
214+
foreach ($probids as $id) {
215+
$endpoints = [
216+
"/team/problems/{$id}",
217+
"/team/problems/{$id}/statement",
218+
"/team/problems/{$id}/samples.zip"
219+
];
220+
221+
foreach ($endpoints as $endpoint) {
222+
$this->client->request('GET', $endpoint);
223+
$statusCode = $this->client->getResponse()->getStatusCode();
224+
static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}");
225+
}
226+
}
227+
}
186228
}

0 commit comments

Comments
 (0)