Ejemplo n.º 1
0
 /**
  * @param string  $key
  * @param Account $entity
  */
 public function fillEntityData($key, $entity)
 {
     $userRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\UserBundle\\Entity\\User');
     $contactRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact');
     switch ($key) {
         case 'Coleman':
             $entity->setId(1)->setName($key)->setOwner($userRepo->getEntity('John Doo'))->addContact($contactRepo->getEntity('Jerry Coleman'))->setDefaultContact($contactRepo->getEntity('Jerry Coleman'));
             return;
         case 'Smith':
             $entity->setId(2)->setName($key)->setOwner($userRepo->getEntity('John Doo'))->addContact($contactRepo->getEntity('John Smith'))->setDefaultContact($contactRepo->getEntity('John Smith'));
             return;
     }
     parent::fillEntityData($key, $entity);
 }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 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());
 }