public function testSpooledMailing() { $this->webtestLogin(); // Start spooling mail $mut = new CiviMailUtils($this, TRUE); // Add a contact $fname = substr(sha1(rand()), 0, 6); $lname = substr(sha1(rand()), 0, 6); $email = $this->webtestAddContact($fname, $lname, TRUE); // Get the contact id of the newly added contact $cid = $this->urlArg('cid'); // Send an email to the added contact $this->openCiviPage("activity/email/add", "action=add&reset=1&cid={$cid}&selectedChild=activity&atype=3"); $this->type('subject', 'test spool'); $this->fillRichTextField('html_message', 'Unit tests keep children safe.'); $this->click("_qf_Email_upload"); // Retrieve an ezc mail object version of the email $msg = $mut->getMostRecentEmail('ezc'); $this->assertNotEmpty($msg, 'Mail message empty or not found.'); $this->assertEquals($msg->subject, 'test spool'); // should really walk through the 'to' array, but this is legal according to the docs $this->assertContains($email, implode(';', $msg->to), 'Recipient incorrect.'); $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback')); $msg->walkParts($context, $msg); /* * Now try a regular activity with cc to assignee */ $this->WebtestAddActivity(); $msg = $mut->getMostRecentEmail('raw'); $this->assertNotEmpty($msg, 'Mail message empty or not found.'); $this->assertContains('Subject: This is subject of test activity', $msg, 'Subject of email is wrong.'); $mut->stop(); }
/** * Check mailing is sent */ function testProcessMailing() { $this->createContactsInGroup(10, $this->_groupID); CRM_Core_Config::singleton()->mailerBatchLimit = 2; $this->callAPISuccess('mailing', 'create', $this->_params); $this->callAPISuccess('job', 'process_mailing', array()); $this->_mut->assertRecipients($this->getRecipients(1, 2)); }
/** * Execute the default schedule, without any special recipient selections. * * @dataProvider createTestCases * * @param string $targetDate * @param string $setupFuncs * @param array $expectMessages * * @throws \Exception */ public function testDefault($targetDate, $setupFuncs, $expectMessages) { $this->targetDate = $targetDate; foreach (explode(' ', $setupFuncs) as $setupFunc) { $this->{$setupFunc}(); } $this->schedule->save(); $actualMessages = array(); foreach ($this->cronTimes() as $time) { \CRM_Utils_Time::setTime($time); $this->callAPISuccess('job', 'send_reminder', array()); foreach ($this->mut->getAllMessages('ezc') as $message) { /** @var \ezcMail $message */ $simpleMessage = array('time' => $time, 'to' => \CRM_Utils_Array::collect('email', $message->to), 'subject' => $message->subject); sort($simpleMessage['to']); $actualMessages[] = $simpleMessage; $this->mut->clearMessages(); } } $errorText = "Incorrect messages: " . print_r(array('actualMessages' => $actualMessages, 'expectMessages' => $expectMessages), 1); $this->assertEquals(count($expectMessages), count($actualMessages), $errorText); usort($expectMessages, array(__CLASS__, 'compareSimpleMsgs')); usort($actualMessages, array(__CLASS__, 'compareSimpleMsgs')); foreach ($expectMessages as $offset => $expectMessage) { $actualMessage = $actualMessages[$offset]; $this->assertApproxEquals(strtotime($expectMessage['time']), strtotime($actualMessage['time']), $this->dateTolerance, $errorText); if (isset($expectMessage['to'])) { sort($expectMessage['to']); $this->assertEquals($expectMessage['to'], $actualMessage['to'], $errorText); } if (isset($expectMessage['subject'])) { $this->assertRegExp($expectMessage['subject'], $actualMessage['subject'], $errorText); } } }
/** * Setup various mail configuration options (eg $mailerBatchLimit, * $mailerJobMax) and spawn multiple worker threads ($workers). * Allow the threads to complete. (Optionally, repeat the above * process.) Finally, check to see if the right number of * jobs delivered the right number of messages. * * @param array $settings * An array of settings (eg mailerBatchLimit, workers). See comments * for $this->defaultSettings. * @param array $expectedTallies * A listing of the number cron-runs keyed by their size. * For example, array(10=>2) means that there 2 cron-runs * which delivered 10 messages each. * @param int $expectedTotal * The total number of contacts for whom messages should have * been sent. * @dataProvider concurrencyExamples */ public function testConcurrency($settings, $expectedTallies, $expectedTotal) { $settings = array_merge($this->defaultSettings, $settings); $this->createContactsInGroup($settings['recipients'], $this->_groupID); Civi::settings()->add(CRM_Utils_Array::subset($settings, array('mailerBatchLimit', 'mailerJobsMax', 'mailThrottleTime'))); for ($i = 0; $i < $settings['mailings']; $i++) { $this->callAPISuccess('mailing', 'create', $this->_params); } $this->_mut->assertRecipients(array()); $allApiResults = array(); for ($iterationId = 0; $iterationId < $settings['iterations']; $iterationId++) { $apiCalls = $this->createExternalAPI(); $apiCalls->addEnv(array('CIVICRM_CRON_HOLD' => $settings['lockHold'])); for ($workerId = 0; $workerId < $settings['workers']; $workerId++) { $apiCalls->addCall('job', 'process_mailing', array()); } $apiCalls->start(); $this->assertEquals($settings['workers'], $apiCalls->getRunningCount()); $apiCalls->wait(); $allApiResults = array_merge($allApiResults, $apiCalls->getResults()); } $actualTallies = $this->tallyApiResults($allApiResults); $this->assertEquals($expectedTallies, $actualTallies, 'API tallies should match.' . print_r(array('expectedTallies' => $expectedTallies, 'actualTallies' => $actualTallies, 'apiResults' => $allApiResults), TRUE)); $this->_mut->assertRecipients($this->getRecipients(1, $expectedTotal / $settings['mailings'], 'nul.example.com', $settings['mailings'])); $this->assertEquals(0, $apiCalls->getRunningCount()); }
public function testStandaloneActivityAdd() { $this->webtestLogin(); $this->openCiviPage("admin/setting/preferences/display", "reset=1", "name=activity_assignee_notification_ics"); // Notify assignees should be checked by default, so we just need to click the ical setting which is off by default. $this->check("name=activity_assignee_notification_ics"); $this->click("_qf_Display_next"); $this->waitForPageToLoad($this->getTimeoutMsec()); // Start spooling emails $mailer = new CiviMailUtils($this, TRUE); self::$foundIt = FALSE; $firstName1 = substr(sha1(rand()), 0, 7); $this->webtestAddContact("{$firstName1}", "Anderson", $firstName1 . "@anderson.com"); $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload"); $this->select("activity_type_id", "value=1"); $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input"); // Because it tends to cause problems, all uses of sleep() must be justified in comments // Sleep should never be used for wait for anything to load from the server // Justification for this instance: tokeninput has a slight delay sleep(1); $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " "); $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1); $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1); $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); $this->clickAt("xpath=//div[@class='select2-result-label']"); $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "{$firstName1}"); $subject = "Testing Ical attachment for activity assignee"; $this->type("subject", $subject); $location = 'Some location needs to be put in this field.'; $this->type("location", $location); $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); $this->select("status_id", "value=1"); $this->click("_qf_Activity_upload"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->waitForText('crm-notification-container', $subject); // check the resulting email $mail = $mailer->getMostRecentEmail('ezc'); $this->assertNotNull($mail, ts('Assignee email not generated or problem locating it.')); $this->assertEquals($mail->subject, "{$subject}"); $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback')); $mail->walkParts($context, $mail); $mailer->stop(); $this->assertTrue(self::$foundIt, ts('Generated email does not contain an ical attachment.')); }
/** * Run a series of cron jobs and make an assertion about email deliveries. * * @param array $cronRuns * array specifying when to run cron and what messages to expect; each item is an array with keys: * - time: string, e.g. '2012-06-15 21:00:01' * - recipients: array(array(string)), list of email addresses which should receive messages */ public function assertCronRuns($cronRuns) { foreach ($cronRuns as $cronRun) { CRM_Utils_Time::setTime($cronRun['time']); $this->callAPISuccess('job', 'send_reminder', array()); $this->mut->assertRecipients($cronRun['recipients']); if (array_key_exists('subjects', $cronRun)) { $this->mut->assertSubjects($cronRun['subjects']); } $this->mut->clearMessages(); } }
/** * Test the submit function of the membership form. */ public function testSubmitRecurCompleteInstant() { $form = $this->getForm(); $mut = new CiviMailUtils($this, TRUE); $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); $processor->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'kettles boil water', 'fee_amount' => 0.14)); $this->callAPISuccess('MembershipType', 'create', array('id' => $this->membershipTypeAnnualFixedID, 'duration_unit' => 'month', 'duration_interval' => 1, 'auto_renew' => TRUE)); $form->preProcess(); $this->createLoggedInUser(); $params = $this->getBaseSubmitParams(); $form->_mode = 'test'; $form->_contactID = $this->_individualId; $form->testSubmit($params); $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); $contribution = $this->callAPISuccess('Contribution', 'getsingle', array('contact_id' => $this->_individualId, 'is_test' => TRUE)); $this->assertEquals(0.14, $contribution['fee_amount']); $this->assertEquals('kettles boil water', $contribution['trxn_id']); $this->callAPISuccessGetCount('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id']), 1); $mut->checkMailLog(array('=========================================================== Billing Name and Address =========================================================== Test 10 Test St Test, AR 90210 US', '=========================================================== Membership Information =========================================================== Membership Type: AnnualFixed Membership Start Date: ', '=========================================================== Credit Card Information =========================================================== Visa ************1111 Expires: ')); $mut->stop(); }
/** * Test sending a mail via the API. */ public function testSendMailEvent() { $mut = new CiviMailUtils($this, TRUE); $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => '*****@*****.**')); $this->_eventID = $event['id']; $participantParams = array('contact_id' => $this->_individualId, 'event_id' => $this->_eventID, 'status_id' => 1, 'role_id' => 1, 'register_date' => '2007-07-21 00:00:00', 'source' => 'Online Event Registration: API Testing'); $participant = $this->callAPISuccess('participant', 'create', $participantParams); $this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contribution['id'])); $this->callAPISuccess('contribution', 'sendconfirmation', array('id' => $contribution['id'], 'receipt_from_email' => '*****@*****.**')); $mut->checkMailLog(array('Annual CiviCRM meet', 'Event', 'To: "Mr. Anthony Anderson II" <*****@*****.**>'), array()); $mut->stop(); }
/** * Test functions involving premiums. */ public function testPremiumUpdateCreditCard() { $form = new CRM_Contribute_Form_Contribution(); $mut = new CiviMailUtils($this, TRUE); $form->testSubmit(array('total_amount' => 50, 'financial_type_id' => 1, 'receive_date' => '04/21/2015', 'receive_date_time' => '11:27PM', 'contact_id' => $this->_individualId, 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), 'contribution_status_id' => 1, 'product_name' => array($this->products[0]['id'], 1), 'fulfilled_date' => '', 'is_email_receipt' => TRUE, 'from_email_address' => '*****@*****.**', 'payment_processor_id' => $this->paymentProcessor->id, 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026), 'credit_card_number' => '411111111111111'), CRM_Core_Action::ADD, 'live'); $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array()); $this->assertEquals('clumsy smurf', $contributionProduct['product_option']); $mut->checkMailLog(array('Premium Information', 'Smurf', 'clumsy smurf')); $mut->stop(); }
/** * Test IPN response mails don't leak. */ public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline() { $mut = new CiviMailUtils($this, TRUE); $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); $this->addProfile('supporter_profile', $this->_contributionPageID); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); $IPN->main(); $mut->checkAllMailLog(array('Membership Type: General', 'Mr. Anthony Anderson II" <*****@*****.**>', 'Amount: $ 200.00', 'Membership Start Date:', 'Supporter Profile', 'First Name: Anthony', 'Last Name: Anderson', 'Email Address: anthony_anderson@civicrm.org', 'This membership will be automatically renewed every', 'Dear Mr. Anthony Anderson II', 'Thanks for your auto renew membership sign-up')); $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => '*****@*****.**')); $this->_invoiceID = uniqid(); $this->_contributionPageID = NULL; $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); $mut->clearMessages(99999); $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers'))); $IPN->main(); $mut->checkAllMailLog(array('Membership Type: General', 'Mrs. Antonia Anderson II', '*****@*****.**', 'Amount: $ 200.00', 'Membership Start Date:', 'Transaction #: hers', 'This membership will be automatically renewed every', 'Dear Mrs. Antonia Anderson II', 'Thanks for your auto renew membership sign-up'), array('First Name: Anthony', 'First Name: Antonia', 'Last Name: Anderson', 'Supporter Profile', 'Email Address: antonia_anderson@civicrm.org')); $mut->stop(); $mut->clearMessages(); }
/** * Test the LoadObjects function with recurring membership data. */ public function testsendMailParticipantObjectsNoMail() { $this->_setUpParticipantObjects(); $event = new CRM_Event_BAO_Event(); $event->id = $this->_eventId; $event->is_email_confirm = FALSE; $event->save(); $values = array(); $tablesToTruncate = array('civicrm_mailing_spool'); $this->quickCleanup($tablesToTruncate, FALSE); require_once 'CiviTest/CiviMailUtils.php'; $mut = new CiviMailUtils($this, TRUE); $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId); $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE); $mut->assertMailLogEmpty('no mail should have been send as event set to no confirm'); $mut->stop(); }
/** * Test submit with a membership block in place. */ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() { $mut = new CiviMailUtils($this, TRUE); $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0))); $this->setUpMembershipContributionPage(TRUE); $this->addProfile('supporter_profile', $this->_ids['contribution_page']); $submitParams = array('price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']), 'id' => (int) $this->_ids['contribution_page'], 'amount' => 0, 'billing_first_name' => 'Billy', 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruffalo', 'selectMembership' => $this->_ids['membership_type'], 'payment_processor_id' => 0, 'email-Primary' => '*****@*****.**'); $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page'])); $this->assertCount(2, $contributions['values']); $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array()); $this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values']))); $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id'])); $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']); $mut->checkMailLog(array('Gruffalo', 'General Membership: $ 0.00', 'Membership Fee')); $mut->stop(); $mut->clearMessages(); }