CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Regression testing of email send
Pages: [1]

Author Topic: Regression testing of email send  (Read 4209 times)

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Regression testing of email send
January 09, 2009, 07:39:21 pm
Gurus,

I am hoping for some guidance.  I would like to write a unit test of mail sending functions.  However, I do not want to actually send a large number of emails or, worse yet, go through them by hand looking for incorrect processing.  Therefore emails generated by the test must be grabbed and parsed by the test harness.

I looked through the existing test suite and did not find much that was helpful.

There is a Drupal module reroute_email which grabs outgoing mail with Drupal hook_mail_alter and changes the destination address to something of the tester's choosing.  But CiviCRM does not call the Drupal hook.

One approach that strikes me as feasible is to direct mail to the spool, then have the test inspect what appears in the spool.  This seems to offer the best hope for test automation.  Unfortunately CRM_Mailing_BAO_Spool::send() requires one more argument than the SMTP and sendmail send methods generated by Mail::factory(), therefore using this method causes a fatal PHP error.  This could be hacked to make the fourth argument optional, defaulting to null, and allow civicrm_mailing_spool.job_id to be null.

Other feasible approaches might be to have the test harness grab the test mail with a mock /usr/sbin/sendmail program, or somehow return a suitable mock object from Mail::factory().

What does the group suggest?

Thanks in advance  -- Walt

http://dharmatech.org
oss@dharmatech.org
801.541.8671

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Regression testing of email send
January 09, 2009, 08:30:52 pm

There is another option (undocumented) which logs all mail to a directory (or optionally to a file)

if u define:

define( 'CIVICRM_MAIL_LOG' , 1 );

in your settings files, all mail gets logged to: files/civicrm/upload/mail/*

if you give it a filename instead, it overwrites that file with the last mail (we typically would use /dev/null in this case)

i suspect the above would help and simplify testing?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: Regression testing of email send
January 10, 2009, 07:00:25 am
Thanks Lobo, I'll try that

-- Walt
http://dharmatech.org
oss@dharmatech.org
801.541.8671

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Regression testing of email send
July 20, 2009, 09:15:44 am
I'm also trying to test a mailing (reminder notices from UpdateMembershipRecord.php) but don't want actual mails to go out.

If one adds "define( 'CIVICRM_MAILER_SPOOL' , 1 );" to the settings file will it redirect all outgoing mail to the civicrm_mailing_spool table, effectively preventing mails from going out?

Setting CIVICRM_MAIL_LOG as suggested by Lobo looks like it additionally logs mail to a file, but by itself wouldn't prevent mails from going out.

Is this correct?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Regression testing of email send
July 20, 2009, 11:21:20 am
Using the "mail log" setting (below) causes all outbound mail to be written to an MD5 named file in $yourUploadDir/mail directory:

Code: [Select]
define( 'CIVICRM_MAIL_LOG' , 1 );
Protect your investment in CiviCRM by  becoming a Member!

alphageekboy

  • I’m new here
  • *
  • Posts: 11
  • Karma: 1
  • Web Developer
    • Alpha Geek Tech, LLC
Re: Regression testing of email send
June 24, 2010, 06:47:00 pm
Is this still a valid option? I put the setting in the civicrm.settings.php file and it appears to not be sending mail, but I don't see it going into my civicrm upload directory.
Tracy C. Smith
Chief Technologist & Founder

Alpha Geek  Tech, LLC
p: 831.706.2187
http://alphageektech.net
skype/aol: tracycsmith
t: alphageektech

alphageekboy

  • I’m new here
  • *
  • Posts: 11
  • Karma: 1
  • Web Developer
    • Alpha Geek Tech, LLC
Re: Regression testing of email send
June 24, 2010, 07:53:44 pm
Ah, found the answer here: http://forum.civicrm.org/index.php?topic=10104.0

This is the directory where mail goes. 

 files/civicrm/templates_c/en_US/ConfigAndLog/mail

I created a SymLink to this directory so may users can test by going to http:///www.example.com/mail and added .htaccess file to allow indexes.  Now they can navigate to this directory and click refresh to view emails that are logged.

Tracy C. Smith
Chief Technologist & Founder

Alpha Geek  Tech, LLC
p: 831.706.2187
http://alphageektech.net
skype/aol: tracycsmith
t: alphageektech

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Regression testing of email send

This forum was archived on 2017-11-26.