/** * @return array */ public function submitProvider() { $entity = new AccountUser(); $expectedEntity = new AccountUser(); $expectedEntity->setSalt($entity->getSalt()); return ['reset password' => ['defaultData' => $entity, 'submittedData' => ['plainPassword' => 'new password'], 'expectedData' => $expectedEntity]]; }
/** * @param AccountUser $accountUser * @param boolean $enabled * @param string $successMessage * @return JsonResponse */ protected function enableTrigger(AccountUser $accountUser, $enabled, $successMessage) { $userManager = $this->get('orob2b_account_user.manager'); $accountUser->setEnabled($enabled); $userManager->updateUser($accountUser); return new JsonResponse(['successful' => true, 'message' => $successMessage]); }
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()); }
/** * @param AccountUser|null $accountUser * @return PriceList */ public function getPriceList(AccountUser $accountUser = null) { if ($accountUser) { $account = $accountUser->getAccount(); if ($account) { $priceList = $this->getPriceListRepository()->getPriceListByAccount($account); if ($priceList) { return $priceList; } $priceList = $this->getPriceListFromAccountTree($account); if ($priceList) { return $priceList; } $priceList = $this->getPriceListFromAccountGroup($account); if ($priceList) { return $priceList; } $priceList = $this->getPriceListFromAccountGroupTree($account); if ($priceList) { return $priceList; } } } $priceList = $this->getPriceListFromWebsite(); if ($priceList) { return $priceList; } return $this->getPriceListRepository()->getDefault(); }
/** * Process form * * @param AccountUser $accountUser * @return bool True on successful processing, false otherwise */ public function process(AccountUser $accountUser) { if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) { $this->form->submit($this->request); if ($this->form->isValid()) { if (!$accountUser->getId()) { if ($this->form->get('passwordGenerate')->getData()) { $generatedPassword = $this->userManager->generatePassword(10); $accountUser->setPlainPassword($generatedPassword); } if ($this->form->get('sendEmail')->getData()) { $this->userManager->sendWelcomeEmail($accountUser); } } $token = $this->securityFacade->getToken(); if ($token instanceof OrganizationContextTokenInterface) { $organization = $token->getOrganizationContext(); $accountUser->setOrganization($organization)->addOrganization($organization); } $this->userManager->updateUser($accountUser); return true; } } return false; }
public function testAccountUserView() { $this->client->request('GET', $this->getUrl('orob2b_account_account_user_view', ['id' => $this->accountUser->getId()])); $result = $this->client->getResponse(); $this->assertHtmlResponseStatusCodeEquals($result, 200); $content = $result->getContent(); $this->assertContains('Address Book', $content); }
/** * @param AccountUser $accountUser * @return QueryBuilder */ public function getAvailableRolesByAccountUserQueryBuilder(AccountUser $accountUser) { $qb = $this->createQueryBuilder('accountUserRole'); $qb->where($qb->expr()->andX($qb->expr()->orX($qb->expr()->isNull('accountUserRole.account'), $qb->expr()->eq('accountUserRole.account', ':account')), $qb->expr()->eq('accountUserRole.organization', ':organization'))); $qb->setParameter('account', $accountUser->getAccount()); $qb->setParameter('organization', $accountUser->getOrganization()); return $qb; }
public function testGetEmail() { $quote = new Quote(); $this->assertEmpty($quote->getEmail()); $accountUser = new AccountUser(); $accountUser->setEmail('test'); $quote->setAccountUser($accountUser); $this->assertEquals('test', $quote->getEmail()); }
/** * @return array */ public function submitProvider() { $entity = new AccountUser(); $owner = new User(); $expectedEntity = new AccountUser(); $expectedEntity->setFirstName('John')->setLastName('Doe')->setEmail('*****@*****.**')->setOwner($owner); $entity->setSalt($expectedEntity->getSalt()); return ['new user' => ['defaultData' => $entity, 'submittedData' => ['firstName' => 'John', 'lastName' => 'Doe', 'email' => '*****@*****.**', 'plainPassword' => '123456'], 'expectedData' => $expectedEntity, 'owner' => $owner]]; }
/** * @Route( * "/disable/{id}", * name="orob2b_account_frontend_account_user_disable", * requirements={"id"="\d+"} * ) * @AclAncestor("orob2b_account_frontend_account_user_update") * * {@inheritdoc} */ public function disableAction(AccountUser $accountUser) { /** @var $user AccountUser */ $user = $this->getUser(); if ($user->getId() == $accountUser->getId()) { throw new ForbiddenException('self disable'); } return parent::disableAction($accountUser); }
/** * @param ObjectManager $manager * @param AccountUser $accountUser * @param string $label * @param boolean $current * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $label, $current) { $shoppingList = new ShoppingList(); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getAccount()); $shoppingList->setNotes('Some notes for ' . $label); $shoppingList->setCurrent($current); $shoppingList->setLabel($label); $manager->persist($shoppingList); }
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()); }
protected function setUp() { $this->form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $this->request = new Request(); $this->manager = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->converter = $this->getMockBuilder('OroB2B\\Bundle\\SaleBundle\\Model\\QuoteToOrderConverter')->disableOriginalConstructor()->getMock(); $account = new Account(); $account->setName('account'); $this->accountUser = new AccountUser(); $this->accountUser->setEmail('*****@*****.**')->setAccount($account); $this->handler = new QuoteToOrderHandler($this->form, $this->request, $this->manager, $this->converter, $this->accountUser); }
/** * @param ObjectManager $manager * @param string $name * @param AccountUser $accountUser * @param bool $isCurrent * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $name, $isCurrent = false) { $shoppingList = new ShoppingList(); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getAccount()); $shoppingList->setLabel($name . '_label'); $shoppingList->setNotes($name . '_notes'); $shoppingList->setCurrent($isCurrent); $manager->persist($shoppingList); $this->addReference($name, $shoppingList); return $shoppingList; }
/** * @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())]; }
/** * Process form * * @param AccountUser $accountUser * @return bool True on successful processing, false otherwise */ public function process(AccountUser $accountUser) { if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) { $this->form->submit($this->request); if ($this->form->isValid()) { if (!$accountUser->getId()) { $this->userManager->register($accountUser); } $this->userManager->updateUser($accountUser); $this->userManager->reloadUser($accountUser); return true; } } return false; }
public function testUpdateFromPredefined() { //TODO: see BB-1134 $this->markTestSkipped('Must be fixed in scope with BB-1134'); $currentUserRoles = $this->currentUser->getRoles(); $oldRoleId = $this->predefinedRole->getId(); $crawler = $this->client->request('GET', $this->getUrl('orob2b_account_frontend_account_user_role_update', ['id' => $oldRoleId])); $form = $crawler->selectButton('Save and Close')->form(); $token = $this->getContainer()->get('security.csrf.token_manager')->getToken('orob2b_account_frontend_account_user_role')->getValue(); $this->client->followRedirects(true); $crawler = $this->client->request($form->getMethod(), $form->getUri(), ['input_action' => '', 'orob2b_account_frontend_account_user_role' => ['_token' => $token, 'label' => self::CUSTOMIZED_ROLE, 'appendUsers' => $this->currentUser->getId()]]); $result = $this->client->getResponse(); $this->assertHtmlResponseStatusCodeEquals($result, 200); $content = $crawler->html(); $this->assertContains('Account User Role has been saved', $content); // Find id of new role $response = $this->requestFrontendGrid('frontend-account-account-user-roles-grid', ['frontend-account-account-user-roles-grid[_filter][label][value]' => self::CUSTOMIZED_ROLE]); $result = $this->getJsonResponseContent($response, 200); $result = reset($result['data']); $newRoleId = $result['id']; $this->assertNotEquals($newRoleId, $oldRoleId); /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUserRole $role */ $role = $this->getUserRoleRepository()->find($newRoleId); $this->assertNotNull($role); $this->assertEquals(self::CUSTOMIZED_ROLE, $role->getLabel()); $this->assertNotEmpty($role->getRole()); /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUser $user */ $user = $this->getCurrentUser(); // Add new role $this->assertCount(count($currentUserRoles) + 1, $user->getRoles()); $this->assertEquals($user->getRole($role->getRole()), $role); }
/** * @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(); }
/** * @return AccountUser */ protected function getAccountUser() { $accountUser = new AccountUser(); /** @var WebsiteManager $websiteManager */ $websiteManager = $this->get('orob2b_website.manager'); $website = $websiteManager->getCurrentWebsite(); /** @var Organization|OrganizationInterface $websiteOrganization */ $websiteOrganization = $website->getOrganization(); if (!$websiteOrganization) { throw new \RuntimeException('Website organization is empty'); } $defaultRole = $this->getDoctrine()->getManagerForClass('OroB2BAccountBundle:AccountUserRole')->getRepository('OroB2BAccountBundle:AccountUserRole')->getDefaultAccountUserRoleByWebsite($website); if (!$defaultRole) { throw new \RuntimeException(sprintf('Role "%s" was not found', AccountUser::ROLE_DEFAULT)); } $accountUser->addOrganization($websiteOrganization)->setOrganization($websiteOrganization)->addRole($defaultRole); return $accountUser; }
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 AccountUserRole|AbstractRole $role * @param EntityManager $manager */ protected function removeOriginalRoleFromUsers(AccountUserRole $role, EntityManager $manager) { if (!$role->getId() || $role->getId() === $this->newRole->getId()) { return; } array_map(function (AccountUser $accountUser) use($role, $manager) { if ($accountUser->getAccount()->getId() === $this->loggedAccountUser->getAccount()->getId()) { $accountUser->removeRole($role); $manager->persist($accountUser); } }, $this->appendUsers); }
/** * @param Quote $quote * @param AccountUser|null $user * @param array|null $selectedOffers * @return Order */ public function convert(Quote $quote, AccountUser $user = null, array $selectedOffers = null) { $accountUser = $user ?: $quote->getAccountUser(); $account = $user ? $user->getAccount() : $quote->getAccount(); $order = new Order(); $order->setAccount($account)->setAccountUser($accountUser)->setOwner($quote->getOwner())->setOrganization($quote->getOrganization()); if (!$selectedOffers) { foreach ($quote->getQuoteProducts() as $quoteProduct) { /** @var QuoteProductOffer $productOffer */ $productOffer = $quoteProduct->getQuoteProductOffers()->first(); $order->addLineItem($this->createOrderLineItem($productOffer)); } } else { foreach ($selectedOffers as $selectedOffer) { /** @var QuoteProductOffer $offer */ $offer = $selectedOffer[self::FIELD_OFFER]; $order->addLineItem($this->createOrderLineItem($offer, (double) $selectedOffer[self::FIELD_QUANTITY])); } } $this->orderCurrencyHandler->setOrderCurrency($order); $this->fillSubtotals($order); return $order; }
/** * {@inheritdoc} * @dataProvider supportedMethods */ public function testProcessSupportedRequest($method, $isValid, $isProcessed) { $organization = null; if ($isValid) { $organization = new Organization(); $organization->setName('test'); $organizationToken = $this->getMock('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\OrganizationContextTokenInterface'); $organizationToken->expects($this->any())->method('getOrganizationContext')->willReturn($organization); $this->securityFacade->expects($this->any())->method('getToken')->willReturn($organizationToken); $this->form->expects($this->at(2))->method('get')->with('passwordGenerate')->will($this->returnValue($this->passwordGenerateForm)); $this->form->expects($this->at(3))->method('get')->with('sendEmail')->will($this->returnValue($this->sendEmailForm)); $this->passwordGenerateForm->expects($this->once())->method('getData')->will($this->returnValue(false)); $this->sendEmailForm->expects($this->once())->method('getData')->will($this->returnValue(false)); } $this->form->expects($this->any())->method('isValid')->will($this->returnValue($isValid)); $this->request->setMethod($method); $this->form->expects($this->once())->method('submit')->with($this->request); $this->assertEquals($isProcessed, $this->handler->process($this->entity)); if ($organization) { $this->assertEquals($organization, $this->entity->getOrganization()); $this->assertTrue($this->entity->hasOrganization($organization)); } }
/** * "Success" form handler * * @param ShoppingList $entity * @return bool */ protected function onSuccess(ShoppingList $entity) { $rfpRequest = new RFPRequest(); $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus); foreach ($entity->getLineItems() as $shoppingListLineItem) { $requestProduct = new RequestProduct(); $requestProduct->setProduct($shoppingListLineItem->getProduct()); $requestProductItem = new RequestProductItem(); $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit()); $requestProduct->addRequestProductItem($requestProductItem); $rfpRequest->addRequestProduct($requestProduct); } try { $this->manager->persist($rfpRequest); $this->manager->flush(); $this->rfpRequest = $rfpRequest; } catch (DBALException $e) { $this->exception = $e; return false; } return true; }
public function testRegisterConfirmationNotRequired() { $password = '******'; $user = new AccountUser(); $user->setConfirmed(false); $user->setPlainPassword($password); $this->configManager->expects($this->exactly(2))->method('get')->willReturnMap([['oro_b2b_account.confirmation_required', false, false, false], ['oro_b2b_account.send_password_in_welcome_email', false, false, true]]); $this->emailProcessor->expects($this->once())->method('sendWelcomeNotification')->with($user, $password); $this->userManager->register($user); $this->assertTrue($user->isConfirmed()); }
/** * @param string $accountName * @return AccountUser */ protected function createAccountUser($accountName) { $accountUser = new AccountUser(); $accountUser->setFirstName($accountName . ' first')->setLastName($accountName . ' last')->setSalt(null); $account = new Account(); $account->setName($accountName)->addUser($accountUser); return $accountUser; }
/** * Get the truncated email displayed when requesting the resetting. * The default implementation only keeps the part following @ in the address. * * @param AccountUser $user * * @return string */ protected function getObfuscatedEmail(AccountUser $user) { $email = $user->getEmail(); if (false !== ($pos = strpos($email, '@'))) { $email = '...' . substr($email, $pos); } return $email; }
/** * @param AccountUser $user * @param AccountOwnerAwareInterface $object * @return bool */ protected function isSameUser(AccountUser $user, AccountOwnerAwareInterface $object) { return $object->getAccountUser() && $user->getId() === $object->getAccountUser()->getId(); }
/** * @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 AccountUser $accountUser * @return null|Account */ protected function getAccount(AccountUser $accountUser = null) { $account = $this->getOrderHandler()->getAccount(); if (!$account && $accountUser) { $account = $accountUser->getAccount(); } if ($account && $accountUser) { $this->validateRelation($accountUser, $account); } return $account; }