function GlobalRedirectTestCaseConfigLanguages::setUp in Global Redirect 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 GlobalRedirectTestCase::setUp
See also
DrupalWebTestCase::prepareDatabasePrefix()
DrupalWebTestCase::changeDatabasePrefix()
DrupalWebTestCase::prepareEnvironment()
File
- ./
globalredirect.test, line 471 - Global Redirect functionality tests
Class
Code
function setUp(array $modules = array()) {
parent::setUp(array(
'locale',
'translation',
));
$this->admin_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer nodes',
'administer languages',
'administer content types',
'administer blocks',
'access administration pages',
));
$this
->drupalLogin($this->admin_user);
// Force each lang code to have a prefix.
foreach (array(
'en',
'fr',
'de',
) as $langcode) {
$prefix = '';
if ($langcode != 'en') {
$this
->addLanguage($langcode);
$prefix = $langcode;
}
$edit = array(
'prefix' => $prefix,
);
$this
->drupalPost('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language'));
// TODO: There doesn't seem to be a message to confirm the save was successful!
//$this->assertRaw(t('The configuration options have been saved.'), t('URL language part set to prefix.'));
}
$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',
)), t('Basic page content type has been updated.'));
// Enable URL language detection and selection
$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.'), t('URL language detection enabled.'));
drupal_static_reset('locale_url_outbound_alter');
// Ensure the URL part is set to prefix
$edit = array(
'locale_language_negotiation_url_part' => 0,
);
$this
->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration'));
$this
->assertRaw(t('The configuration options have been saved.'), t('URL language part set to prefix.'));
// Create a dummy english node
// This is Node 2 (node 1 is in the parent::setUp())
$node = array(
'type' => 'page',
'title' => 'Test English Page Node',
'path' => array(
'alias' => 'test-english-node',
),
'language' => 'en',
'tnid' => 2,
'body' => array(
'en' => array(
array(),
),
),
);
// Save the node
$node = $this
->drupalCreateNode($node);
// Create a translation of the english node, tp French
// This is Node 3
$node = array(
'type' => 'page',
'title' => 'Test French Page Node',
'path' => array(
'alias' => 'test-french-node',
),
'language' => 'fr',
'tnid' => 2,
'body' => array(
'fr' => array(
array(),
),
),
);
// Save the node
$node = $this
->drupalCreateNode($node);
// Create another translation of the english node, to German
// This is Node 4
$node = array(
'type' => 'page',
'title' => 'Test German Page Node',
'path' => array(
'alias' => 'test-german-node',
),
'language' => 'de',
'tnid' => 2,
'body' => array(
'de' => array(
array(),
),
),
);
// Save the node
$node = $this
->drupalCreateNode($node);
}