In DrupalTestCase::assert, a db_insert() is done without special try/catch handler, even though the $db_prefix is temporarily set to the non-testing database. If an exception is thrown by db_insert(), the exception-handling mechanism proceeds without the $db_prefix set correctly, resulting an a final, incomprehensible result, because the exception handler triggers on $db_prefix.

What I did: Made a stupid error in a test (left out the t())

    $this->assertText('Saved @name configuration.', array('@name' => $content_type_friendly));

What happened: I got a fatal out of the simpletest batch with

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /batch?id=21&op=do StatusText: OK ResponseText: {"status":true,"percentage":"100","message":"Processed test 1 of 1 - \u003cem class=\"placeholder\"\u003eField Example Tests\u003c\/em\u003e.\u003cdiv class=\"simpletest-fail\"\u003eOverall results: 20 passes, 8 fails, 1 exception, and 7 debug messages\u003c\/div\u003e\u003cdiv class=\"item-list\"\u003e\u003cul\u003e\u003cli class=\"first last\"\u003e\u003cdiv class=\"simpletest-fail\"\u003eField Example Tests: 20 passes, 8 fails, 1 exception, and 7 debug messages\u003c\/div\u003e\u003c\/li\u003e\n\u003c\/ul\u003e\u003c\/div\u003e"}Uncaught exception thrown in shutdown function.PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd7git.search_total' doesn't exist: SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL; Array ( ) in search_update_totals() (line 411 of /home/rfay/workspace/d7git/modules/search/search.module).

because the non-testing (host) system doesn't even have search module enabled.

What I expected instead: Some kind of a rational failure.

The attached patch simply switches the $db_prefix back to what it is supposed to be before handling proceeds. The result is that Simpletest registers the full requisite information.

Comments

rfay’s picture

The attached shows the exception handling in Simpletest *with* the patch.

rfay’s picture

Title: assert() needs to catch exception on db_insert() » DrupalTestCase::assert() needs to catch exception on db_insert()
dries’s picture

+++ modules/simpletest/drupal_web_test_case.php
@@ -443,7 +452,7 @@ abstract class DrupalTestCase {
-          $this->exceptionHandler($e);
+          $x = $this->exceptionHandler($e);

I don't understand why we assign this to $x. Debugging left-over?

rfay’s picture

Ah, but you *do* understand. Debugging of course. Good eye.

Status: Needs review » Needs work

The last submitted patch, drupal.simpletest_reset_current_db_818838_04.patch, failed testing.

aspilicious’s picture

Status: Needs work » Needs review
rfay’s picture

The "can't drop database" is plaguing DamZ's fine testing server. I just reset it, but will see if there's anything we can actually do about it.

rfay’s picture

Status: Needs review » Needs work

The last submitted patch, drupal.simpletest_reset_current_db_818838_04.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.