Skip to content

Commit c8bfada

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 c8bfada

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
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;
10+
use App\DataFixtures\Test\DemoAboutToStartContestFixture;
911
use Generator;
1012

1113
class ProblemControllerTest extends BaseTestCase
@@ -183,4 +185,32 @@ public function testInteractiveSamples(): void
183185
$response = $this->client->getResponse();
184186
self::assertEquals(404, $response->getStatusCode());
185187
}
188+
189+
/**
190+
* Test that the problems page does not show page, statement, sample data before contest start.
191+
*/
192+
public function testAccessProblemBeforeContestStarts(): void
193+
{
194+
$this->loadFixtures([DemoAboutToStartContestFixture::class]);
195+
196+
$this->withChangedConfiguration('public_access_before_contest', true, function () {
197+
$this->client->request('GET', '/public/problems');
198+
static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
199+
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');
200+
201+
for ($i = 1; $i <= 3; $i++) {
202+
$endpoints = [
203+
"/team/problems/{$i}",
204+
"/team/problems/{$i}/statement",
205+
"/team/problems/{$i}/samples.zip"
206+
];
207+
208+
foreach ($endpoints as $endpoint) {
209+
$this->client->request('GET', $endpoint);
210+
$statusCode = $this->client->getResponse()->getStatusCode();
211+
static::assertSame(404, $statusCode, "Expected status code 404, got {$statusCode} for {$endpoint}");
212+
}
213+
}
214+
});
215+
}
186216
}

0 commit comments

Comments
 (0)