You are here

public function MetatagTestBase::setupLocales in Metatag 7

Set up a basic starting point for the locales.

This assumes the Locale module is enabled. This also must be done before other user accounts are logged in.

Parameters

array $locales: A list of locales to be enabled, in langcode format.

10 calls to MetatagTestBase::setupLocales()
MetatagContextWithI18nTest::setUp in metatag_context/tests/MetatagContextWithI18nTest.test
Sets up a Drupal site for running functional and integration tests.
MetatagCoreLocaleTest::testNodeFormTranslations in tests/MetatagCoreLocaleTest.test
Test that the node form meta tag fields are translated correctly.
MetatagCoreNodeWithI18nTest::setUp in tests/MetatagCoreNodeWithI18nTest.test
Sets up a Drupal site for running functional and integration tests.
MetatagCoreTermWithI18nTest::setUp in tests/MetatagCoreTermWithI18nTest.test
Sets up a Drupal site for running functional and integration tests.
MetatagCoreWithI18nConfigTest::setUp in tests/MetatagCoreWithI18nConfigTest.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

tests/MetatagTestBase.test, line 301
A base class for the Metatag tests, provides shared methods.

Class

MetatagTestBase
A base class for the Metatag tests, provides shared methods.

Code

public function setupLocales(array $locales = array()) {

  // If no locales were requested, add Spanish and French.
  if (empty($locales)) {
    $locales[] = 'es';
    $locales[] = 'fr';
  }

  // Log in as an admin user with privs to just set up the locales.
  $perms = array(
    'administer languages',
    'translate interface',
    'access administration pages',
  );
  $admin_user = $this
    ->drupalCreateUser($perms);
  $this
    ->drupalLogin($admin_user);

  // Load the admin page, just to have a point of reference.
  $this
    ->drupalGet('admin');
  $this
    ->assertResponse(200, 'Loaded the main admin page.');

  // Identify the site's default language.
  $default_language = language_default('language');

  // Add the locales.
  foreach ($locales as $langcode) {

    // Don't create the default language, it's already present.
    if ($langcode != $default_language) {
      $this
        ->addSiteLanguage($langcode);
    }
  }

  // Enable URL language detection and selection.
  $this
    ->drupalGet('admin/config/regional/language/configure');
  $this
    ->assertResponse(200);
  $edit = array(
    'language[enabled][locale-url]' => TRUE,
  );

  // Also enable path handling for Entity Translation if it is installed.
  if (module_exists('entity_translation')) {
    $edit['language_content[enabled][locale-url]'] = TRUE;
  }
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  $this
    ->assertResponse(200);

  // Once all the setup is done, log out the user.
  $this
    ->drupalLogout();
}