Skip to content

Commit

Permalink
add unittest to test that the problems page does not show page, state…
Browse files Browse the repository at this point in the history
…ment, sample data before contest start.
  • Loading branch information
as6325400 committed Oct 27, 2024
1 parent 2d6f4ff commit ae65428
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions webapp/tests/Unit/Controller/Team/ProblemControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace App\Tests\Unit\Controller\Team;

use App\Entity\Problem;
use App\Entity\ContestProblem;
use App\Entity\Testcase;
use App\Entity\Contest;
use App\Tests\Unit\BaseTestCase;
use Doctrine\ORM\EntityManagerInterface;
use App\DataFixtures\Test\DemoAboutToStartContestFixture;
use Generator;

class ProblemControllerTest extends BaseTestCase
Expand Down Expand Up @@ -183,4 +186,42 @@ 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);
$problemCount = $em->createQueryBuilder()
->from(ContestProblem::class, 'cp')
->select('COUNT(cp.contest)')
->where('cp.contest = :contest')
->setParameter('contest', 1)
->getQuery()
->getSingleScalarResult();

$this->withChangedConfiguration('public_access_before_contest', true, function () use ($problemCount) {
$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.');

for ($i = 1; $i <= $problemCount; $i++) {
$endpoints = [
"/team/problems/{$i}",
"/team/problems/{$i}/statement",
"/team/problems/{$i}/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}");
}
}
});
}
}

0 comments on commit ae65428

Please sign in to comment.