Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

modules/translation/translation.test, line 24
Tests for the Translation module.

Class

TranslationTestCase
Functional tests for the Translation module.

Code

function setUp() {
  parent::setUp('locale', 'translation', 'translation_test');

  // Setup users.
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'bypass node access',
    'administer nodes',
    'administer languages',
    'administer content types',
    'administer blocks',
    'access administration pages',
    'translate content',
  ));
  $this->translator = $this
    ->drupalCreateUser(array(
    'create page content',
    'edit own page content',
    'translate content',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Add languages.
  $this
    ->addLanguage('en');
  $this
    ->addLanguage('es');
  $this
    ->addLanguage('it');

  // Disable Italian to test the translation behavior with disabled languages.
  $edit = array(
    'enabled[it]' => FALSE,
  );
  $this
    ->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));

  // Set "Basic page" content type to use multilingual support with
  // translation.
  $this
    ->drupalGet('admin/structure/types/manage/page');
  $edit = array();
  $edit['language_content_type'] = 2;
  $this
    ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  $this
    ->assertRaw(t('The content type %type has been updated.', array(
    '%type' => 'Basic page',
  )), 'Basic page content type has been updated.');

  // Enable the language switcher block.
  $language_type = LANGUAGE_TYPE_INTERFACE;
  $edit = array(
    "blocks[locale_{$language_type}][region]" => 'sidebar_first',
  );
  $this
    ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

  // Enable URL language detection and selection to make the language switcher
  // block appear.
  $edit = array(
    'language[enabled][locale-url]' => TRUE,
  );
  $this
    ->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
  $this
    ->assertRaw(t('Language negotiation configuration saved.'), 'URL language detection enabled.');
  $this
    ->resetCaches();
  $this
    ->drupalLogin($this->translator);
}