Skip to content

Commit 0e12edd

Browse files
committed
add unittest to test that the problems page does not show page, statement, sample data before contest start.
1 parent 68438a6 commit 0e12edd

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

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

Lines changed: 38 additions & 1 deletion
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,40 @@ public function testInteractiveSamples(): void
183184
$response = $this->client->getResponse();
184185
self::assertEquals(404, $response->getStatusCode());
185186
}
186-
}
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+
203+
$date = new \DateTime($datetime, new \DateTimeZone($timezone));
204+
$date->modify('+1 hour');
205+
$newTimeString = $date->format('Y-m-d H:i:s') . ' ' . $timezone;
206+
$contest->setStarttimeString($newTimeString)->updateTimes();
207+
208+
$this->withChangedConfiguration('public_access_before_contest', true, function () {
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+
$this->client->request('GET', '/team/problems/2/statement');
214+
$statusCode = $this->client->getResponse()->getStatusCode();
215+
static::assertSame(404, $statusCode, 'Expected status code 404, got ' . $statusCode);
216+
217+
$this->client->request('GET', '/team/problems/2/samples.zip');
218+
$statusCode = $this->client->getResponse()->getStatusCode();
219+
static::assertSame(404, $statusCode, 'Expected status code 404, got ' . $statusCode);
220+
});
221+
$contest->setStarttimeString($originalStartTime)->updateTimes();
222+
}
223+
}

0 commit comments

Comments
 (0)