public function beforeSave() { if (!parent::beforeSave()) { return false; } if ($this->id < 0 || isset($this->originalAttributeValues['unsubscribed']) && $this->originalAttributeValues['unsubscribed'] != $this->unsubscribed) { $operation = Autoresponder::OPERATION_SUBSCRIBE; if ($this->unsubscribed) { $operation = Autoresponder::OPERATION_UNSUBSCRIBE; } AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation($operation, $this->marketingList->id, $this->contact); } $this->modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); return true; }
/** * @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 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); }