4

Now my module has two main files:

  • menu_perm.module
  • menu_perm.admin.inc

I added second file to .info:

files[] = menu_perm.admin.inc

I cleared the cache.

In my test class (PHPUnit) file I am bootrapping Drupal by:

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

and I call form submit function manually inside test function, ends with below error:

Call to undefined function menu_perm_user_form_submit()

Function is in menu_perm.admin.inc.

Before this everything was ok.

What am I doing wrong here?

2 Answers 2

3

files[] only works for class/interface autoloading, it won't include arbitrary PHP files. The docs say

Drupal now supports a dynamic-loading code registry. To support it, all modules must now declare any code files containing class or interface declarations in the .info file

You can get around it by adding a line like this to the top of your .module file:

require_once DRUPAL_ROOT . '/sites/all/modules/my_module/my_module.admin.inc';
1
  • 1
    I would rather use DIR instead of an absolute path. As long as you are within the same module and not within a hook implementation, this is the safest way to do it.
    – donquixote
    Commented Jan 4, 2014 at 22:50
-1

Use module_load_include inside your test function, e.g.
module_load_include('inc', 'my_module', 'my_module.admin');

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.