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' => 'Foo Profile',
'description' => 'Ensure that the Foo profile configure the site.',
'group' => 'Foo',
);
}
public function setUp() {
$this->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' => array(
'display_name' => 'Install additional languages',
'display' => TRUE,
'type' => 'batch',
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
)
);
}
function foo_install_import_locales(&$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;
}
}