/** * @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 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 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()); }