private function createAccount($name) { $account = new Account(); $account->setName($name); $this->em->persist($account); return $account; }
public function testAccountMediaDeleteNotExistingRelation() { $client = $this->createAuthenticatedClient(); $client->request('DELETE', '/api/accounts/' . $this->account->getId() . '/medias/99'); $this->assertEquals('404', $client->getResponse()->getStatusCode()); $client->request('GET', '/api/accounts/' . $this->account->getId()); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals(1, count($response->medias)); }
private function createAccount($name, $tags = [], $categories = []) { $account = new Account(); $account->setName($name); foreach ($tags as $tag) { $account->addTag($this->tags[$tag]); } foreach ($categories as $category) { $account->addCategory($this->categories[$category]); } $this->em->persist($account); return $account; }
public function testPrimaryAddressHandlingPut() { $client = $this->createAuthenticatedClient(); $client->request('PUT', '/api/accounts/' . $this->account->getId(), ['name' => 'ExampleCompany', 'urls' => [['id' => $this->url->getId(), 'url' => 'http://example.company.com', 'urlType' => ['id' => $this->urlType->getId(), 'name' => 'Private']], ['url' => 'http://test.company.com', 'urlType' => ['id' => $this->urlType->getId(), 'name' => 'Private']]], 'emails' => [['email' => '*****@*****.**', 'emailType' => ['id' => $this->emailType->getId(), 'name' => 'Private']], ['email' => '*****@*****.**', 'emailType' => ['id' => $this->emailType->getId(), 'name' => 'Private']]], 'addresses' => [['id' => $this->address->getId(), 'street' => 'Bahnhofstraße', 'number' => '2', 'zip' => '0022', 'city' => 'Dornbirn', 'state' => 'state1', 'country' => ['id' => $this->country->getId(), 'name' => 'Musterland', 'code' => 'ML'], 'addressType' => ['id' => $this->addressType->getId(), 'name' => 'Private'], 'billingAddress' => true, 'primaryAddress' => true, 'deliveryAddress' => false, 'postboxCity' => 'Dornbirn', 'postboxPostcode' => '6850', 'postboxNumber' => '4711'], ['street' => 'Rathausgasse 1', 'number' => '3', 'zip' => '2222', 'city' => 'Dornbirn', 'state' => 'state1', 'country' => ['id' => $this->country->getId(), 'name' => 'Musterland', 'code' => 'ML'], 'addressType' => ['id' => $this->addressType->getId(), 'name' => 'Private'], 'billingAddress' => true, 'primaryAddress' => true, 'deliveryAddress' => false, 'postboxCity' => 'Dornbirn', 'postboxPostcode' => '6850', 'postboxNumber' => '4711'], ['street' => 'Rathausgasse 2', 'number' => '3', 'zip' => '2222', 'city' => 'Dornbirn', 'state' => 'state1', 'country' => ['id' => $this->country->getId(), 'name' => 'Musterland', 'code' => 'ML'], 'addressType' => ['id' => $this->addressType->getId(), 'name' => 'Private'], 'billingAddress' => true, 'primaryAddress' => true, 'deliveryAddress' => false, 'postboxCity' => 'Dornbirn', 'postboxPostcode' => '6850', 'postboxNumber' => '4711']]]); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); usort($response->addresses, $this->sortAddressesPrimaryLast()); $this->assertEquals(false, $response->addresses[0]->primaryAddress); $this->assertEquals(false, $response->addresses[1]->primaryAddress); $this->assertEquals(true, $response->addresses[2]->primaryAddress); $client->request('GET', '/api/accounts/' . $this->account->getId()); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); usort($response->addresses, $this->sortAddressesPrimaryLast()); $this->assertEquals(false, $response->addresses[0]->primaryAddress); $this->assertEquals(false, $response->addresses[1]->primaryAddress); $this->assertEquals(true, $response->addresses[2]->primaryAddress); }
public function testPrimaryAddressHandlingPost() { $client = $this->createTestClient(); $client->request('POST', '/api/contacts', ['firstName' => 'Erika', 'lastName' => 'Mustermann', 'title' => 'MSc', 'position' => ['id' => $this->contactPosition->getId(), 'position' => $this->contactPosition->getPosition()], 'account' => ['id' => $this->account1->getId()], 'emails' => [['email' => '*****@*****.**', 'emailType' => ['id' => $this->emailType->getId(), 'name' => 'Private']], ['email' => '*****@*****.**', 'emailType' => ['id' => $this->emailType->getId(), 'name' => 'Private']]], 'addresses' => [['street' => 'Musterstraße', 'number' => '1', 'zip' => '0000', 'city' => 'Musterstadt', 'state' => 'Musterstate', 'country' => ['id' => $this->country->getId(), 'name' => 'Musterland', 'code' => 'ML'], 'addressType' => ['id' => $this->addressType->getId(), 'name' => 'Private'], 'billingAddress' => true, 'primaryAddress' => true, 'deliveryAddress' => false, 'postboxCity' => 'Dornbirn', 'postboxPostcode' => '6850', 'postboxNumber' => '4711'], ['street' => 'Musterstraße 2', 'number' => '1', 'zip' => '0000', 'city' => 'Musterstadt', 'state' => 'Musterstate', 'country' => ['id' => $this->country->getId(), 'name' => 'Musterland', 'code' => 'ML'], 'addressType' => ['id' => $this->addressType->getId(), 'name' => 'Private'], 'billingAddress' => true, 'primaryAddress' => true, 'deliveryAddress' => false, 'postboxCity' => 'Dornbirn', 'postboxPostcode' => '6850', 'postboxNumber' => '4711']], 'notes' => [['value' => 'Note 1'], ['value' => 'Note 2']], 'salutation' => 'Sehr geehrte Frau Dr Mustermann', 'formOfAddress' => ['id' => 0]]); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals($this->account1->getId(), $response->account->id); $this->assertEquals(false, $response->addresses[0]->primaryAddress); $this->assertEquals(true, $response->addresses[1]->primaryAddress); $client->request('GET', '/api/contacts/' . $response->id); $response = json_decode($client->getResponse()->getContent(), true); $addresses = $response['addresses']; $filterKeys = ['primaryAddress', 'street']; $filteredAddresses = array_map(function ($address) use($filterKeys) { return array_intersect_key($address, array_flip($filterKeys)); }, $addresses); $this->assertContains(['primaryAddress' => false, 'street' => 'Musterstraße'], $filteredAddresses); $this->assertContains(['primaryAddress' => true, 'street' => 'Musterstraße 2'], $filteredAddresses); }
public function initOrm() { $this->purgeDatabase(); $contact = new Contact(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $contact->setPosition('CEO'); $contact->setFormOfAddress(1); $contact->setSalutation('Sehr geehrter Herr Dr Mustermann'); $this->contact = $contact; $title = new ContactTitle(); $title->setTitle('MSc'); $contact->setTitle($title); $position = new Position(); $position->setPosition('Manager'); $account = new Account(); $account->setLft(0); $account->setRgt(1); $account->setDepth(0); $account->setName('Musterfirma'); $account1 = new Account(); $account1->setLft(0); $account1->setRgt(1); $account1->setDepth(0); $account1->setName('Musterfirma'); $phoneType = new PhoneType(); $phoneType->setName('Private'); $phone = new Phone(); $phone->setPhone('123456789'); $phone->setPhoneType($phoneType); $contact->addPhone($phone); $emailType = new EmailType(); $emailType->setName('Private'); $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $contact->addEmail($email); $faxType = new FaxType(); $faxType->setName('Private'); $this->faxType = $faxType; $fax = new Fax(); $fax->setFax('123654789'); $fax->setFaxType($faxType); $contact->addFax($fax); $country1 = new Country(); $country1->setName('Musterland'); $country1->setCode('ML'); $country2 = new Country(); $country2->setName('United States'); $country2->setCode('US'); $addressType = new AddressType(); $addressType->setName('Private'); $address = new Address(); $address->setStreet('Musterstraße'); $address->setNumber('1'); $address->setZip('0000'); $address->setCity('Musterstadt'); $address->setState('Musterland'); $address->setCountry($country1); $address->setAddressType($addressType); $address->setBillingAddress(true); $address->setPrimaryAddress(true); $address->setDeliveryAddress(false); $address->setPostboxCity('Dornbirn'); $address->setPostboxPostcode('6850'); $address->setPostboxNumber('4711'); $contactAddress = new ContactAddress(); $contactAddress->setAddress($address); $contactAddress->setContact($contact); $contactAddress->setMain(true); $contact->addContactAddress($contactAddress); $address->addContactAddress($contactAddress); $note = new Note(); $note->setValue('Note'); $contact->addNote($note); $this->setUpMediaEntities($contact); $this->em->persist($contact); $this->em->persist($title); $this->em->persist($position); $this->em->persist($account); $this->em->persist($account1); $this->em->persist($phoneType); $this->em->persist($phone); $this->em->persist($faxType); $this->em->persist($fax); $this->em->persist($emailType); $this->em->persist($email); $this->em->persist($country1); $this->em->persist($country2); $this->em->persist($addressType); $this->em->persist($contactAddress); $this->em->persist($address); $this->em->persist($note); $this->em->flush(); }
/** * Sets the medias of the given account to the given medias. * Currently associated medias are replaced. * * @param Account $account * @param $medias * * @throws EntityNotFoundException */ public function setMedias(Account $account, $medias) { $mediaIds = array_map(function ($media) { return $media['id']; }, $medias); $foundMedias = $this->mediaRepository->findById($mediaIds); $foundMediaIds = array_map(function ($mediaEntity) { return $mediaEntity->getId(); }, $foundMedias); if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) { throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds)); } $account->getMedias()->clear(); foreach ($foundMedias as $media) { $account->addMedia($media); } }
/** * Takes an account-entity and the id of a media and adds the media as the logo of the account. * TODO: handle logo adding differently and remove this method (or make it private). * * @param Account $account * @param int $mediaId */ public function setLogo($account, $mediaId) { $media = $this->mediaManager->getEntityById($mediaId); $account->setLogo($media); }
private function initOrm() { $this->purgeDatabase(); $contact = new Contact(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $contact->setPosition('CEO'); $contact->setFormOfAddress(1); $contact->setSalutation('Sehr geehrter Herr Dr Mustermann'); $contact->setDisabled(0); $this->contact = $contact; $title = new ContactTitle(); $title->setTitle('MSc'); $contact->setTitle($title); $position = new Position(); $position->setPosition('Manager'); $account = new Account(); $account->setLft(0); $account->setRgt(1); $account->setDepth(0); $account->setName('Musterfirma'); $this->account = $account; $account1 = new Account(); $account1->setLft(0); $account1->setRgt(1); $account1->setDepth(0); $account1->setName('Musterfirma'); $this->account1 = $account1; $phoneType = new PhoneType(); $phoneType->setName('Private'); $this->phoneType = $phoneType; $phone = new Phone(); $phone->setPhone('123456789'); $phone->setPhoneType($phoneType); $contact->addPhone($phone); $this->phone = $phone; $emailType = new EmailType(); $emailType->setName('Private'); $this->emailType = $emailType; $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $contact->addEmail($email); $this->email = $email; $faxType = new FaxType(); $faxType->setName('Private'); $this->faxType = $faxType; $fax = new Fax(); $fax->setFax('123654789'); $fax->setFaxType($faxType); $contact->addFax($fax); $this->fax = $fax; $country1 = new Country(); $country1->setName('Musterland'); $country1->setCode('ML'); $this->country = $country1; $country2 = new Country(); $country2->setName('United States'); $country2->setCode('US'); $this->country2 = $country2; $addressType = new AddressType(); $addressType->setName('Private'); $this->addressType = $addressType; $address = new Address(); $address->setStreet('Musterstraße'); $address->setNumber('1'); $address->setZip('0000'); $address->setCity('Musterstadt'); $address->setState('Musterland'); $address->setCountry($country1); $address->setAddressType($addressType); $address->setBillingAddress(true); $address->setPrimaryAddress(true); $address->setDeliveryAddress(false); $address->setPostboxCity('Dornbirn'); $address->setPostboxPostcode('6850'); $address->setPostboxNumber('4711'); $address->setNote('Note'); $this->address = $address; $contactAddress = new ContactAddress(); $contactAddress->setAddress($address); $contactAddress->setContact($contact); $contactAddress->setMain(true); $this->contactAddress = $contactAddress; $contact->addContactAddress($contactAddress); $address->addContactAddress($contactAddress); $note = new Note(); $note->setValue('Note'); $this->note = $note; $contact->addNote($note); $this->em->persist($contact); $this->em->persist($title); $this->em->persist($position); $this->em->persist($account); $this->em->persist($account1); $this->em->persist($phoneType); $this->em->persist($phone); $this->em->persist($faxType); $this->em->persist($fax); $this->em->persist($emailType); $this->em->persist($email); $this->em->persist($country1); $this->em->persist($country2); $this->em->persist($addressType); $this->em->persist($contactAddress); $this->em->persist($address); $this->em->persist($note); /* First Category -------------------------------------*/ $category = new Category(); $category->setKey('first-category-key'); $this->category = $category; // name for first category $categoryTrans = new CategoryTranslation(); $categoryTrans->setLocale('en'); $categoryTrans->setTranslation('First Category'); $categoryTrans->setCategory($category); $category->addTranslation($categoryTrans); // meta for first category $categoryMeta = new CategoryMeta(); $categoryMeta->setLocale('en'); $categoryMeta->setKey('description'); $categoryMeta->setValue('Description of Category'); $categoryMeta->setCategory($category); $category->addMeta($categoryMeta); $this->em->persist($category); /* Second Category -------------------------------------*/ $category2 = new Category(); $category2->setKey('second-category-key'); $this->category2 = $category2; // name for second category $categoryTrans2 = new CategoryTranslation(); $categoryTrans2->setLocale('de'); $categoryTrans2->setTranslation('Second Category'); $categoryTrans2->setCategory($category2); $category2->addTranslation($categoryTrans2); // meta for second category $categoryMeta2 = new CategoryMeta(); $categoryMeta2->setLocale('de'); $categoryMeta2->setKey('description'); $categoryMeta2->setValue('Description of second Category'); $categoryMeta2->setCategory($category2); $category2->addMeta($categoryMeta2); $this->em->persist($category2); $this->em->flush(); $this->contactTitle = $title; $this->contactPosition = $position; }