You are here

public function MetatagHreflangWithEntityTranslationTest::setUp in Metatag 7

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 MetatagTestBase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

metatag_hreflang/tests/MetatagHreflangWithEntityTranslationTest.test, line 28
Tests for hreflang handle when Entity Translation is used.

Class

MetatagHreflangWithEntityTranslationTest
Tests for hreflang handle when Entity Translation is used.

Code

public function setUp(array $modules = array()) {

  // Used for debugging some token values.
  $modules[] = 'devel';

  // Need Locale for the multiple languages.
  $modules[] = 'locale';

  // Need Entity Translation for the tokens to work.
  $modules[] = 'entity_translation';

  // This module.
  $modules[] = 'metatag_hreflang';

  // Enable all of the modules & install the site.
  parent::setUp($modules);

  // Add some new languages.
  $this
    ->setupLocales($this
    ->supportedLocales());

  // The content that will be used.
  $content_type = 'page';

  // Create an admin user that can also manage locales.
  $perms = array(
    // For Locale, so languages can be added.
    'administer languages',
    // For Entity Translation, so content can be translated.
    'translate any entity',
    // For Devel, for access to the node's "devel" tab.
    'access devel information',
    // For Field UI, so field settings can be changed.
    'administer fields',
    // For Node, so content type settings can be changed.
    'administer content types',
    // For Node, so content can be created and edited.
    'create ' . $content_type . ' content',
    'edit any ' . $content_type . ' content',
  );
  $this->adminUser = $this
    ->createAdminUser($perms);

  // Log in the admin user.
  $this
    ->drupalLogin($this->adminUser);

  // Enable translation support for the content type.
  variable_set('language_content_type_' . $content_type, ENTITY_TRANSLATION_ENABLED);

  // Allow the body field to be translated.
  $this
    ->drupalGet('admin/structure/types/manage/' . $content_type . '/fields/body');
  $this
    ->assertResponse(200);
  $this
    ->assertFieldByName('field[translatable]');
  $edit = array(
    'field[translatable]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));

  // Clear all the caches so that all of the various hooks are activated and
  // the appropriate tokens, fields, meta tags, etc are available.
  drupal_flush_all_caches();
}