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));
 }
Example #2
0
 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);
 }
Example #3
0
 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);
 }