/** * @depends testCreateAndGetAutoresponderById */ public function testRequiredAttributes() { $intervalArray = array_flip(Autoresponder::getIntervalDropDownArray()); $autoresponder = new Autoresponder(); $this->assertFalse($autoresponder->save()); $errors = $autoresponder->getErrors(); $this->assertNotEmpty($errors); $this->assertCount(4, $errors); $this->assertArrayHasKey('subject', $errors); $this->assertEquals('Subject cannot be blank.', $errors['subject'][0]); $this->assertArrayHasKey('textContent', $errors); $this->assertEquals('Please provide at least one of the contents field.', $errors['textContent'][0]); $this->assertArrayHasKey('secondsFromOperation', $errors); $this->assertEquals('Send After cannot be blank.', $errors['secondsFromOperation'][0]); $this->assertArrayHasKey('operationType', $errors); $this->assertEquals('Triggered By cannot be blank.', $errors['operationType'][0]); $autoresponder->subject = 'Test Autoresponder subject 02'; $autoresponder->htmlContent = 'Test HtmlContent 02'; $autoresponder->textContent = 'Test TextContent 02'; $autoresponder->secondsFromOperation = $intervalArray['1 month']; $autoresponder->operationType = Autoresponder::OPERATION_UNSUBSCRIBE; $autoresponder->enableTracking = 1; $this->assertTrue($autoresponder->save()); $id = $autoresponder->id; unset($autoresponder); $autoresponder = Autoresponder::getById($id); $this->assertEquals('Test Autoresponder subject 02', $autoresponder->subject); $this->assertEquals('Test HtmlContent 02', $autoresponder->htmlContent); $this->assertEquals('Test TextContent 02', $autoresponder->textContent); $this->assertEquals($intervalArray['1 month'], $autoresponder->secondsFromOperation); $this->assertEquals(Autoresponder::OPERATION_UNSUBSCRIBE, $autoresponder->operationType); $this->assertEquals(1, $autoresponder->enableTracking); }
/** * @depends testCreateAndGetAutoresponderById */ public function testRequiredAttributes() { $autoresponder = new Autoresponder(); $this->assertFalse($autoresponder->save()); $errors = $autoresponder->getErrors(); $this->assertNotEmpty($errors); $this->assertCount(5, $errors); $this->assertArrayHasKey('subject', $errors); $this->assertEquals('Subject cannot be blank.', $errors['subject'][0]); $this->assertArrayHasKey('textContent', $errors); $this->assertEquals('Please provide at least one of the contents field.', $errors['textContent'][0]); $this->assertArrayHasKey('fromOperationDurationInterval', $errors); $this->assertEquals('Send After cannot be blank.', $errors['fromOperationDurationInterval'][0]); $this->assertArrayHasKey('fromOperationDurationType', $errors); $this->assertEquals('From Operation Duration Type cannot be blank.', $errors['fromOperationDurationType'][0]); $this->assertArrayHasKey('operationType', $errors); $this->assertEquals('Triggered By cannot be blank.', $errors['operationType'][0]); $autoresponder->subject = 'Test Autoresponder subject 02'; $autoresponder->htmlContent = 'Test HtmlContent 02'; $autoresponder->textContent = 'Test TextContent 02'; $autoresponder->fromOperationDurationInterval = '1'; $autoresponder->fromOperationDurationType = TimeDurationUtil::DURATION_TYPE_MONTH; $autoresponder->operationType = Autoresponder::OPERATION_UNSUBSCRIBE; $autoresponder->enableTracking = 1; $this->assertTrue($autoresponder->save()); $id = $autoresponder->id; unset($autoresponder); $autoresponder = Autoresponder::getById($id); $this->assertEquals('Test Autoresponder subject 02', $autoresponder->subject); $this->assertEquals('Test HtmlContent 02', $autoresponder->htmlContent); $this->assertEquals('Test TextContent 02', $autoresponder->textContent); $this->assertEquals('1', $autoresponder->fromOperationDurationInterval); $this->assertEquals(TimeDurationUtil::DURATION_TYPE_MONTH, $autoresponder->fromOperationDurationType); $this->assertEquals(Autoresponder::OPERATION_UNSUBSCRIBE, $autoresponder->operationType); $this->assertEquals(1, $autoresponder->enableTracking); }
/** * @depends testCreateAndGetAutoresponderById */ public function testHtmlContentGetsSavedCorrectly() { $randomData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('EmailTemplatesModule', 'EmailTemplate'); $htmlContent = $randomData['htmlContent'][count($randomData['htmlContent']) - 1]; $autoresponder = new Autoresponder(); $autoresponder->subject = 'Another Test subject'; $autoresponder->textContent = 'Text Content'; $autoresponder->htmlContent = $htmlContent; $autoresponder->fromOperationDurationInterval = '1'; $autoresponder->fromOperationDurationType = TimeDurationUtil::DURATION_TYPE_MONTH; $autoresponder->operationType = Autoresponder::OPERATION_UNSUBSCRIBE; $autoresponder->enableTracking = 1; $this->assertTrue($autoresponder->save()); $autoresponderId = $autoresponder->id; $autoresponder->forgetAll(); $autoresponder = Autoresponder::getById($autoresponderId); $this->assertEquals($htmlContent, $autoresponder->htmlContent); $this->assertEquals(4, Autoresponder::getCount()); }
function afterSave() { if ($this->isNewRecord) { // insert 3 autoresponder records for ($i = 1; $i <= 3; $i++) { $ar = new Autoresponder(); $ar->wlabel_id = $this->wlabel_id; $ar->type = $i; $ar->subject = ' '; $ar->message = ' '; $ar->save(); } } Yii::app()->cache->flush(); return parent::afterSave(); }