public function load(ObjectManager $manager) { $adminUser = $manager->getRepository('OroUserBundle:User')->findOneByUsername('admin'); $account = new Account(); $account->setName('Test Account #1'); $account->setOwner($adminUser); $manager->persist($account); $manager->flush(); $this->addReference('orocrm_partner:test_account_1', $account); $account = new Account(); $account->setName('Test Account #2'); $account->setOwner($adminUser); $manager->persist($account); $manager->flush(); $this->addReference('orocrm_partner:test_account_2', $account); $account = new Account(); $account->setName('Third Test Account'); $account->setOwner($adminUser); $manager->persist($account); $manager->flush(); $this->addReference('orocrm_partner:test_account_3', $account); $account = new Account(); $account->setName('Fourth Account'); $account->setOwner($adminUser); $manager->persist($account); $manager->flush(); $this->addReference('orocrm_partner:test_account_4', $account); $account = new Account(); $account->setName('Fifth Account'); $account->setOwner($adminUser); $manager->persist($account); $manager->flush(); $this->addReference('orocrm_partner:test_account_5', $account); }
/** * @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)); }
public function testOwners() { $entity = new Account(); $user = new User(); $this->assertEmpty($entity->getOwner()); $entity->setOwner($user); $this->assertEquals($user, $entity->getOwner()); }
/** * @param string $name * @return Account */ protected function createAccount($name) { $account = new Account(); $account->setName($name); $entityManager = $this->getEntityManager(); $entityManager->persist($account); $entityManager->flush($account); return $account; }
public function testGetEmail() { $account = new Account(); $contact = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $this->assertNull($account->getEmail()); $account->setDefaultContact($contact); $contact->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**')); $this->assertEquals('*****@*****.**', $account->getEmail()); }
/** * Load Accounts * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { foreach ($this->names as $name) { $account = new Account(); $account->setName($name . ' test account'); $this->setReference('Account_' . $name, $account); $manager->persist($account); } $manager->flush(); }
protected function createAccount() { $account = new Account(); $account->setName(self::ACCOUNT_NAME); $account->setOrganization($this->organization); $this->em->persist($account); $this->em->flush(); $this->setReference('default_account', $account); return $this; }
public function testRemoveAccount() { $account = new Account(); $account->setId(1); $contact = new Contact(); $contact->setId(2); $contact->addAccount($account); $this->assertCount(1, $contact->getAccounts()->toArray()); $contact->removeAccount($account); $this->assertEmpty($contact->getAccounts()->toArray()); }
/** * Gets a list of all phone numbers available for the given Account object * * @param Account $object * * @return array of [phone number, phone owner] */ public function getPhoneNumbers($object) { $defaultContact = $object->getDefaultContact(); $result = $defaultContact ? $this->rootProvider->getPhoneNumbers($defaultContact) : []; foreach ($object->getContacts() as $contact) { if ($contact !== $defaultContact) { $result = array_merge($result, $this->rootProvider->getPhoneNumbers($contact)); } } return $result; }
public function testGetPhoneNumbers() { $entity = new Account(); $contact1 = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $contact2 = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $entity->setDefaultContact($contact1); $entity->addContact($contact1); $entity->addContact($contact2); $this->rootProvider->expects($this->at(0))->method('getPhoneNumbers')->with($this->identicalTo($contact1))->will($this->returnValue([['123-123', $contact1], ['456-456', $contact1]])); $this->rootProvider->expects($this->at(1))->method('getPhoneNumbers')->with($this->identicalTo($contact2))->will($this->returnValue([['789-789', $contact2], ['111-111', $contact2]])); $this->assertEquals([['123-123', $contact1], ['456-456', $contact1], ['789-789', $contact2], ['111-111', $contact2]], $this->provider->getPhoneNumbers($entity)); }
/** * @param EntityManager $em * @param string $name * * @return Account */ protected function ensureAccountCreated(EntityManager $em, $name) { if (!isset($this->accounts[$name])) { $account = new Account(); $account->setName($name); $account->setOwner($this->getUser($em)); $em->persist($account); $em->flush($account); $this->accounts[$name] = $account; } return $this->accounts[$name]; }
/** * @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); }
public function testCreate() { $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_b2bcustomer_create')); $form = $crawler->selectButton('Save and Close')->form(); $name = 'name' . $this->generateRandomString(); $form['orocrm_sales_b2bcustomer_form[name]'] = $name; $form['orocrm_sales_b2bcustomer_form[account]'] = self::$account->getId(); $form['orocrm_sales_b2bcustomer_form[dataChannel]'] = self::$channel->getId(); $form['orocrm_sales_b2bcustomer_form[owner]'] = 1; $this->client->followRedirects(true); $crawler = $this->client->submit($form); $result = $this->client->getResponse(); $this->assertHtmlResponseStatusCodeEquals($result, 200); $this->assertContains("Customer saved", $crawler->html()); }
public function testSetDefaultContact() { $account = new Account(); $this->assertNull($account->getDefaultContact()); $contact = new Contact(); $account->setDefaultContact($contact); $this->assertSame($contact, $account->getDefaultContact()); $this->assertCount(1, $contact->getDefaultInAccounts()); $this->assertSame($account, $contact->getDefaultInAccounts()->first()); $contact2 = new Contact(); $account->setDefaultContact($contact2); $this->assertCount(0, $contact->getDefaultInAccounts()); $this->assertCount(1, $contact2->getDefaultInAccounts()); $this->assertSame($contact2, $account->getDefaultContact()); $this->assertSame($account, $contact2->getDefaultInAccounts()->first()); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { /** @var Organization $organization */ $organization = $this->getReference('default_organization'); $handle = fopen(__DIR__ . DIRECTORY_SEPARATOR . 'dictionaries' . DIRECTORY_SEPARATOR . "accounts.csv", "r"); $headers = fgetcsv($handle, 1000, ","); $companies = []; while (($data = fgetcsv($handle, 1000, ",")) !== false) { $data = array_combine($headers, array_values($data)); if (!isset($companies[$data['Company']])) { $account = new Account(); $account->setName($data['Company']); $account->setOwner($this->getRandomUserReference()); $account->setOrganization($organization); $this->em->persist($account); $companies[$data['Company']] = $data['Company']; } } fclose($handle); $this->em->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { /** @var Organization $organization */ $organization = $this->getReference('default_organization'); $dictionaryDir = $this->container->get('kernel')->locateResource('@OroCRMDemoDataBundle/Migrations/Data/Demo/ORM/dictionaries'); $handle = fopen($dictionaryDir . DIRECTORY_SEPARATOR . "accounts.csv", "r"); $headers = fgetcsv($handle, 1000, ","); $companies = []; while (($data = fgetcsv($handle, 1000, ",")) !== false) { $data = array_combine($headers, array_values($data)); if (!isset($companies[$data['Company']])) { $account = new Account(); $account->setName($data['Company']); $account->setOwner($this->getRandomUserReference()); $account->setOrganization($organization); $this->em->persist($account); $companies[$data['Company']] = $data['Company']; } } fclose($handle); $this->em->flush(); }
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); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /** @var UserManager $userManager */ $userManager = $this->container->get('oro_user.manager'); $role = $manager->getRepository('OroUserBundle:Role')->findOneByRole('ROLE_ADMINISTRATOR'); $group = $manager->getRepository('OroUserBundle:Group')->findOneByName('Administrators'); $unit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneByName('Main'); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); $user = new User(); $user->setUsername('somename'); $user->addGroup($group); $user->addRole($role); $user->addBusinessUnit($unit); $user->setFirstname('Test FirstName'); $user->setLastname('Test LastName'); $user->setEmail('*****@*****.**'); $user->setOwner($unit); $user->addGroup($group); $user->setPlainPassword('test password'); $user->setSalt(md5(mt_rand(1, 222))); $user->setOrganization($organization); $userManager->updateUser($user); $this->setReference('not_associated_entities_owner', $user); $account = new Account(); $account->setName('Some Test Name'); $account->setOwner($user); $account->setOrganization($organization); $manager->persist($account); $this->setReference('not_associated_account', $account); $contact = new Contact(); $contact->setFirstName('Test First Name'); $contact->setLastName('Test Last Name'); $contact->setOwner($user); $contact->setOrganization($organization); $manager->persist($contact); $this->setReference('not_associated_contact', $contact); $manager->flush(); }
/** * Create an Account * * @param array $data * @param int $iteration * @return Account */ private function createAccount(array $data, $iteration = 0) { /** @var $account Account */ $account = new Account(); $name = $data['Username'] . $data['MiddleInitial'] . '_' . $data['Surname']; if ($iteration) { $name .= '_' . $iteration; } $account->setName($name); return $account; }
/** * @Route("/widget/account-contacts/{id}", name="orocrm_account_widget_contacts", requirements={"id"="\d+"}) * @AclAncestor("orocrm_contact_view") * @Template() */ public function accountContactsAction(Account $account) { $defaultContact = $account->getDefaultContact(); $contacts = $account->getContacts(); $contactsWithoutDefault = array(); if (empty($defaultContact)) { $contactsWithoutDefault = $contacts->toArray(); } else { /** @var Contact $contact */ foreach ($contacts as $contact) { if ($contact->getId() == $defaultContact->getId()) { continue; } $contactsWithoutDefault[] = $contact; } } /** * Compare contacts to sort them alphabetically * * @param Contact $firstContact * @param Contact $secondContact * @return int */ $compareFunction = function ($firstContact, $secondContact) { $first = $firstContact->getLastName() . $firstContact->getFirstName() . $firstContact->getMiddleName(); $second = $secondContact->getLastName() . $secondContact->getFirstName() . $secondContact->getMiddleName(); return strnatcasecmp($first, $second); }; usort($contactsWithoutDefault, $compareFunction); return array('entity' => $account, 'defaultContact' => $defaultContact, 'contactsWithoutDefault' => $contactsWithoutDefault); }
/** * @return Account */ protected function createAccount() { $account = new Account(); $account->setName('acc'); $account->setOwner($this->getUser()); $account->setOrganization($this->organization); $this->em->persist($account); return $account; }
/** * Remove contacts from account * * @param Account $account * @param Contact[] $contacts */ protected function removeContacts(Account $account, array $contacts) { foreach ($contacts as $contact) { $account->removeContact($contact); } }