/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Account::INTERNAL_RATING_CODE))->findAll();
     /** @var \Oro\Bundle\UserBundle\Entity\User $accountOwner */
     $accountOwner = $manager->getRepository('OroUserBundle:User')->findOneBy([]);
     foreach ($this->accounts as $accountName => $accountData) {
         /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $accountGroup */
         $accountGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $accountData['group']);
         $account = new Account();
         $account->setName($accountName)->setGroup($accountGroup)->setParent(null)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
         $manager->persist($account);
         $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $account->getName(), $account);
         if (isset($accountData['subsidiaries'])) {
             foreach ($accountData['subsidiaries'] as $subsidiaryName => $subsidiaryData) {
                 /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $subsidiaryGroup */
                 $subsidiaryGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $subsidiaryData['group']);
                 $subsidiary = new Account();
                 $subsidiary->setName($subsidiaryName)->setGroup($subsidiaryGroup)->setParent($account)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
                 $manager->persist($subsidiary);
                 $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $subsidiary->getName(), $subsidiary);
             }
         }
     }
     $manager->flush();
 }
 /**
  * @return array
  */
 public function getPaymentTermDataProvider()
 {
     $account = new Account();
     $accountWithGroup = new Account();
     $accountWithGroup->setGroup(new AccountGroup());
     $paymentTerm = new PaymentTerm();
     return [['account' => $account, 'repositoryMethods' => ['getOnePaymentTermByAccount' => ['expects' => $this->once(), 'with' => $account, 'willReturn' => $paymentTerm], 'getOnePaymentTermByAccountGroup' => ['expects' => $this->never()]], 'expected' => $paymentTerm], ['account' => $account, 'repositoryMethods' => ['getOnePaymentTermByAccount' => ['expects' => $this->once(), 'with' => $account, 'willReturn' => null], 'getOnePaymentTermByAccountGroup' => ['expects' => $this->never()]], 'expected' => null], ['account' => $accountWithGroup, 'repositoryMethods' => ['getOnePaymentTermByAccount' => ['expects' => $this->once(), 'with' => $accountWithGroup, 'willReturn' => null], 'getOnePaymentTermByAccountGroup' => ['expects' => $this->once(), 'with' => $accountWithGroup->getGroup(), 'willReturn' => $paymentTerm]], 'expected' => $paymentTerm], ['account' => $accountWithGroup, 'repositoryMethods' => ['getOnePaymentTermByAccount' => ['expects' => $this->once(), 'with' => $accountWithGroup, 'willReturn' => null], 'getOnePaymentTermByAccountGroup' => ['expects' => $this->once(), 'with' => $accountWithGroup->getGroup(), 'willReturn' => null]], 'expected' => null]];
 }
 /**
  * @param Account $entity
  * @return array
  */
 protected function buildTreeRecursive(Account $entity)
 {
     $entities = [];
     $children = $entity->getChildren();
     foreach ($children->toArray() as $child) {
         $entities[] = $child;
         $entities = array_merge($entities, $this->buildTreeRecursive($child));
     }
     return $entities;
 }
 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);
 }
