mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-10 09:30:14 +02:00
b1f68425cd
- Scope AbstractControllerWebTestCase::getCandidate/getQuizByName by season code (both Candidate and Quiz are only unique per season, not system-wide) and add a CandidateRepository regression test guarding against same-named candidates in different seasons - Add missing entityManager->clear() before verifying DB state after a POST in PrepareEliminationControllerTest and QuestionBankControllerTest - Add non-owner denial tests for BackofficeController::exportQuiz and QuizQuestionController::edit/reorder, which had IsGranted checks with no test coverage
57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Tests\Controller\Backoffice;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Tvdt\Controller\Backoffice\BackofficeController;
|
|
use Tvdt\Tests\Controller\AbstractControllerWebTestCase;
|
|
|
|
#[CoversClass(BackofficeController::class)]
|
|
final class BackofficeControllerTest extends AbstractControllerWebTestCase
|
|
{
|
|
public function testExportQuizFilenameIsSanitized(): void
|
|
{
|
|
$user = $this->getUserByEmail('user2@example.org');
|
|
$user->isVerified = true;
|
|
|
|
$this->entityManager->flush();
|
|
$this->client->loginUser($user);
|
|
|
|
$quiz = $this->getQuizByName('Quiz 1');
|
|
|
|
$this->client->request(Request::METHOD_GET, \sprintf('/backoffice/quiz/%s/export', $quiz->id));
|
|
|
|
self::assertResponseIsSuccessful();
|
|
$disposition = (string) $this->client->getResponse()->headers->get('Content-Disposition');
|
|
$this->assertStringContainsString('filename=Quiz-1.xlsx', $disposition);
|
|
$this->assertStringNotContainsString('Quiz 1.xlsx', $disposition);
|
|
}
|
|
|
|
public function testExportQuizRequiresVerifiedEmail(): void
|
|
{
|
|
$user = $this->getUserByEmail('user2@example.org');
|
|
$this->assertFalse($user->isVerified);
|
|
$this->client->loginUser($user);
|
|
|
|
$quiz = $this->getQuizByName('Quiz 1');
|
|
|
|
$this->client->request(Request::METHOD_GET, \sprintf('/backoffice/quiz/%s/export', $quiz->id));
|
|
|
|
self::assertResponseRedirects(\sprintf('/backoffice/season/%s', $quiz->season->seasonCode));
|
|
}
|
|
|
|
public function testExportQuizIsDeniedForNonOwner(): void
|
|
{
|
|
$this->loginAs('test@example.org');
|
|
|
|
$quiz = $this->getQuizByName('Quiz 1');
|
|
|
|
$this->client->request(Request::METHOD_GET, \sprintf('/backoffice/quiz/%s/export', $quiz->id));
|
|
|
|
self::assertResponseStatusCodeSame(403);
|
|
}
|
|
}
|