/** * 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); } } }
/** * 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 completing a transaction with an event via the API. * * Note that we are creating a logged in user because email goes out from * that person */ public function testCompleteTransactionWithParticipantRecord() { $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $this->createLoggedInUser(); $contributionID = $this->createPendingParticipantContribution(); $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contributionID)); $participantStatus = $this->callAPISuccessGetValue('participant', array('id' => $this->_ids['participant'], 'return' => 'participant_status_id')); $this->assertEquals(1, $participantStatus); $mut->checkMailLog(array('Annual CiviCRM meet', 'Event', 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.')); $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 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(); }