security = $this->createMock(Security::class); $this->token = $this->createMock(TokenInterface::class); $this->token->method('getUser')->willReturn(new User()); $this->mainVoter = new MainVoter($this->security); } public function testVoteReturnsAbstainForInvalidAttribute(): void { $this->assertSame(VoterInterface::ACCESS_ABSTAIN, $this->mainVoter->vote($this->token, null, ['INVALID'])); } public function testVoteReturnsAbstainForInvalidSubject(): void { $this->assertSame(VoterInterface::ACCESS_ABSTAIN, $this->mainVoter->vote($this->token, new \stdClass(), [MainVoter::LIST_ENTRIES])); } public function testVoteReturnsDeniedForInvalidUser(): void { $this->token->method('getUser')->willReturn(new \stdClass()); $this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::LIST_ENTRIES])); } public function testVoteReturnsDeniedForNonUserListEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(false); $this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::LIST_ENTRIES])); } public function testVoteReturnsGrantedForUserListEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(true); $this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::LIST_ENTRIES])); } public function testVoteReturnsDeniedForNonUserCreateEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(false); $this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::CREATE_ENTRIES])); } public function testVoteReturnsGrantedForUserCreateEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(true); $this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::CREATE_ENTRIES])); } public function testVoteReturnsDeniedForNonUserEditEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(false); $this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::EDIT_ENTRIES])); } public function testVoteReturnsGrantedForUserEditEntries(): void { $this->security->method('isGranted')->with('ROLE_USER')->willReturn(true); $this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::EDIT_ENTRIES])); } }