Пример #1
0
 public function testProcessGetRequestWithNewEntity()
 {
     $targetEntity = new TestTarget(123);
     $targetEntity1 = new TestTarget(456);
     $this->request->query->set('entityClass', get_class($targetEntity));
     $this->request->query->set('entityId', $targetEntity->getId());
     $this->phoneProvider->expects($this->once())->method('getPhoneNumber')->with($this->identicalTo($targetEntity))->will($this->returnValue('phone2'));
     $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));
     $this->formFactory->expects($this->once())->method('createNamed')->with('orocrm_call_form', 'orocrm_call_form', $this->entity, ['phone_suggestions' => ['phone1', 'phone2']])->will($this->returnValue($this->form));
     $this->form->expects($this->never())->method('submit');
     $this->assertFalse($this->handler->process($this->entity));
     $this->assertEquals('phone2', $this->entity->getPhoneNumber());
 }
Пример #2
0
 /**
  * @param ObjectManager $om
  */
 protected function persistDemoCalls(ObjectManager $om)
 {
     $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll();
     $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll();
     $callStatus = $om->getRepository('OroCRMCallBundle:CallStatus')->findOneBy(['name' => 'completed']);
     $directions = ['incoming' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(['name' => 'incoming']), 'outgoing' => $om->getRepository('OroCRMCallBundle:CallDirection')->findOneBy(['name' => 'outgoing'])];
     $contactCount = count($contacts);
     $accountCount = count($accounts);
     for ($i = 0; $i < 100; ++$i) {
         $contactRandom = rand(0, $contactCount - 1);
         $accountRandom = rand(0, $accountCount - 1);
         /** @var Contact $contact */
         $contact = $contacts[$contactRandom];
         /** @var Account $account */
         $account = $accounts[$accountRandom];
         $call = new Call();
         $call->setCallStatus($callStatus);
         $call->setOrganization($this->organization);
         $call->setOwner($contact->getOwner());
         $call->setSubject($this->subjects[array_rand($this->subjects)]);
         $call->setDuration(new \DateTime(rand(0, 1) . ':' . rand(0, 59) . ':' . rand(0, 59), new \DateTimeZone('UTC')));
         if ($call->supportActivityTarget(get_class($contact->getOwner()))) {
             $call->addActivityTarget($contact->getOwner());
         }
         $randomPath = rand(1, 10);
         if ($randomPath > 2) {
             if ($call->supportActivityTarget(get_class($contact))) {
                 $this->setSecurityContext($contact->getOwner());
                 $call->addActivityTarget($contact);
             }
             $contactPrimaryPhone = $contact->getPrimaryPhone();
             if ($contactPrimaryPhone) {
                 $call->setPhoneNumber($contactPrimaryPhone->getPhone());
             }
             $call->setDirection($directions['outgoing']);
         }
         if ($randomPath > 3) {
             /** @var Contact[] $relatedContacts */
             $relatedContacts = $call->getActivityTargets('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact');
             if ($relatedContacts) {
                 if ($call->supportActivityTarget(get_class($relatedContacts[0]->getAccounts()[0]))) {
                     $call->addActivityTarget($relatedContacts[0]->getAccounts()[0]);
                 }
             } else {
                 if ($call->supportActivityTarget(get_class($account))) {
                     $call->addActivityTarget($account);
                 }
             }
         }
         $phone = $call->getPhoneNumber();
         if (empty($phone)) {
             $phone = rand(1000000000, 9999999999);
             $phone = sprintf("%s-%s-%s", substr($phone, 0, 3), substr($phone, 3, 3), substr($phone, 6));
             $call->setPhoneNumber($phone);
             $call->setDirection($directions['incoming']);
         }
         $om->persist($call);
     }
 }