assertMail doesn't work on real modules - Class 'DrupalWebTestCase' not found

grendzy - October 5, 2009 - 17:14
Project:SimpleTest
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

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.

AttachmentSize
simpletest_assertMail.patch3.51 KB

#1

grendzy - October 5, 2009 - 17:17
Priority:normal» critical

hmmm, 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.

#2

smk-ka - October 6, 2009 - 10:27

I can't reproduce this issue with SimpleTest 2.9:
14 passes, 0 fails, and 0 exceptions

EDIT: the second issue might still be valid, since I didn't run a 'real' test.

#3

grendzy - October 6, 2009 - 16:10

The 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).

AttachmentSize
596440_demo.patch 923 bytes

#4

Dave Reid - October 13, 2009 - 16:10

Easy 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.

#5

grendzy - October 21, 2009 - 15:49

Yeah, that's what the patch in #0 implements (moving the function to simpletest.mail.inc).

#6

boombatower - November 6, 2009 - 21:23
Status:needs review» fixed

Committed first patch.

Thanks.

#7

System Message - November 20, 2009 - 21:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.