public function testPostWithContactEmail() { $client = $this->createAuthenticatedClient(); // no user-email passed, but a unique contact-email // so the controller should use the contact-email as the user-email as well $client->request('POST', '/api/users', ['username' => 'hikari', 'password' => 'verysecurepassword', 'locale' => 'en', 'contact' => ['id' => $this->contact1->getId(), 'emails' => [['email' => $this->contact1->getEmails()[0]->getEmail()]]], 'userRoles' => [['role' => ['id' => $this->role1->getId()], 'locales' => '["de"]']]]); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals('hikari', $response->username); $this->assertEquals('*****@*****.**', $response->email); $this->assertEquals($this->contact1->getId(), $response->contact->id); $this->assertEquals($this->contact1->getEmails()[0]->getEmail(), $response->contact->emails[0]->email); }
/** * sets Entity's Main-Email. * * @param Contact|AccountInterface $entity */ public function setMainEmail($entity) { // set main to first entry or to null if ($entity->getEmails()->isEmpty()) { $entity->setMainEmail(null); } else { $entity->setMainEmail($entity->getEmails()->first()->getEmail()); } }