Esempio n. 5
0
 /**
  * @param ObjectManager $manager
  */
 protected function loadAccounts(ObjectManager $manager)
 {
     $defaultUser = $this->getUser($manager);
     $organization = $defaultUser->getOrganization();
     foreach ($this->accounts as $item) {
         $account = new Account();
         $account->setName($item['name'])->setOrganization($organization);
         $manager->persist($account);
         $this->addReference($item['name'], $account);
     }
     $manager->flush();
 }
 /**
  * @dataProvider postSubmitDataProvider
  */
 public function testPostSubmit(array $allAddresses, $formAddressKey, array $expectedAddressesData)
 {
     // Set owner for all addresses
     $account = new Account();
     foreach ($allAddresses as $address) {
         $account->addAddress($address);
     }
     $event = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->setMethods(['getData'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getData')->will($this->returnValue($allAddresses[$formAddressKey]));
     $this->subscriber->postSubmit($event);
     foreach ($expectedAddressesData as $addressKey => $expectedData) {
         /** @var AccountAddress $address */
         $address = $allAddresses[$addressKey];
         $defaultTypeNames = [];
         /** @var AddressType $defaultType */
         foreach ($address->getDefaults() as $defaultType) {
             $defaultTypeNames[] = $defaultType->getName();
         }
         $this->assertEquals($expectedData['defaults'], $defaultTypeNames);
     }
 }
 /**
  * @param bool $isPaymentTermExist
  * @param bool $isPaymentTermInGroupExist
  * @dataProvider viewAccountDataProvider
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function testOnAccountView($isPaymentTermExist, $isPaymentTermInGroupExist)
 {
     $accountId = 1;
     $account = new Account();
     $accountGroup = new AccountGroup();
     $paymentTerm = new PaymentTerm();
     $templateAccountPaymentTermHtml = 'template_html_with_account_payment_term';
     $templateAccountGroupPaymentTermHtml = 'template_html_with_account_group_payment_term';
     $templateAccountGroupWithoutPaymentTermHtml = 'template_html_without_account_group_payment_term';
     if ($isPaymentTermInGroupExist) {
         $account->setGroup($accountGroup);
     }
     $paymentTermRepository = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Entity\\Repository\\PaymentTermRepository')->disableOriginalConstructor()->getMock();
     $paymentTermRepository->expects($this->once())->method('getOnePaymentTermByAccount')->with($account)->willReturn($isPaymentTermExist ? $paymentTerm : null);
     $this->doctrineHelper->expects($this->once())->method('getEntityReference')->with('OroB2BAccountBundle:Account', $accountId)->willReturn($account);
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with(static::PAYMENT_TERM_CLASS)->willReturn($paymentTermRepository);
     /** @var \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment $environment */
     $environment = $this->getMock('\\Twig_Environment');
     if ($isPaymentTermExist) {
         $environment->expects($isPaymentTermExist ? $this->once() : $this->never())->method('render')->with('OroB2BPaymentBundle:Account:payment_term_view.html.twig')->willReturn($templateAccountPaymentTermHtml);
     } else {
         $this->translator->expects($this->at(0))->method('trans')->with('orob2b.payment.account.payment_term_non_defined_in_group');
         $paymentTermRepository->expects($this->any())->method('getOnePaymentTermByAccountGroup')->with($accountGroup)->willReturn($isPaymentTermInGroupExist ? $paymentTerm : null);
         if ($isPaymentTermInGroupExist) {
             $this->translator->expects($this->at(1))->method('trans')->with('orob2b.payment.account.payment_term_defined_in_group');
         }
         $environment->expects($this->once())->method('render')->with('OroB2BPaymentBundle:Account:payment_term_view.html.twig')->willReturn($isPaymentTermInGroupExist ? $templateAccountGroupPaymentTermHtml : $templateAccountGroupWithoutPaymentTermHtml);
     }
     $this->listener->setRequest(new Request(['id' => $accountId]));
     $event = $this->createEvent($environment);
     $this->listener->onAccountView($event);
     $scrollData = $event->getScrollData()->getData();
     if ($isPaymentTermExist) {
         $this->assertEqualsForScrollData($templateAccountPaymentTermHtml, $scrollData);
     } elseif ($isPaymentTermInGroupExist) {
         $this->assertEqualsForScrollData($templateAccountGroupPaymentTermHtml, $scrollData);
     } else {
         $this->assertEqualsForScrollData($templateAccountGroupWithoutPaymentTermHtml, $scrollData);
     }
 }
 public function testProcessValidData()
 {
     $appendedAccount = new Account();
     $removedAccount = new Account();
     $removedAccount->setGroup($this->entity);
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $appendForm->expects($this->once())->method('getData')->will($this->returnValue([$appendedAccount]));
     $this->form->expects($this->at(3))->method('get')->with('appendAccounts')->will($this->returnValue($appendForm));
     $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $removeForm->expects($this->once())->method('getData')->will($this->returnValue([$removedAccount]));
     $this->form->expects($this->at(4))->method('get')->with('removeAccounts')->will($this->returnValue($removeForm));
     $this->manager->expects($this->at(0))->method('persist')->with($appendedAccount);
     $this->manager->expects($this->at(1))->method('persist')->with($removedAccount);
     $this->manager->expects($this->at(2))->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $this->assertEquals($this->entity, $appendedAccount->getGroup());
     $this->assertNull($removedAccount->getGroup());
 }
Esempio n. 9
0
 /**
  * @param ObjectManager $manager
  * @param string $name
  * @param Account $parent
  * @param AccountGroup $group
  * @return Account
  */
 protected function createAccount(ObjectManager $manager, $name, Account $parent = null, AccountGroup $group = null)
 {
     $account = new Account();
     $account->setName($name);
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $account->setOrganization($organization);
     if ($parent) {
         $account->setParent($parent);
     }
     if ($group) {
         $account->setGroup($group);
     }
     $manager->persist($account);
     $this->addReference($name, $account);
     return $account;
 }
 /**
  * @param AccountUser $accountUser
  * @param Account $account
  *
  * @throws BadRequestHttpException
  */
 protected function validateRelation(AccountUser $accountUser, Account $account)
 {
     if ($accountUser && $accountUser->getAccount() && $accountUser->getAccount()->getId() !== $account->getId()) {
         throw new BadRequestHttpException('AccountUser must belong to Account');
     }
 }
 /**
  * @param Account $account
  * @return null|PriceList
  */
 protected function getPriceListFromAccountGroup(Account $account)
 {
     $accountGroup = $account->getGroup();
     if (!$accountGroup) {
         return null;
     }
     $priceList = $this->getPriceListRepository()->getPriceListByAccountGroup($accountGroup);
     if ($priceList) {
         return $priceList;
     }
     return null;
 }
 /**
  * @Route("/info/{id}", name="orob2b_account_info", requirements={"id"="\d+"})
  * @Template("OroB2BAccountBundle:Account/widget:info.html.twig")
  * @AclAncestor("orob2b_account_view")
  *
  * @param Account $account
  * @return array
  */
 public function infoAction(Account $account)
 {
     return ['entity' => $account, 'treeData' => $this->get('orob2b_account.account_tree_handler')->createTree($account->getId())];
 }
Esempio n. 13
0
 /**
  * @ORM\PrePersist
  */
 public function createAccount()
 {
     if (!$this->account) {
         $this->account = new Account();
         $this->account->setOrganization($this->organization);
         $this->account->setName(sprintf('%s %s', $this->firstName, $this->lastName));
         if ($this->getOwner() && !$this->account->getOwner()) {
             $this->account->setOwner($this->getOwner(), false);
         }
     }
 }
 /**
  * @param Account $entity
  * @return array
  */
 protected function getAddressBookOptions($entity)
 {
     $addressListUrl = $this->generateUrl('orob2b_api_account_get_account_addresses', ['entityId' => $entity->getId()]);
     $addressCreateUrl = $this->generateUrl('orob2b_account_address_create', ['entityId' => $entity->getId()]);
     $currentAddresses = $this->get('fragment.handler')->render($addressListUrl);
     return ['wid' => $this->getRequest()->get('_wid'), 'entityId' => $entity->getId(), 'addressListUrl' => $addressListUrl, 'addressCreateUrl' => $addressCreateUrl, 'addressUpdateRouteName' => 'orob2b_account_address_update', 'currentAddresses' => $currentAddresses];
 }
 public function testAccountView()
 {
     $this->client->request('GET', $this->getUrl('orob2b_account_view', ['id' => $this->account->getId()]));
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
 }
 /**
  * @param string $html
  * @param string $name
  * @param Account $parent
  * @param AccountGroup $group
  * @param AbstractEnumValue $internalRating
  */
 protected function assertViewPage($html, $name, Account $parent, AccountGroup $group, AbstractEnumValue $internalRating)
 {
     $this->assertContains($name, $html);
     $this->assertContains($parent->getName(), $html);
     $this->assertContains($group->getName(), $html);
     $this->assertContains($internalRating->getName(), $html);
 }
 /**
  * @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;
 }
 /**
  * @return array
  */
 public function submitWithFormSubscribersProvider()
 {
     $accountAddress1 = new AccountAddress();
     $accountAddress1->setTypes(new ArrayCollection([$this->billingType, $this->shippingType]));
     $accountAddress2 = new AccountAddress();
     $accountAddress2->setTypes(new ArrayCollection([$this->billingType, $this->shippingType]))->setDefaults(new ArrayCollection([$this->billingType, $this->shippingType]));
     $accountAddressExpected = new AccountAddress();
     $accountAddressExpected->setPrimary(true)->addType($this->billingType)->addType($this->shippingType)->removeType($this->billingType)->removeType($this->shippingType)->addType($this->billingType)->addType($this->shippingType)->setDefaults(new ArrayCollection([$this->billingType, $this->shippingType]));
     $account = new Account();
     $account->addAddress($accountAddress1);
     $account->addAddress($accountAddress2);
     return ['FixAccountAddressesDefaultSubscriber check' => ['options' => [], 'defaultData' => $accountAddress1, 'viewData' => $accountAddress1, 'submittedData' => ['types' => [AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING], 'defaults' => ['default' => [AddressType::TYPE_BILLING, AddressType::TYPE_SHIPPING]], 'primary' => true], 'expectedData' => $accountAddressExpected, 'otherAddresses' => [$accountAddress2], 'updateOwner' => $account]];
 }