I'm trying to test some permissions that are related to custom node types and Organic Groups that I've built and packaged as a feature using the features module.

I'm trying to enable the feature (and create all the content types and taxonomies that are part of the feature) in the setUp method of my simpletest test case class like this:

class PermissionsTestCase extends DrupalWebTestCase {
  public function setUp() {

    // More setup stuff that depends on content types and taxonomies in my feature
    // ...

However, when I look at the output of module_list it doesn't include my feature or the dependencies and subsequent setup tasks that rely on a taxonomy that's part of my feature don't find the taxonomy vocabulary.

Can I enable a module created with features in the setUp method? What's the best way to do this?

Do I have to explicitly specify the dependencies of my feature in the call to parent::setUp? What about the dependencies of my dependencies? Does the order matter?


As of Drupal 7 you don't have to explicitly specify module dependencies, they are resolved automatically. The order doesn't matter either for that same reason.

As far as actually enabling the feature, it should be fine... I was going to suggest calling drupal_static_reset('system_list') before module_list() but it already does that itself when you pass TRUE as the first param like you did.

I've had some issues when testing features modules and, in certain situations, I've found that it's actually better (and much slower) to force SimpleTest to use the live database.

Granted, that's very specific to certain types of client projects, but still, might help! :)

  • I'm going to accept "it should be fine" as the answers, because all other research I did indicated this as well. I ended up punting on the whole SimpleTest mess and using a persistent test database and writing more integration-style tests using Behat. I know it's best to write both unit and integration tests, but given the friction of working with SimpleTest in this case, and a tight timeline, it was the best option. Jan 16 '14 at 5:12

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.