public function testCreateEmailMessageForm() { $emailMessage = new EmailMessage(); $emailMessageForm = new CreateEmailMessageForm($emailMessage); $emailMessageForm->setScenario('createNonDraft'); $this->assertFalse($emailMessageForm->validate()); $this->assertEquals('To address cannot be blank', $emailMessageForm->getError('recipientsData_to')); $this->assertEquals('Subject cannot be blank.', $emailMessageForm->getModel()->getError('subject')); $this->assertEquals('Folder cannot be blank.', $emailMessageForm->getModel()->getError('folder')); $this->assertEquals('Sender cannot be blank.', $emailMessageForm->getModel()->getError('sender')); $messageRecipient = new EmailMessageRecipient(); $messageRecipient->toAddress = '*****@*****.**'; $messageRecipient->type = EmailMessageRecipient::TYPE_TO; $emailMessage->recipients->add($messageRecipient); $emailMessageForm = new CreateEmailMessageForm($emailMessage); $emailMessageForm->setScenario('createNonDraft'); $this->assertNull($emailMessageForm->getError('recipientsData_to')); }
protected function actionValidateCreateEmailMessage($postData, CreateEmailMessageForm $emailMessageForm) { if (isset($postData['ajax']) && $postData['ajax'] == 'edit-form') { $emailMessageForm->setAttributes($postData[get_class($emailMessageForm)]); if ($emailMessageForm->validate()) { Yii::app()->end(false); } else { $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($emailMessageForm); echo CJSON::encode($errorData); } Yii::app()->end(false); } }