security = $this->createMock(Security::class); } /** * @dataProvider documentAndFeedbackAttributes */ public function testAnAdminIsDeniedOnASkipFormalitiesAssignment(string $attribute): void { $this->security->method('isGranted')->willReturn(true); $this->assertSame( VoterInterface::ACCESS_DENIED, $this->vote($attribute, $this->createDisposition(skipFormalities: true)), ); } /** * The same admin on a normal assignment must still get through - the flag is the only thing * that may take these away. * * @dataProvider documentAndFeedbackAttributes */ public function testTheSameAdminIsGrantedOnANormalAssignment(string $attribute): void { $this->security->method('isGranted')->willReturn(true); $this->assertSame( VoterInterface::ACCESS_GRANTED, $this->vote($attribute, $this->createDisposition(skipFormalities: false)), ); } /** * @return array */ public static function documentAndFeedbackAttributes(): array { return [ 'contract pdf and upload' => [DispositionVoter::CONTRACT], 'invoice pdf and upload' => [DispositionVoter::INVOICE], 'office upload on behalf of the teamer' => [DispositionVoter::CONTRACT_SUPPLEMENTARY], 'office upload of either document' => [DispositionVoter::ADMIN_DOCUMENT_UPLOAD], 'providing the feedback' => [DispositionVoter::FEEDBACK], ]; } /** * Viewing the placement and calling it off are unrelated to the formalities and have to keep * working, or an admin could no longer cancel a teamer on such an assignment. */ public function testViewingAndCallingOffAreUnaffected(): void { $this->security->method('isGranted')->willReturn(true); $disposition = $this->createDisposition(skipFormalities: true); $this->assertSame(VoterInterface::ACCESS_GRANTED, $this->vote(DispositionVoter::VIEW, $disposition)); $this->assertSame(VoterInterface::ACCESS_GRANTED, $this->vote(DispositionVoter::CALL_OFF, $disposition)); } private function vote(string $attribute, Disposition $disposition): int { return (new DispositionVoter($this->security))->vote( $this->createMock(TokenInterface::class), $disposition, [$attribute], ); } private function createDisposition(bool $skipFormalities): Disposition { $assignment = (new Assignment())->setSkipFormalities($skipFormalities); return new Disposition(new Application($assignment, new Teamer())); } }