public function testMakeRecipientsForDynamicTriggeredModelRelation() { $form = new DynamicTriggeredModelRelationWorkflowEmailMessageRecipientForm('Account', Workflow::TYPE_ON_SAVE); $form->relation = 'contacts'; $model = new Account(); $model->name = 'the account'; $contact = new Contact(); $contact->firstName = 'Jason'; $contact->lastName = 'Blue'; $contact->state = ContactsUtil::getStartingState(); $contact->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact->save()); $contact2 = new Contact(); $contact2->firstName = 'Laura'; $contact2->lastName = 'Blue'; $contact2->state = ContactsUtil::getStartingState(); $contact2->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact2->save()); $model->contacts->add($contact); $model->contacts->add($contact2); $this->assertTrue($model->save()); $recipients = $form->makeRecipients($model, User::getById(self::$bobbyUserId)); $this->assertEquals(2, count($recipients)); $this->assertEquals('Jason Blue', $recipients[0]->toName); $this->assertEquals('*****@*****.**', $recipients[0]->toAddress); $this->assertEquals($contact->id, $recipients[0]->personsOrAccounts[0]->id); $this->assertEquals('Laura Blue', $recipients[1]->toName); $this->assertEquals('*****@*****.**', $recipients[1]->toAddress); $this->assertEquals($contact2->id, $recipients[1]->personsOrAccounts[0]->id); }