mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 04:44:19 +01:00
This commit introduces the ability to clear quiz results and delete quizzes directly from the backoffice. It includes new routes, controllers, modals for user confirmation, and updates to translations. The `QuizRepository` now supports dedicated methods for clearing results and deleting quizzes along with error handling. Related database migrations and front-end adjustments are also included.
78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Security\Voter;
|
|
|
|
use App\Entity\Answer;
|
|
use App\Entity\Candidate;
|
|
use App\Entity\Elimination;
|
|
use App\Entity\Question;
|
|
use App\Entity\Quiz;
|
|
use App\Entity\Season;
|
|
use App\Entity\User;
|
|
use App\Security\Voter\SeasonVoter;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\MockObject\Stub;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
|
|
|
final class SeasonVoterTest extends TestCase
|
|
{
|
|
private SeasonVoter $seasonVoter;
|
|
|
|
private TokenInterface&Stub $token;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->seasonVoter = new SeasonVoter();
|
|
$this->token = $this->createStub(TokenInterface::class);
|
|
|
|
$user = $this->createStub(User::class);
|
|
$this->token->method('getUser')->willReturn($user);
|
|
}
|
|
|
|
#[DataProvider('typesProvider')]
|
|
public function testWithTypes(mixed $subject): void
|
|
{
|
|
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->seasonVoter->vote($this->token, $subject, ['SEASON_EDIT']));
|
|
}
|
|
|
|
public function testNotOwnerWillReturnDenied(): void
|
|
{
|
|
$season = self::createStub(Season::class);
|
|
$season->method('isOwner')->willReturn(false);
|
|
|
|
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->seasonVoter->vote($this->token, $season, ['SEASON_EDIT']));
|
|
}
|
|
|
|
public static function typesProvider(): \Generator
|
|
{
|
|
$season = self::createStub(Season::class);
|
|
$season->method('isOwner')->willReturn(true);
|
|
|
|
$quiz = self::createStub(Quiz::class);
|
|
$quiz->method('getSeason')->willReturn($season);
|
|
|
|
$elimination = self::createStub(Elimination::class);
|
|
$elimination->method('getQuiz')->willReturn($quiz);
|
|
|
|
$candidate = self::createStub(Candidate::class);
|
|
$candidate->method('getSeason')->willReturn($season);
|
|
|
|
$question = self::createStub(Question::class);
|
|
$question->method('getQuiz')->willReturn($quiz);
|
|
|
|
$answer = self::createStub(Answer::class);
|
|
$answer->method('getQuestion')->willReturn($question);
|
|
|
|
yield 'Season' => [$season];
|
|
yield 'Elimination' => [$elimination];
|
|
yield 'Quiz' => [$quiz];
|
|
yield 'Candidate' => [$candidate];
|
|
yield 'Question' => [$question];
|
|
yield 'Answer' => [$answer];
|
|
}
|
|
}
|