I'm trying to update the Drupal 7 version of the password_policy.test file that is included with the Password Policy module. When I run the tests, I'm getting "Fatal error: Call to undefined function password_policy_constraint_uppercase_validate()".

The function in question is in an include file in the constraints subdirectory, located inside the module's directory. I've tried adding to the test's setUp() function, along the lines of:

drupal_load('module', 'password_policy');
module_load_include('inc', 'password_policy', 'constraint_uppercase');

I've also tried adding the module_load_include line inside the individual test method generating the error. However, none of my attempts so far appear to be working and the error still persists.

How should I go about loading the ./constraints/constraint_uppercase.inc and other include files, so that the necessary functions are loaded prior to the tests being run?

2 Answers 2


You have a flaw in your code, module_load_include works by including files relative to the module base dir, so you should do

module_load_include('inc', 'password_policy', 'constraints /constraint_uppercase');

to include password_policy/constraints/constraint_uppercase.inc

When you do

module_load_include('inc', 'password_policy', 'constraint_uppercase');

You instead try to include password_policy/constraint_uppercase.inc which doesn't exist.


I believe you can add in the modules .info file:

files[] = constraints/includeme.inc
files[] = constraints/includeme2.inc
files[] = tests/included.test
  • 4
    Files added in the info file on serve the purpose of building the class registry, which allows Drupal to auto load files which contain the needed definition of a PHP class. That's why you should add the test file in the info file, as tests are classes, but this won't solve the problem of loading a class in the test itself.
    – googletorp
    Commented Jan 23, 2012 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.