public function testProcessInvalid()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->assertFalse($this->handler->process($this->entity));
 }
Exemplo n.º 2
0
 /**
  * @dataProvider eventDataProvider
  *
  * @param Integration      $entity
  * @param null|User        $newOwner
  * @param Integration|null $oldIntegration
  * @param bool             $expectOwnerSetEvent
  * @param bool             $expectIntegrationUpdateEvent
  */
 public function testEventDispatching($entity, $newOwner, $oldIntegration, $expectOwnerSetEvent, $expectIntegrationUpdateEvent)
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($entity)->will($this->returnCallback(function ($entity) use($newOwner) {
         $entity->setDefaultUserOwner($newOwner);
     }));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->em->expects($this->once())->method('persist')->with($entity);
     $this->em->expects($this->once())->method('flush');
     if ($entity->getId()) {
         $this->em->expects($this->once())->method('find')->with('OroIntegrationBundle:Channel', $entity->getId())->will($this->returnValue($oldIntegration));
     }
     $dispatchCallIndex = 0;
     if ($expectOwnerSetEvent) {
         $this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(DefaultOwnerSetEvent::NAME), $this->isInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\DefaultOwnerSetEvent'));
     }
     if ($expectIntegrationUpdateEvent) {
         $this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(IntegrationUpdateEvent::NAME), $this->callback(function ($event) use($entity, $oldIntegration) {
             $this->assertInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\IntegrationUpdateEvent', $event);
             $this->assertSame($entity, $event->getIntegration());
             $this->assertEquals($oldIntegration, $event->getOldState());
             return true;
         }));
     } elseif (!$expectOwnerSetEvent) {
         $this->eventDispatcher->expects($this->never())->method('dispatch');
     }
     $this->assertTrue($this->handler->process($entity));
 }
 public function testCreateUserFormDataValidWillReturn201Response()
 {
     $this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->useCaseMock->expects($this->once())->method('editPhoneNumber')->with($this->number, false);
     $view = $this->controller->editPhoneNumberAction($this->number, $this->createExampleRequest());
     $this->assertEquals(new View($this->number, 200), $view);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider supportedMethods
  *
  * @param string $method
  */
 public function testProcessSupportedRequest($method)
 {
     $this->request->setMethod($method);
     $this->form->expects($this->any())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->assertTrue($this->handler->process($this->entity));
 }
 public function testCreateUserFormDataValidWillReturn200Response()
 {
     $request = $this->createExampleRequest();
     $user = $this->createExampleUser();
     $this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $view = $this->controller->editUserAction($user, $request);
     $this->assertInstanceOf(User::class, $view->getData());
     $this->assertSame(200, $view->getStatusCode());
 }
Exemplo n.º 6
0
 public function testProcessWithoutContactViewPermission()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->form->expects($this->never())->method('get');
     $this->assertTrue($this->handler->process($this->entity));
 }
 public function testCreateUserFormDataValidWillReturn201Response()
 {
     $request = $this->createExampleRequest();
     $this->formMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->routerMock->expects($this->once())->method('generate')->will($this->returnValue('http://example.com'));
     $view = $this->controller->createUserAction($request);
     $this->assertInstanceOf(User::class, $view->getData());
     $this->assertSame(201, $view->getStatusCode());
     $this->assertSame(['http://example.com'], $view->getHeaders()['location']);
 }
Exemplo n.º 8
0
 public function testProcessValidData()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
 }
 public function testProcessValidPost()
 {
     $offerData = ['offer', 'data'];
     $quote = new Quote();
     $order = new Order();
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->willReturn(true);
     $this->form->expects($this->once())->method('getData')->willReturn($offerData);
     $this->converter->expects($this->once())->method('convert')->with($quote, $this->accountUser, $offerData)->willReturn($order);
     $this->manager->expects($this->once())->method('persist')->with($order);
     $this->manager->expects($this->once())->method('flush');
     $this->assertEquals($order, $this->handler->process($quote));
 }
Exemplo n.º 10
0
 public function testProcessValidData()
 {
     $subtotal = new Subtotal();
     $amount = 42;
     $subtotal->setType(Subtotal::TYPE_SUBTOTAL);
     $subtotal->setAmount($amount);
     $subtotals = new ArrayCollection([$subtotal]);
     $this->subtotalsProvider->expects($this->any())->method('getSubtotals')->willReturn($subtotals);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     foreach ($subtotals as $subtotal) {
         $this->assertEquals($amount, $propertyAccessor->getValue($this->entity, $subtotal->getType()));
     }
 }
