Skip to content

Commit ae65428

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 ae65428

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace App\Tests\Unit\Controller\Team;
44

55
use App\Entity\Problem;
6+
use App\Entity\ContestProblem;
67
use App\Entity\Testcase;
8+
use App\Entity\Contest;
79
use App\Tests\Unit\BaseTestCase;
810
use Doctrine\ORM\EntityManagerInterface;
11+
use App\DataFixtures\Test\DemoAboutToStartContestFixture;
912
use Generator;
1013

1114
class ProblemControllerTest extends BaseTestCase
@@ -183,4 +186,42 @@ 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+
->from(ContestProblem::class, 'cp')
201+
->select('COUNT(cp.contest)')
202+
->where('cp.contest = :contest')
203+
->setParameter('contest', 1)
204+
->getQuery()
205+
->getSingleScalarResult();
206+
207+
$this->withChangedConfiguration('public_access_before_contest', true, function () use ($problemCount) {
208+
$this->client->request('GET', '/public/problems');
209+
static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
210+
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');
211+
212+
for ($i = 1; $i <= $problemCount; $i++) {
213+
$endpoints = [
214+
"/team/problems/{$i}",
215+
"/team/problems/{$i}/statement",
216+
"/team/problems/{$i}/samples.zip"
217+
];
218+
219+
foreach ($endpoints as $endpoint) {
220+
$this->client->request('GET', $endpoint);
221+
$statusCode = $this->client->getResponse()->getStatusCode();
222+
static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}");
223+
}
224+
}
225+
});
226+
}
186227
}

0 commit comments

Comments
 (0)