Testing installation profile with custom tasks For a large project, we are using a code driven development workflow. We are using a custom installation profile to install and configure the contrib and custom modules used on the project. The ensure correctness of this profile, we need to test it like any other module.

Currently, we use a SimpleTest test case that looks like this which worked good so far.

class FooTestCase extends DrupalWebTestCase {

  protected $admin_user = null;

  public function getInfo() {
    return array(
      'name' =&gt; 'Foo Profile',
      'description' =&gt; 'Ensure that the Foo profile configure the site.',
      'group' =&gt; 'Foo',
    );
  }

  public function setUp() {
    $this-&gt;profile = 'foo';
    parent::setUp();
  }

  //Test methods ...
}


The site has to be multilingual, so in order to install and enable all the required language, I added a custom profile task using hook_install_tasks. The task works fine when executed from the browser. But it is not executed when DrupalWebTestCase::setUp` is run. So we are unable to test its effect to ensure they are not lost whatever the refactoring our profile will go through in the future.

Since languages installation require translations loading, the task itself use batch processing.

I'm looking for both a way to have this particular task executed in FooTestCase:setUp and more generally to have all the (non interactive tasks) in my profile executed.

For reference, here is the code for the task

function foo_install_tasks($install_state) {
  return array(on
    'foo_install_import_locales' =&gt; array(
      'display_name' =&gt; 'Install additional languages',
      'display' =&gt; TRUE,
      'type' =&gt; 'batch',
      'run' =&gt; INSTALL_TASK_RUN_IF_NOT_COMPLETED,
    )
  );
}

function foo_install_import_locales(&amp;$install_state) {
  include_once DRUPAL_ROOT . '/includes/locale.inc';
  include_once DRUPAL_ROOT . '/includes/iso.inc';
  $batch = array();
  $predefined = _locale_get_predefined_list();
  foreach (array('nl', 'de') as $install_locale) {
    if (!isset($predefined[$install_locale])) {
      // Drupal does not know about this language, so we prefill its values with
      // our best guess. The user will be able to edit afterwards.
      locale_add_language($install_locale, $install_locale, $install_locale, LANGUAGE_LTR, '', '', TRUE, FALSE);
    }
    else {
      // A known predefined language, details will be filled in properly.
      locale_add_language($install_locale, NULL, NULL, NULL, '', '', TRUE, FALSE);
    }

    // Collect files to import for this language.
    $batch = array_merge($batch, locale_batch_by_language($install_locale, NULL));

  }
  if (!empty($batch)) {
      // Remember components we cover in this batch set.
      variable_set('foo_install_import_locales', $batch['#components']);
      return $batch;
  }
}
I typically find it best to leave your installation profile as bare bones as possible, and put tasks like this into hook_enable of a site specific module.  Similarly, any updates that need to be made should be put into hook_update_N functions in the same module, while updating the hook_enable implementation.

This makes it much simpler to test and has the added benefit of keeping all of your setup and updates in one place.