I am attempting to write tests that includes content types exported by a feature.

So far I'm not having any luck. I'm using drupal 7.x-rc4 and feature 7.x-1.x-dev (2010-Oct-25).

If anyone has working examples of this I would love to check it out.

I found some interesting ideas (although for drupal 6) here: http://activismlabs.org/2010/07/28/create-simple-tests-for-drupal-features/

For example in setUp():

// Run a features rebuild to ensure our feature is fully installed.
    features_rebuild();
    
    // Clear all caches so everything from the feature is recognized now that it is fully loaded.
    cache_clear_all();

But unfortunately the error didn't change.

I also tried looking at the feeds module (as an implementation of a feature that has lots of tests). I tried a few things I saw there but I'm a bit new to simpletest so I couldn't really dig too deeply. But I did try this since the error seemed to be about not having the permissions loaded at the right time:

parent::setUp('ctools');
    // Enable modules
    $add_modules = array(
      'ctools',
      'views',
      'features',
      'custom_feature',
    );
    foreach ($add_modules as $m) {
      $modules[] =  $m;
    }
    module_enable($modules, TRUE);
    
    $this->resetAll();

The error appears to be about the permissions (see below).

The subsequent messages on the test page are:
* Undefined index: create custom_content_type content Notice user.module 2966 user_role_grant_permissions() Exception
* Trying to get property of non-object Notice session.inc 176 _drupal_session_write()

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /Quilted/Admin/Systems/Testing/simpletest/batch?id=36&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null: INSERT INTO {role_permission} (rid, permission, module) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => create custom_content_type content [:db_insert_placeholder_2] => ) in user_role_grant_permissions() (line 2968 of /modules/user/user.module).Uncaught exception thrown in session handler.PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'uid' cannot be null: INSERT INTO {sessions} (sid, ssid, uid, cache, hostname, session, timestamp) 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); Array ( [:db_insert_placeholder_0] => zxIyqRPqk-OLBY0ISL2cJBAWokdv-J_UxpTwZXrWHPM [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => ::1 [:db_insert_placeholder_5] => batches|a:9:{i:28;b:1;i:29;b:1;i:30;b:1;i:31;b:1;i:32;b:1;i:33;b:1;i:34;b:1;i:35;b:1;i:36;b:1;} [:db_insert_placeholder_6] => 1293779223 ) in _drupal_session_write() (line 204 of /includes/session.inc).

CommentFileSizeAuthor
#7 ctest.tar_.gz1.07 KBlambic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Status: Active » Closed (duplicate)
lambic’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

I don't think this is a duplicate. This ticket refers to features components not showing up in the simpletest environment. I'm experiencing the same problem. Here is my current setUp:

  function setUp() {
    parent::setUp();
    $success = module_enable(array('myfeature'));
    $this->assertTrue($success, 'Enabled module myfeature');
    features_rebuild();
    $obj = features_get_features('myfeature');
    features_rebuild();
    cache_clear_all();
    $this->resetAll();
  }

As you can see I'm trying with some desperation to force features to do its thing, but if I try to reference one of the permissions provided by that feature the test fails saying the permission does not exist.

hefox’s picture

Category: Bug report » Support request

Did you look how the current feature tests enables features?

lambic’s picture

After much digging I'm still not entirely sure what is happening, but here's what I've discovered:

Features tests enables the module to be tested in the call to parent::setUp(), but we can't do that because our feature is dependant on a theme (because of fe_block) so our setUp() function looks like this:

  function setUp() {
    $this->profile = 'minimal';
    parent::setUp();
    theme_enable(array('myTheme'));
    $success = module_enable(array('myModule'));
    $this->assertTrue($success, 'Enabled module');
    features_rebuild();
  }

If I try to do parent::setUp('myTheme', 'myModule') it fails because module_enable() gets called on the theme, which returns false. In theory though the above should be the same, as all drupalWebTestCase::setUp() does is a module_enable().

However when I run the test:

  field_info_instance('node', 'field_item_id', 'channel_news');
  $this->assertTrue(!empty($object), t('@component present.', array('@component' => 'field_item_id')));

Even though I know that field exists in the feature and shows up fine in a normal environment.

To remove the theme issue I took the fe_block stuff out of the feature completely so now my setUp() function is basically the same as the one in features test, but the result of the test still fails.

My next step is to start taking components out of the feature until it magically starts working, but any other suggestions welcome.

lambic’s picture

Ha, turns out my test was invalid as I wasn't defining $object. Too early in the morning I guess.

I'm still having trouble with perms, but at least the fields are showing up now.

lambic’s picture

Here's where I am at the end of a frustrating day:

After setUp() runs, I can see the featurised roles and permissions.

After I run drupalCreateUser() I can still see the featurised roles and permissions.

After I add my custom roles to the user I can still see the featurised roles and permissions.

As soon as I do $this->drupalLogin($user) the permissions for my custom role disappear.

In features_test it doesn't look like you ever actually test that the permission gets applied to a user so I can't copy a test from there.

lambic’s picture

FileSize
1.07 KB

I've distilled this problem down to the attached feature which defines a single role and attempts to grant 'access toolbar' permission to that role. This works in a normal environment but fails in the test. The permission is there before doing a drupalLogin and gone after.