예제 #1
0
 public function testProcessValidData()
 {
     $appendedContact = new Contact();
     $appendedContact->setId(1);
     $removedContact = new Contact();
     $removedContact->setId(2);
     $this->entity->addContact($removedContact);
     $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(true));
     $contactsForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedContact)));
     $contactsForm->expects($this->at(0))->method('get')->with('added')->will($this->returnValue($appendForm));
     $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedContact)));
     $contactsForm->expects($this->at(1))->method('get')->with('removed')->will($this->returnValue($removeForm));
     $this->form->expects($this->exactly(1))->method('get')->with('contacts')->will($this->returnValue($contactsForm));
     $this->manager->expects($this->once())->method('persist')->with($this->entity);
     $this->manager->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->entity));
     $actualContacts = $this->entity->getContacts()->toArray();
     $this->assertCount(1, $actualContacts);
     $this->assertEquals($appendedContact, current($actualContacts));
 }
예제 #2
0
 /**
  * @param string  $key
  * @param Contact $entity
  */
 public function fillEntityData($key, $entity)
 {
     $userRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\UserBundle\\Entity\\User');
     $accountRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\AccountBundle\\Entity\\Account');
     $contactAddressRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\ContactBundle\\Entity\\ContactAddress');
     switch ($key) {
         case 'Jerry Coleman':
             $primaryAddress = $contactAddressRepo->getEntity('Jerry Coleman');
             $entity->setId(1)->setNamePrefix('Mr.')->setFirstName('Jerry')->setLastName('Coleman')->setNameSuffix('Jr.')->setBirthday(new \DateTime('1973-03-07'))->setGender('male')->setDescription('Sample Contact')->setJobTitle('Manager')->setFax('713-450-0721')->setSkype('crm-jerrycoleman')->setTwitter('crm-jerrycoleman')->setFacebook('crm-jerrycoleman')->setGooglePlus('https://plus.google.com/454646545646546')->setLinkedIn('http://www.linkedin.com/in/crm-jerrycoleman')->setSource($this->createContactSource('website'))->setMethod($this->createContactMethod('phone'))->setOwner($userRepo->getEntity('John Doo'))->setAssignedTo($userRepo->getEntity('John Doo'))->addEmail($this->createContactEmail('*****@*****.**', true))->addEmail($this->createContactEmail('*****@*****.**'))->addEmail($this->createContactEmail('*****@*****.**'))->addPhone($this->createContactPhone('585-255-1127', true))->addPhone($this->createContactPhone('914-412-0298'))->addPhone($this->createContactPhone('310-430-7876'))->addGroup($this->createContactGroup('Sales Group'))->addGroup($this->createContactGroup('Marketing Group'))->addAccount($accountRepo->getEntity('Coleman'))->addAccount($accountRepo->getEntity('Smith'))->addAddress($primaryAddress)->addAddress($this->createContactAddress('Jerry Coleman', 2))->addAddress($this->createContactAddress('Jerry Coleman', 3))->setPrimaryAddress($primaryAddress);
             return;
         case 'John Smith':
             $primaryAddress = $this->createContactAddress('John Smith', 1);
             $entity->setId(2)->setNamePrefix('Mr.')->setFirstName('John')->setLastName('Smith')->setNameSuffix('Jr.')->setBirthday(new \DateTime('1973-03-07'))->setGender('male')->setDescription('Sample Contact')->setJobTitle('Manager')->setFax('713-450-0721')->setSkype('crm-johnsmith')->setTwitter('crm-johnsmith')->setFacebook('crm-johnsmith')->setGooglePlus('https://plus.google.com/343535434535435')->setLinkedIn('http://www.linkedin.com/in/crm-johnsmith')->setSource($this->createContactSource('website'))->setMethod($this->createContactMethod('phone'))->setOwner($userRepo->getEntity('John Doo'))->setAssignedTo($userRepo->getEntity('John Doo'))->addEmail($this->createContactEmail('*****@*****.**', true))->addEmail($this->createContactEmail('*****@*****.**'))->addEmail($this->createContactEmail('*****@*****.**'))->addPhone($this->createContactPhone('585-255-1127', true))->addPhone($this->createContactPhone('914-412-0298'))->addPhone($this->createContactPhone('310-430-7876'))->addGroup($this->createContactGroup('Sales Group'))->addGroup($this->createContactGroup('Marketing Group'))->addAccount($accountRepo->getEntity('Smith'))->addAccount($accountRepo->getEntity('Coleman'))->addAddress($primaryAddress)->addAddress($this->createContactAddress('John Smith', 2))->addAddress($this->createContactAddress('John Smith', 3))->setPrimaryAddress($primaryAddress);
             return;
     }
     parent::fillEntityData($key, $entity);
 }
예제 #3
0
 public function testRemoveContact()
 {
     $account = new Account();
     $account->setId(1);
     $contact = new Contact();
     $contact->setId(2);
     $account->addContact($contact);
     $this->assertCount(1, $account->getContacts()->toArray());
     $account->removeContact($contact);
     $this->assertEmpty($account->getContacts()->toArray());
 }