Exemplo n.º 11
0
 /**
  * @param Channel $entity
  * @param mixed $requestValue
  * @param string $expectedType
  *
  * @dataProvider handleRequestDataProvider
  */
 public function testHandleRequestChannelType(Channel $entity, $requestValue, $expectedType)
 {
     $this->request->setMethod('GET');
     $expectedEntity = clone $entity;
     $expectedEntity->setChannelType($expectedType);
     $this->form->expects($this->once())->method('setData')->with($expectedEntity);
     $this->form->expects($this->never())->method('submit');
     $this->dispatcher->expects($this->never())->method('dispatch');
     $this->request->request->set('orocrm_channel_form', ['channelType' => $requestValue]);
     $this->handler->process($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function testProcessValidData()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $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(true));
     $this->sendEmailForm->expects($this->once())->method('getData')->will($this->returnValue(true));
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->assertTrue($this->handler->process($this->entity));
 }
Exemplo n.º 13
0
 /**
  * @dataProvider processValidDataProvider
  *
  * @param bool $isDataChanged
  */
 public function testProcessValidData($isDataChanged)
 {
     $appendedAccount = new Account();
     $appendedAccount->setId(1);
     $removedAccount = new Account();
     $removedAccount->setId(2);
     $this->entity->addAccount($removedAccount);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $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(array($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(array($removedAccount)));
     $this->form->expects($this->at(4))->method('get')->with('removeAccounts')->will($this->returnValue($removeForm));
     if ($isDataChanged) {
         $this->manager->expects($this->once())->method('persist')->with($this->entity);
     } else {
         $this->manager->expects($this->exactly(2))->method('persist')->with($this->entity);
     }
     $this->manager->expects($this->once())->method('flush');
     $this->configureUnitOfWork($isDataChanged);
     $this->assertTrue($this->handler->process($this->entity));
     $actualAccounts = $this->entity->getAccounts()->toArray();
     $this->assertCount(1, $actualAccounts);
     $this->assertEquals($appendedAccount, current($actualAccounts));
 }
Exemplo n.º 14
0
 public function testProcessValidData()
 {
     $appendedUser = new User();
     $appendedUser->setId(1);
     $removedUser = new User();
     $removedUser->setId(2);
     $removedUser->addBusinessUnit($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(array($appendedUser)));
     $this->form->expects($this->at(3))->method('get')->with('appendUsers')->will($this->returnValue($appendForm));
     $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedUser)));
     $this->form->expects($this->at(4))->method('get')->with('removeUsers')->will($this->returnValue($removeForm));
     $this->manager->expects($this->at(0))->method('persist')->with($appendedUser);
     $this->manager->expects($this->at(1))->method('persist')->with($removedUser);
     $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));
     $businessUnits = $appendedUser->getBusinessUnits()->toArray();
     $this->assertCount(1, $businessUnits);
     $this->assertEquals($this->entity, current($businessUnits));
     $this->assertCount(0, $removedUser->getBusinessUnits()->toArray());
 }
Exemplo n.º 15
0
 public function testProcessWithoutContactViewPermission()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->form->expects($this->once())->method('has')->with('contacts')->will($this->returnValue(false));
     $this->form->expects($this->never())->method('get');
     $this->assertTrue($this->handler->process($this->entity));
     $actualContacts = $this->entity->getContacts()->toArray();
     $this->assertCount(0, $actualContacts);
     $this->assertEquals(array(), $actualContacts);
 }
Exemplo n.º 16
0
 public function testProcessNotExistingLineItem()
 {
     $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT'));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\Repository\\LineItemRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(null));
     $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $manager->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($repository));
     $manager->expects($this->once())->method('persist')->with($this->lineItem);
     $manager->expects($this->once())->method('flush');
     $this->registry->expects($this->once())->method('getManagerForClass')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($manager));
     $handler = new LineItemHandler($this->form, $this->request, $this->registry);
     $this->assertTrue($handler->process($this->lineItem));
     $this->assertEquals([], $handler->updateSavedId([]));
 }
Exemplo n.º 17
0
 public function testProcessWithoutLeadViewPermission()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->form->expects($this->any())->method('has')->will($this->returnValueMap([['leads', false], ['opportunities', false]]));
     $this->form->expects($this->never())->method('get');
     $this->assertTrue($this->handler->process($this->entity));
     $actualLeads = $this->entity->getLeads()->toArray();
     $actualOpportunities = $this->entity->getOpportunities()->toArray();
     $this->assertCount(0, $actualLeads);
     $this->assertEquals([], $actualLeads);
     $this->assertCount(0, $actualOpportunities);
     $this->assertEquals([], $actualOpportunities);
 }
