/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (!isset($_SESSION['filemanager'])) { $_SESSION['filemanager'] = TRUE; } $_SESSION['currentFolder'] = 'emailTemplate/'; $model = new EmailTemplate('create'); if (isset($_POST['EmailTemplate'])) { $model->attributes = $_POST['EmailTemplate']; if ($model->validate()) { if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('emailTemplate', 'Add emailTemplate successfully.')); } else { Yii::app()->user->setFlash('error', Yii::t('emailTemplate', 'Add emailTemplate failed. Please try it later.')); } $this->redirect(array('/' . backend . '/emailTemplate/admin')); } } $this->render(strtolower($this->action->Id), array('model' => $model)); }
public function testGetData() { $moduleClassName = Contact::getModuleClassName(); $type = Report::TYPE_ROWS_AND_COLUMNS; $treeType = ComponentForReportForm::TYPE_FILTERS; $report = new Report(); $report->setModuleClassName($moduleClassName); $report->setType($type); $reportToTreeAdapter = new MergeTagsReportRelationsAndAttributesToTreeAdapter($report, $treeType, 'EmailTemplate'); $emailTemplate = new EmailTemplate(); $emailTemplate->type = EmailTemplate::TYPE_CONTACT; $emailTemplate->subject = 'Another Test subject'; $emailTemplate->name = 'Another Test Email Template'; $emailTemplate->textContent = 'Text Content '; $emailTemplate->htmlContent = 'Html Content '; $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML; $emailTemplate->modelClassName = 'Contact'; // By testing the getData method we're actually testing that all Merge Tags are valid // and that we can save the EmailTemplate with each Merge Tag without having the error 'Invalid Merge Tag'. $data = $reportToTreeAdapter->getData('source'); foreach ($data[1]['children'] as $child) { if (isset($child['dataValue']) && $child['dataValue']) { $emailTemplate->textContent .= ' ' . $child['dataValue']; $emailTemplate->htmlContent .= ' ' . $child['dataValue']; } } $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertEmpty($emailTemplate->getErrors()); $this->assertTrue($emailTemplate->save()); $data = $reportToTreeAdapter->getData('EmailTemplate_createdByUser'); $emailTemplate->textContent = ''; $emailTemplate->htmlContent = ''; foreach ($data as $child) { if (isset($child['dataValue']) && $child['dataValue']) { $emailTemplate->textContent .= ' ' . $child['dataValue']; $emailTemplate->htmlContent .= ' ' . $child['dataValue']; } } $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertEmpty($emailTemplate->getErrors()); $this->assertTrue($emailTemplate->save()); $data = $reportToTreeAdapter->getData('EmailTemplate_owner'); $emailTemplate->textContent = ''; $emailTemplate->htmlContent = ''; foreach ($data as $child) { if (isset($child['dataValue']) && $child['dataValue']) { $emailTemplate->textContent .= ' ' . $child['dataValue']; $emailTemplate->htmlContent .= ' ' . $child['dataValue']; } } $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertEmpty($emailTemplate->getErrors()); $this->assertTrue($emailTemplate->save()); $data = $reportToTreeAdapter->getData('EmailTemplate_owner___primaryEmail'); $emailTemplate->textContent = ''; $emailTemplate->htmlContent = ''; foreach ($data as $child) { if (isset($child['dataValue']) && $child['dataValue']) { $emailTemplate->textContent .= ' ' . $child['dataValue']; $emailTemplate->htmlContent .= ' ' . $child['dataValue']; } } $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertEmpty($emailTemplate->getErrors()); $this->assertTrue($emailTemplate->save()); $data = $reportToTreeAdapter->getData('EmailTemplate_primaryAddress'); $emailTemplate->textContent = ''; $emailTemplate->htmlContent = ''; foreach ($data as $child) { if (isset($child['dataValue']) && $child['dataValue']) { $emailTemplate->textContent .= ' ' . $child['dataValue']; $emailTemplate->htmlContent .= ' ' . $child['dataValue']; } } $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertEmpty($emailTemplate->getErrors()); $this->assertTrue($emailTemplate->save()); // Test against invalid Merge Tags $emailTemplate->textContent = 'Text Content [[TEXT__INVALID^MERGE^TAG]]'; $emailTemplate->htmlContent = 'Html Content [[HTMLINVALIDMERGETAG]]'; $validated = $emailTemplate->validate(null, false, true); $this->assertFalse($validated); $errorMessages = $emailTemplate->getErrors(); $this->assertEquals(2, count($errorMessages)); $this->assertTrue(array_key_exists('textContent', $errorMessages)); $this->assertTrue(array_key_exists('htmlContent', $errorMessages)); $this->assertEquals(1, count($errorMessages['textContent'])); $this->assertEquals(1, count($errorMessages['htmlContent'])); $this->assertContains('TEXT__INVALID^MERGE^TAG', $errorMessages['textContent'][0]); $this->assertContains('HTMLINVALIDMERGETAG', $errorMessages['htmlContent'][0]); }
/** * @depends testCreateAndGetEmailTemplateById */ public function testDummyHtmlContentThrowsValidationErrorWhenTextContentIsEmpty() { $emailTemplate = new EmailTemplate(); $emailTemplate->type = EmailTemplate::TYPE_CONTACT; $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML; $emailTemplate->subject = 'Another Test subject'; $emailTemplate->name = 'Another Test Email Template'; $emailTemplate->textContent = ''; $emailTemplate->htmlContent = "<html>\n<head>\n</head>\n<body>\n</body>\n</html>"; $emailTemplate->modelClassName = 'Contact'; $validated = $emailTemplate->validate(null, false, true); $this->assertFalse($validated); $errorMessages = $emailTemplate->getErrors(); $this->assertEquals(1, count($errorMessages)); $this->assertTrue(array_key_exists('textContent', $errorMessages)); $this->assertEquals(1, count($errorMessages['textContent'])); $this->assertEquals('Please provide at least one of the contents field.', $errorMessages['textContent'][0]); $emailTemplate->textContent = 'Text Content'; $validated = $emailTemplate->validate(null, false, true); $this->assertTrue($validated); $this->assertTrue($emailTemplate->save()); $this->assertEquals(6, EmailTemplate::getCount()); $id = $emailTemplate->id; unset($emailTemplate); $emailTemplate = EmailTemplate::getById($id); $this->assertEquals(EmailTemplate::TYPE_CONTACT, $emailTemplate->type); $this->assertEquals('Another Test subject', $emailTemplate->subject); $this->assertEquals('Another Test Email Template', $emailTemplate->name); $this->assertEquals(null, $emailTemplate->htmlContent); $this->assertEquals('Text Content', $emailTemplate->textContent); }