In the current Drupal 7, if you have the Profile module enabled, and then go to admin/config/development/testing and try to run your choice of any test on the system, it will fail with a fatal error, which looks something like this:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd7git.simpletest380601profile_field' doesn't exist: SELECT DISTINCT(category) FROM {profile_field}; Array

If you disable the Profile module before starting the tests, the tests will run as usual.

Comments

jhodgdon’s picture

Component: profile.module » simpletest.module

This SQL query appears to be coming from the function profile_user_categories() in profile.module (only place I could find it in the code), which is an implementation of hook_user_categories().

This hook is only invoked in _user_categories() in user.module, which is called from user_category_load() and user_menu(). Which both work just fine for running Drupal, with or without the profile module being installed.

So I think this is actually a simpletest issue or something to do with an interaction between simpletest and the registry, where simpletest is thinking the profile module is installed and trying to call its profile_user_categories() function when the module hasn't been actually enabled in such a way as to install its table. Because my regular Drupal database has this table, it's just not in simpletest's user space.

And by the way, two other people who were on an IRC channel with me yesterday had this issue, it's not just me. :)

jhodgdon’s picture

I'm not all that familiar with the guts of SimpleTest, but it looks to me as though the problem is DrupalWebTestCase->preloadRegistry(), which is apparently preloading the function registry from the Drupal installation that the tests are being run from. But it is apparently not installing all the modules that might be referenced in the registry.

I could be wrong... I will let a SimpleTest expert figure this out, but it seems to me that preloading the registry from the environment that you are running the tests from is not a good idea. Maybe the registry could be built during the first test run, rather than that? You should be able to run tests, no matter what modules you have enabled on your Drupal site, shouldn't you?

jhodgdon’s picture

Today it is even worse. I did a CVS update and Simpletest cannot even seem to initialize at all. It's getting a database error when it tries to set up the menu router table, apparently:

Message: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO {menu_router} (path, load_functions, to_arg_functions, access_callback, access_arguments, page_callback, page_arguments, fit, number_parts, tab_parent, tab_root, title, title_callback, title_arguments, type, block_callback, description, position, weight, file) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8,  .....

(this error message goes on for many many many lines)

jvandyk’s picture

The problem is that when Simpletest does its setup, the toolbar.module's .install function does a menu_rebuild(). This is very early in the installation process, and almost no modules are enabled yet (maybe only system module?). So menu hook implementations that expect some information from the system with which to build their menu items will, say, query the database for something that will become the title of their current menu item, but unexpectedly not find it, so the title of the menu item becomes NULL. Saving a menu item with a NULL title generates the error.

jhodgdon’s picture

Status: Active » Closed (fixed)

This problem has vanished. Probably because the function registry vanished, which is what was causing the problem, in my analysis.