public function testNotValidForm()
 {
     $this->form->expects($this->once())->method('setData');
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('POST'));
     $this->form->expects($this->once())->method('submit');
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->om->expects($this->never())->method('persist');
     $this->om->expects($this->never())->method('flush');
     $this->assertFalse($this->handler->process($this->address));
 }
 /**
  * @param Account $account
  * @param AccountAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Account $account, AccountAddress $address)
 {
     $responseData = ['saved' => false, 'entity' => $account];
     if ($this->getRequest()->getMethod() === 'GET' && !$address->getId() && !$account->getAddresses()->count()) {
         $address->setPrimary(true);
     }
     if (!$address->getFrontendOwner()) {
         $account->addAddress($address);
     } elseif ($address->getFrontendOwner()->getId() !== $account->getId()) {
         throw new BadRequestHttpException('Address must belong to Account');
     }
     $form = $this->createForm(AccountTypedAddressType::NAME, $address);
     $handler = new AddressHandler($form, $this->getRequest(), $this->getDoctrine()->getManagerForClass($this->container->getParameter('orob2b_account.entity.account_address.class')));
     if ($handler->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $form->createView();
     $responseData['routes'] = ['create' => 'orob2b_account_address_create', 'update' => 'orob2b_account_address_update'];
     return $responseData;
 }
 /**
  * @param Customer $customer
  * @param CustomerAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Customer $customer, CustomerAddress $address)
 {
     $responseData = ['saved' => false, 'customer' => $customer];
     if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) {
         if (!$customer->getAddresses()->count()) {
             $address->setPrimary(true);
         }
     }
     if ($address->getOwner() && $address->getOwner()->getId() != $customer->getId()) {
         throw new BadRequestHttpException('Address must belong to customer');
     } elseif (!$address->getOwner()) {
         $customer->addAddress($address);
     }
     $form = $this->createForm(CustomerTypedAddressType::NAME, $address);
     $handler = new AddressHandler($form, $this->getRequest(), $this->getDoctrine()->getManagerForClass('OroB2BCustomerBundle:CustomerAddress'));
     if ($handler->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $form->createView();
     return $responseData;
 }