public function testMakeRecipientsForDynamicTriggeredModelUserManagerOfOwner()
 {
     $form = new DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $form->dynamicUserType = DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_MANAGER_OF_OWNER;
     $model = new WorkflowModelTestItem();
     $model->setScenario('importModel');
     $model->lastName = 'lastName';
     $model->string = 'string';
     $model->createdByUser = User::getById(self::$bobbyUserId);
     $model->modifiedByUser = User::getById(self::$sarahUserId);
     $this->assertTrue($model->save());
     $modelId = $model->id;
     $model->forget();
     $model = WorkflowModelTestItem::getById($modelId);
     $recipients = $form->makeRecipients($model, Yii::app()->user->userModel);
     $this->assertEquals(1, count($recipients));
     $this->assertEquals('superBoss superBossson', $recipients[0]->toName);
     $this->assertEquals('*****@*****.**', $recipients[0]->toAddress);
     $this->assertEquals(self::$superBossUserId, $recipients[0]->personsOrAccounts[0]->id);
 }
 /**
  * @param RedBeanModel $model
  * @param User $triggeredByUser
  * @return array
  * @throws NotSupportedException
  */
 public function makeRecipients(RedBeanModel $model, User $triggeredByUser)
 {
     $modelClassName = $this->modelClassName;
     $recipients = array();
     if ($model->isADerivedRelationViaCastedUpModel($this->relation) && $model->getDerivedRelationType($this->relation) == RedBeanModel::MANY_MANY) {
         foreach (WorkflowUtil::resolveDerivedModels($model, $this->relation) as $resolvedModel) {
             $recipients = self::resolveRecipientsAsUniquePeople($recipients, parent::makeRecipients($resolvedModel, $triggeredByUser));
         }
     } elseif ($modelClassName::getInferredRelationModelClassNamesForRelation(ModelRelationsAndAttributesToWorkflowAdapter::resolveRealAttributeName($this->relation)) != null) {
         foreach (WorkflowUtil::getInferredModelsByAtrributeAndModel($this->relation, $model) as $resolvedModel) {
             $recipients = self::resolveRecipientsAsUniquePeople($recipients, parent::makeRecipients($resolvedModel, $triggeredByUser));
         }
     } elseif ($model->{$this->relation} instanceof RedBeanMutableRelatedModels) {
         if (!$this->relationFilter == self::RELATION_FILTER_ALL) {
             throw new NotSupportedException();
         }
         foreach ($model->{$this->relation} as $resolvedModel) {
             $recipients = self::resolveRecipientsAsUniquePeople($recipients, parent::makeRecipients($resolvedModel, $triggeredByUser));
         }
     } elseif ($modelClassName::isRelationTypeAHasOneVariant($this->relation)) {
         if ($model->{$this->relation}->id > 0) {
             $recipients = parent::makeRecipients($model->{$this->relation}, $triggeredByUser);
         }
     } else {
         throw new NotSupportedException();
     }
     return $recipients;
 }