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?

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';
| improve this answer | |
  • 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 Jan 4 '14 at 22:50
-1

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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