public function testDefaultIfNotFound() { $accountUser = new AccountUser(); $accountUser->setAccount($this->getAccount('account.level_1')); $this->websiteManager->expects($this->once())->method('getCurrentWebsite')->willReturn(null); $this->assertTrue($this->handler->getPriceList($accountUser)->isDefault()); }
public function testAccountUserToAccountRelation() { $order = new Order(); /** @var Account|\PHPUnit_Framework_MockObject_MockObject $account */ $account = $this->getMock('OroB2B\\Bundle\\AccountBundle\\Entity\\Account'); $account->expects($this->any())->method('getId')->will($this->returnValue(1)); $accountUser = new AccountUser(); $accountUser->setAccount($account); $this->assertEmpty($order->getAccount()); $order->setAccountUser($accountUser); $this->assertSame($account, $order->getAccount()); }
/** * @return array */ protected function getExtensions() { $account = $this->getAccount(1); $user = new AccountUser(); $user->setAccount($account); $this->securityFacade->expects($this->any())->method('getLoggedUser')->willReturn($user); $frontendUserRoleSelectType = new EntitySelectTypeStub($this->getRoles(), FrontendAccountUserRoleSelectType::NAME, new AccountUserRoleSelectType()); $addressEntityType = new EntityType($this->getAddresses(), 'test_address_entity'); $accountSelectType = new AccountSelectTypeStub($this->getAccounts(), 'orob2b_account_select'); $accountUserType = new AccountUserType($this->securityFacade); $accountUserType->setDataClass(self::DATA_CLASS); $accountUserType->setAddressClass(self::ADDRESS_CLASS); return [new PreloadedExtension([OroDateType::NAME => new OroDateType(), AccountUserType::NAME => $accountUserType, FrontendAccountUserRoleSelectType::NAME => $frontendUserRoleSelectType, $accountSelectType->getName() => $accountSelectType, AddressCollectionTypeStub::NAME => new AddressCollectionTypeStub(), $addressEntityType->getName() => $addressEntityType], []), new ValidatorExtension(Validation::createValidator())]; }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { foreach ($this->users as $user) { if (isset($user['account'])) { /** @var Account $account */ $account = $this->getReference($user['account']); } else { $accountUser = $manager->getRepository('OroB2BAccountBundle:AccountUser')->findOneBy(['username' => UserData::AUTH_USER]); $account = $accountUser->getAccount(); } $role = $manager->getRepository('OroB2BAccountBundle:AccountUserRole')->findOneBy([]); $entity = new AccountUser(); $entity->setAccount($account)->setFirstName($user['first_name'])->setLastName($user['last_name'])->setEmail($user['email'])->setEnabled($user['enabled'])->setOrganization($account->getOrganization())->addRole($role)->setPassword($user['password']); $this->setReference($entity->getEmail(), $entity); $manager->persist($entity); } $manager->flush(); }
protected function setUp() { $account = $this->createAccount(1, 'account'); $user = new AccountUser(); $user->setAccount($account); $this->qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->securityFacade->expects($this->any())->method('getLoggedUser')->willReturn($user); $this->registry = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); /** @var $repo AccountUserRoleRepository|\PHPUnit_Framework_MockObject_MockObject */ $repo = $this->getMockBuilder('OroB2B\\Bundle\\AccountBundle\\Entity\\Repository\\AccountUserRoleRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->any())->method('getAvailableRolesByAccountUserQueryBuilder')->with($user)->willReturn($this->qb); /** @var $em ObjectManager|\PHPUnit_Framework_MockObject_MockObject */ $em = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $em->expects($this->any())->method('getRepository')->with('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUserRole')->willReturn($repo); $this->registry->expects($this->any())->method('getManagerForClass')->willReturn($em); $this->formType = new FrontendAccountUserRoleSelectType($this->securityFacade, $this->registry); $this->formType->setRoleClass('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUserRole'); parent::setUp(); }
/** * @param AccountUser|null $accountUser * @param bool $isGranted * @param int $accountId * @param int $loggedUserAccountId * @param int $expected * @param bool $failAccountUserRole * @dataProvider attributeFrontendUpdateViewDataProvider */ public function testVoteFrontendView($accountUser, $isGranted, $accountId, $loggedUserAccountId, $expected, $failAccountUserRole = false) { /** @var Account $roleAccount */ $roleAccount = $this->createEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\Account', $accountId); /** @var Account $userAccount */ $userAccount = $this->createEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\Account', $loggedUserAccountId); if ($failAccountUserRole) { $accountUserRole = new \stdClass(); } else { $accountUserRole = new AccountUserRole(); $accountUserRole->setAccount($roleAccount); } if ($accountUser) { $accountUser->setAccount($userAccount); } $this->getMocksForVote($accountUserRole); if (!$failAccountUserRole) { $this->getMockForUpdateAndView($accountUser, $isGranted, 'VIEW'); } /** @var \PHPUnit_Framework_MockObject_MockObject|TokenInterface $token */ $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $this->assertEquals($expected, $this->voter->vote($token, $accountUserRole, [AccountUserRoleVoter::ATTRIBUTE_FRONTEND_ACCOUNT_ROLE_VIEW])); }
/** * @param AccountUserRole $role * @param int $numberOfUsers * @param Account $account * @return \OroB2B\Bundle\AccountBundle\Entity\AccountUser[] */ protected function createUsersWithRole(AccountUserRole $role, $numberOfUsers, Account $account = null) { /** @var AccountUser[] $users */ $users = []; for ($i = 0; $i < $numberOfUsers; $i++) { $user = new AccountUser(); $user->setUsername('user' . $i . $role->getRole()); $user->setRoles([$role]); $user->setAccount($account); $users[] = $user; } return $users; }