/** @dataProvider provideRoles */
 public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles, array $inheritedRoles)
 {
     $tokenStorage = new TokenStorage();
     $tokenStorage->setToken(new UsernamePasswordToken('hhamon', 'P4$$w0rD', 'provider', $roles));
     $collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
     $collector->collect($this->getRequest(), $this->getResponse());
     $this->assertTrue($collector->isEnabled());
     $this->assertTrue($collector->isAuthenticated());
     $this->assertSame('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken', $collector->getTokenClass());
     $this->assertTrue($collector->supportsRoleHierarchy());
     $this->assertSame($normalizedRoles, $collector->getRoles());
     $this->assertSame($inheritedRoles, $collector->getInheritedRoles());
     $this->assertSame('hhamon', $collector->getUser());
 }
 /** @dataProvider provideRoles */
 public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles)
 {
     $securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $securityContext->expects($this->once())->method('getToken')->willReturn(new UsernamePasswordToken('hhamon', 'P4$$w0rD', 'provider', $roles));
     $collector = new SecurityDataCollector($securityContext);
     $collector->collect($this->getRequest(), $this->getResponse());
     $this->assertTrue($collector->isEnabled());
     $this->assertTrue($collector->isAuthenticated());
     $this->assertSame('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken', $collector->getTokenClass());
     $this->assertSame($normalizedRoles, $collector->getRoles());
     $this->assertSame('hhamon', $collector->getUser());
 }
Пример #3
0
 public function testGetFirewallReturnsNull()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     // Don't inject any firewall map
     $collector = new SecurityDataCollector();
     $collector->collect($request, $response);
     $this->assertNull($collector->getFirewall());
     // Inject an instance that is not context aware
     $firewallMap = $this->getMockBuilder(FirewallMapInterface::class)->disableOriginalConstructor()->getMock();
     $collector = new SecurityDataCollector(null, null, null, null, $firewallMap);
     $collector->collect($request, $response);
     $this->assertNull($collector->getFirewall());
     // Null config
     $firewallMap = $this->getMockBuilder(FirewallMap::class)->disableOriginalConstructor()->getMock();
     $collector = new SecurityDataCollector(null, null, null, null, $firewallMap);
     $collector->collect($request, $response);
     $this->assertNull($collector->getFirewall());
 }