There seem to be two issues:
-- Setting smtp_library to simpletest.test causes the following error. Moving the drupal_mail_wrapper() function to it's own file seems to resolve this problem.
Class 'DrupalWebTestCase' not found
PHP Stack trace: Fatal error
PHP 1. {main}() /drupal/cron.php:0 Fatal error
PHP 2. drupal_cron_run() /drupal/cron.php:11 Fatal error
PHP 3. module_invoke_all(*uninitialized*) /drupal/includes/common.inc:2702 Fatal error
PHP 4. call_user_func_array(*uninitialized*, *uninitialized*) /drupal/includes/module.inc:471 Fatal error
PHP 5. mymodule_cron() /drupal/includes/module.inc:0 Fatal error
PHP 6. _mymodule_transcode_videos() /drupal/sites/all/modules/custom/mymodule/mymodule.module:316 Fatal error
PHP 7. drupal_mail($module = *uninitialized*, $key = *uninitialized*, $to = *uninitialized*, $language = *uninitialized*, $params = *uninitialized*, $from = *uninitialized*, $send = *uninitialized*) /drupal/sites/all/modules/custom/mymodule/includes/transcoder.inc:30 Fatal error
PHP 8. drupal_mail_send($message = *uninitialized*) /drupal/includes/mail.inc:130 Fatal error
PHP 9. include_once() /drupal/includes/mail.inc:176 Fatal error
-- The second issue I don't completely understand – in assertMail, the keys for $email seem to be different when testing a real module, vs the mail in simpletest.test. I sort of punted on this by making the logic check for both $email['params']['$name'] and $email['$name']. But perhaps that part need more study.
Comments
Comment #1
grendzy commentedhmmm, marking as critical because "Class 'DrupalWebTestCase' not found" pops up if any code under test calls drupal_mail, whether or not you ever use assertMail.
Comment #2
smk-ka commentedI can't reproduce this issue with SimpleTest 2.9:
14 passes, 0 fails, and 0 exceptionsEDIT: the second issue might still be valid, since I didn't run a 'real' test.
Comment #3
grendzy commentedThe think the SimpleTestMailCaptureTestCase isn't valid, because it's calling drupal_mail from the "wrong side" of the simpletest browser. What's really needed is a mock module, or a test that targets a core use of drupal_mail.
I've attached a test for core user.module that demonstrates the problem.
Basically, when drupal_mail tries to load simpletest.test as the smtp_library, it fails because DrupalWebTestCase isn't loaded (nor should it be).
Comment #4
dave reidEasy solution is to either put the function in simpletest.module or create a new file just for the mail function. Ran into this while debugging Mollom tests.
Comment #5
grendzy commentedYeah, that's what the patch in #0 implements (moving the function to simpletest.mail.inc).
Comment #6
boombatower commentedCommitted first patch.
Thanks.