/**
  * @expectedException        \Symfony\Component\Security\Core\Exception\BadCredentialsException
  * @expectedExceptionMessage You don't have access to organization 'Inactive Org'
  */
 public function testBadOrganizationAuthenticate()
 {
     $organization = new Organization(2);
     $organization->setEnabled(false);
     $organization->setName('Inactive Org');
     $user = new User(1);
     $user->addOrganization($organization);
     $token = new OrganizationRememberMeToken($user, 'provider', 'testKey', $organization);
     $this->userChecker->expects($this->once())->method('checkPreAuth');
     $this->provider->authenticate($token);
 }
 /**
  * @dataProvider buildFilterConstraintProvider
  */
 public function testGetAclConditionData($userId, $organizationId, $isGranted, $accessLevel, $ownerType, $targetEntityClassName, $expectedConstraint)
 {
     $this->buildTestTree();
     if ($ownerType !== null) {
         $this->metadataProvider->setMetadata(self::TEST_ENTITY, new OwnershipMetadata($ownerType, 'owner', 'owner_id', 'organization', 'organization_id'));
     }
     /** @var OneShotIsGrantedObserver $aclObserver */
     $aclObserver = null;
     $this->aclVoter->expects($this->any())->method('addOneShotIsGrantedObserver')->will($this->returnCallback(function ($observer) use(&$aclObserver, &$accessLevel) {
         $aclObserver = $observer;
         /** @var OneShotIsGrantedObserver $aclObserver */
         $aclObserver->setAccessLevel($accessLevel);
     }));
     $user = new User($userId);
     $organization = new Organization($organizationId);
     $user->addOrganization($organization);
     $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $token->expects($this->any())->method('getOrganizationContext')->will($this->returnValue($organization));
     $this->securityContext->expects($this->any())->method('isGranted')->with($this->equalTo('VIEW'), $this->equalTo('entity:' . $targetEntityClassName))->will($this->returnValue($isGranted));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($userId ? $token : null));
     $result = $this->builder->getAclConditionData($targetEntityClassName);
     $this->assertEquals($expectedConstraint, $result);
 }