Exemplo n.º 18
0
 /**
  * @dataProvider supportedMethods
  *
  * @param string $method
  */
 public function testProcessValidDataWithTargetEntityActivity($method)
 {
     $targetEntity = new TestTarget(123);
     $action = 'activity';
     $this->request->setMethod($method);
     $this->form->expects($this->once())->method('setData')->with($this->identicalTo($this->entity));
     $this->form->expects($this->once())->method('submit')->with($this->identicalTo($this->request));
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->entityRoutingHelper->expects($this->once())->method('getAction')->with($this->identicalTo($this->request))->will($this->returnValue($action));
     $this->entityRoutingHelper->expects($this->once())->method('getEntityClassName')->with($this->identicalTo($this->request))->will($this->returnValue(get_class($targetEntity)));
     $this->entityRoutingHelper->expects($this->once())->method('getEntityId')->with($this->identicalTo($this->request))->will($this->returnValue($targetEntity->getId()));
     $this->entityRoutingHelper->expects($this->once())->method('getEntityReference')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity));
     $this->activityManager->expects($this->once())->method('addActivityTarget')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     $this->om->expects($this->once())->method('persist')->with($this->identicalTo($this->entity));
     $this->om->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
 }
Exemplo n.º 19
0
 /**
  * @dataProvider formViewDataProvider
  *
  * @param bool $isUpdateMode
  */
 public function testGetFormView($isUpdateMode)
 {
     $this->request->query->set(IntegrationChannelHandler::UPDATE_MARKER, $isUpdateMode);
     $form = $this->form;
     if ($isUpdateMode) {
         $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface');
         $formConfig = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
         $formFactory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface');
         $formType = $this->getMock('Symfony\\Component\\Form\\ResolvedFormTypeInterface');
         $formConfig->expects($this->once())->method('getFormFactory')->will($this->returnValue($formFactory));
         $formConfig->expects($this->once())->method('getType')->will($this->returnValue($formType));
         $formType->expects($this->once())->method('getName')->will($this->returnValue('type' . self::TEST_NAME));
         $this->form->expects($this->once())->method('getName')->will($this->returnValue('form' . self::TEST_NAME));
         $this->form->expects($this->once())->method('getConfig')->will($this->returnValue($formConfig));
         $formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));
     }
     $form->expects($this->once())->method('createView')->will($this->returnValue($this->getFormView()));
     $this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $this->handler->getFormView());
 }
 public function testProcessNotExistingLineItem()
 {
     $this->request = Request::create('/', 'PUT');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     /** @var \PHPUnit_Framework_MockObject_MockObject|LineItemRepository $repository */
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\Repository\\LineItemRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(null));
     /** @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface $manager */
     $manager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');
     $manager->expects($this->once())->method('beginTransaction');
     $manager->expects($this->once())->method('commit');
     $manager->expects($this->never())->method('rollback');
     $manager->expects($this->once())->method('persist')->with($this->lineItem);
     $manager->expects($this->once())->method('flush');
     $manager->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($repository));
     $this->registry->expects($this->once())->method('getManagerForClass')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($manager));
     $handler = new LineItemHandler($this->form, $this->request, $this->registry, $this->shoppingListManager);
     $this->assertTrue($handler->process($this->lineItem));
     $this->assertEquals([], $handler->updateSavedId([]));
 }
Exemplo n.º 21
0
 /**
  * @dataProvider supportedMethods
  *
  * @param string $method
  */
 public function testProcessValidDataWithTargetEntity($method)
 {
     $this->entity->setPhoneNumber('phone1');
     $targetEntity = new TestTarget(123);
     $targetEntity1 = new TestTarget(456);
     $this->request->query->set('entityClass', get_class($targetEntity));
     $this->request->query->set('entityId', $targetEntity->getId());
     $this->formFactory->expects($this->once())->method('createNamed')->with('orocrm_call_form', 'orocrm_call_form', $this->entity, [])->will($this->returnValue($this->form));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $this->phoneProvider->expects($this->never())->method('getPhoneNumber');
     $this->phoneProvider->expects($this->once())->method('getPhoneNumbers')->with($this->identicalTo($targetEntity))->will($this->returnValue([['phone1', $targetEntity], ['phone2', $targetEntity], ['phone1', $targetEntity1]]));
     $this->entityRoutingHelper->expects($this->once())->method('getEntity')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity));
     // phone1, $targetEntity
     $this->callActivityManager->expects($this->at(0))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     // phone2, $targetEntity
     $this->callActivityManager->expects($this->at(1))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity));
     // phone1, $targetEntity1
     $this->callActivityManager->expects($this->at(2))->method('addAssociation')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity1));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->request->setMethod($method);
     $this->assertTrue($this->handler->process($this->entity));
 }
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject|FormInterface $form
  * @param string $message
  * @param array $messageParameters
  */
 public function assertFormErrorAdded($form, $message, array $messageParameters = [])
 {
     $this->translator->expects($this->once())->method('trans')->with($message, $messageParameters)->will($this->returnValue($message));
     $form->expects($this->once())->method('addError')->with(new FormError($message));
 }