/** * @depends testCreateAndGetAutoresponderById */ public function testDeleteAutoresponder() { $autoresponders = Autoresponder::getAll(); $this->assertCount(7, $autoresponders); $autoresponderId = $autoresponders[0]->id; $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $contact = ContactTestHelper::createContactByNameForOwner('autoresponderContact', Yii::app()->user->userModel); $saved = AutoresponderItem::addNewItem(0, $processDateTime, $contact, $autoresponders[0]); $this->assertTrue($saved); $autoresponderItems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId); $this->assertNotEmpty($autoresponderItems); $this->assertCount(1, $autoresponderItems); $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf'); $files = array(); foreach ($fileNames as $index => $fileName) { $file = ZurmoTestHelper::createFileModel($fileName); $files[$index]['name'] = $fileName; $files[$index]['type'] = $file->type; $files[$index]['size'] = $file->size; $files[$index]['contents'] = $file->fileContent->content; $autoresponders[0]->files->add($file); } $this->assertTrue($autoresponders[0]->save()); $autoresponders = Autoresponder::getAll(); $this->assertNotEmpty($autoresponders[0]->files); $this->assertCount(count($files), $autoresponders[0]->files); $this->assertEquals(count($files), FileModel::getCount()); $autoresponders[0]->delete(); $autoresponders = Autoresponder::getAll(); $this->assertEquals(6, count($autoresponders)); $autoresponderitems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId); $this->assertEquals(0, count($autoresponderitems)); $this->assertEquals(0, FileModel::getCount()); }
/** * @depends testCreateAndGetMarketingListMemberById */ public function testBeforeSaveAutoresponderRegister() { $marketingList = MarketingListTestHelper::createMarketingListByName('test marketing List 06'); $this->assertNotNull($marketingList); $autoresponderSubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Subscribe', 'This is text content Subscribe', 'This is <b>html</b> content Subscribe', 10, Autoresponder::OPERATION_SUBSCRIBE, false, $marketingList); $this->assertNotNull($autoresponderSubscribe); $autoresponderUnsubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Unsubscribe', 'This is text content Unsubscribe', 'This is <b>html</b> content Unsubscribe', 20, Autoresponder::OPERATION_UNSUBSCRIBE, true, $marketingList); $this->assertNotNull($autoresponderUnsubscribe); $member = MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList); $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderSubscribe->id); $this->assertNotEmpty($autoresponderItemsSubscribe); $this->assertCount(1, $autoresponderItemsSubscribe); $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderUnsubscribe->id); $this->assertEmpty($autoresponderItemsUnsubscribe); $member->unsubscribed = 1; $saved = $member->unrestrictedSave(); $this->assertTrue($saved); $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderSubscribe->id); $this->assertNotEmpty($autoresponderItemsSubscribe); $this->assertCount(1, $autoresponderItemsSubscribe); $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderUnsubscribe->id); $this->assertNotEmpty($autoresponderItemsUnsubscribe); $this->assertCount(1, $autoresponderItemsUnsubscribe); }
/** * @depends testAddNewItem */ public function testRegisterAutoresponderItemsByAutoresponderOperation() { $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04'); $autoresponderSubscribe = AutoresponderTestHelper::createAutoresponder('autoresponder Subscribe', 'test autoresponder Subscribe', 'This is text content Subscribe', 'This is <b>html</b> content Subscribe', 10, Autoresponder::OPERATION_SUBSCRIBE, $marketingList); $this->assertNotNull($autoresponderSubscribe); $autoresponderUnsubscribe = AutoresponderTestHelper::createAutoresponder('autoresponder Unsubscribe', 'test autoresponder Unsubscribe', 'This is text content Unsubscribe', 'This is <b>html</b> content Unsubscribe', 20, Autoresponder::OPERATION_UNSUBSCRIBE, $marketingList); $this->assertNotNull($autoresponderUnsubscribe); $autoresponderRemove = AutoresponderTestHelper::createAutoresponder('autoresponder Remove', 'test autoresponder Remove', 'This is text content Remove', 'This is <b>html</b> content Remove', 10, Autoresponder::OPERATION_REMOVE, $marketingList); $this->assertNotNull($autoresponderRemove); $super = User::getByUsername('super'); $contact1 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 01', $super); $contact2 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 02', $super); $contact3 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 03', $super); $contact4 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 04', $super); $contact5 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 05', $super); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE, $marketingList->id, $contact1); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE, $marketingList->id, $contact2); $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(AutoresponderItem::NOT_PROCESSED, $autoresponderSubscribe->id); $this->assertNotEmpty($autoresponderItemsSubscribe); $this->assertCount(2, $autoresponderItemsSubscribe); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE, $marketingList->id, $contact3); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE, $marketingList->id, $contact4); $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(AutoresponderItem::NOT_PROCESSED, $autoresponderUnsubscribe->id); $this->assertNotEmpty($autoresponderItemsUnsubscribe); $this->assertCount(2, $autoresponderItemsUnsubscribe); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_REMOVE, $marketingList->id, $contact5); $autoresponderItemsRemove = AutoresponderItem::getByProcessedAndAutoresponderId(AutoresponderItem::NOT_PROCESSED, $autoresponderRemove->id); $this->assertNotEmpty($autoresponderItemsRemove); $this->assertCount(1, $autoresponderItemsRemove); }
/** * @depends testRunWithCustomBatchSize */ public function testRunWithContactContainingPrimaryEmailOptedOut() { $unprocessedItems = AutoresponderItem::getByProcessed(0); $this->assertEmpty($unprocessedItems); $job = new AutoresponderQueueMessagesInOutboxJob(); $email = new Email(); $email->emailAddress = '*****@*****.**'; $email->optOut = true; $contact = ContactTestHelper::createContactByNameForOwner('contact 07', $this->user); $contact->primaryEmail = $email; $this->assertTrue($contact->save()); $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 08', 'description goes here', 'fromName', '*****@*****.**'); MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact); $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 08', '[[FIRST^NAME]]', '[[LAST^NAME]]', 1, Autoresponder::OPERATION_SUBSCRIBE, true, $marketingList); $processed = 0; $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - rand(10, 500)); $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact); $unprocessedItems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponder->id); $this->assertCount(1, $unprocessedItems); $this->assertTrue($job->run()); $unprocessedItems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponder->id); $this->assertCount(0, $unprocessedItems); $personId = $contact->getClassId('Person'); $activities = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(AutoresponderItemActivity::TYPE_SKIP, $autoresponderItem->id, $personId); $this->assertNotEmpty($activities); $this->assertCount(1, $activities); }
/** * @depends testCreateAndGetAutoresponderById */ public function testDeleteAutoresponder() { $autoresponders = Autoresponder::getAll(); $this->assertCount(7, $autoresponders); $autoresponderId = $autoresponders[0]->id; $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $contact = ContactTestHelper::createContactByNameForOwner('autoresponderContact', Yii::app()->user->userModel); $saved = AutoresponderItem::addNewItem(0, $processDateTime, $contact, $autoresponders[0]); $this->assertTrue($saved); $autoresponderItems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId); //print_r($autoresponderItems[0]->id); $this->assertNotEmpty($autoresponderItems); $this->assertCount(1, $autoresponderItems); $autoresponderItemActivity = new AutoresponderItemActivity(); $autoresponderItemActivity->type = AutoresponderItemActivity::TYPE_OPEN; $autoresponderItemActivity->quantity = 10; $autoresponderItemActivity->latestSourceIP = '10.11.12.13'; $autoresponderItemActivity->autoresponderItem = $autoresponderItems[0]; $this->assertTrue($autoresponderItemActivity->save()); //print_r($autoresponderItemActivity->id); $autoresponderItemActivities = AutoresponderItemActivity::getAll(); $this->assertCount(1, $autoresponderItemActivities); $autoresponders[0]->delete(); $autoresponders = Autoresponder::getAll(); $this->assertEquals(6, count($autoresponders)); $autoresponderitems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderId); $this->assertEquals(0, count($autoresponderitems)); $autoresponderItemActivities = AutoresponderItemActivity::getAll(); $this->assertCount(0, $autoresponderItemActivities); }
/** * @depends testAddNewItem */ public function testRegisterAutoresponderItemsByAutoresponderOperation() { $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 04'); $autoresponderSubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Subscribe', 'This is text content Subscribe', 'This is <b>html</b> content Subscribe', 10, Autoresponder::OPERATION_SUBSCRIBE, true, $marketingList); $this->assertNotNull($autoresponderSubscribe); $autoresponderUnsubscribe = AutoresponderTestHelper::createAutoresponder('test autoresponder Unsubscribe', 'This is text content Unsubscribe', 'This is <b>html</b> content Unsubscribe', 20, Autoresponder::OPERATION_UNSUBSCRIBE, true, $marketingList); $this->assertNotNull($autoresponderUnsubscribe); $contact1 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 01', Yii::app()->user->userModel); $contact2 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 02', Yii::app()->user->userModel); $contact3 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 03', Yii::app()->user->userModel); $contact4 = ContactTestHelper::createContactByNameForOwner('autoresponderContact 04', Yii::app()->user->userModel); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE, $marketingList->id, $contact1); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_SUBSCRIBE, $marketingList->id, $contact2); $autoresponderItemsSubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderSubscribe->id); $this->assertNotEmpty($autoresponderItemsSubscribe); $this->assertCount(2, $autoresponderItemsSubscribe); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE, $marketingList->id, $contact3); AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation(Autoresponder::OPERATION_UNSUBSCRIBE, $marketingList->id, $contact4); $autoresponderItemsUnsubscribe = AutoresponderItem::getByProcessedAndAutoresponderId(0, $autoresponderUnsubscribe->id); $this->assertNotEmpty($autoresponderItemsUnsubscribe); $this->assertCount(2, $autoresponderItemsUnsubscribe); }
/** * @depends testRunWithInvalidMergeTags */ public function testRunWithValidMergeTags() { $job = new AutoresponderMessageInQueueJob(); $email = new Email(); $email->emailAddress = '*****@*****.**'; $contact = ContactTestHelper::createContactByNameForOwner('contact 05', $this->user); $contact->primaryEmail = $email; $this->assertTrue($contact->save()); $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06', 'description goes here', 'fromName', '*****@*****.**'); $autoresponder = AutoresponderTestHelper::createAutoresponder('autoresponder 06', 'subject 06', '[[FIRST^NAME]]', '[[LAST^NAME]]', 1, Autoresponder::OPERATION_SUBSCRIBE, $marketingList); $processed = AutoresponderItem::NOT_PROCESSED; $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10); AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact); $this->assertTrue($job->run()); $autoresponderItems = AutoresponderItem::getAll(); $this->assertCount(4, $autoresponderItems); $autoresponderItemsProcessed = AutoresponderItem::getByProcessedAndAutoresponderId(AutoresponderItem::PROCESSED, $autoresponder->id); $this->assertCount(1, $autoresponderItemsProcessed); }
protected function afterDelete() { parent::afterDelete(); $autoresponderitems = AutoresponderItem::getByProcessedAndAutoresponderId(0, $this->id); foreach ($autoresponderitems as $autoresponderitem) { ZurmoRedBean::exec("DELETE FROM autoresponderitemactivity WHERE autoresponderitem_id = " . $autoresponderitem->id); } ZurmoRedBean::exec("DELETE FROM autoresponderitem WHERE processed = 0 and autoresponder_id = " . $this->id); }