Problem/Motivation

DrupalWebTestCase::prepareEnvironment() overrides only $GLOBALS['language']. Other languages ($GLOBALS['language_content'] and $GLOBALS['language_url']) remain from the current Drupal installation which is not good because they may be used (see example in #4).

Proposed resolution

Override all language types.

Original report:

Project: title 7.x-1.x

Title: Random test fails because of "en/" path prefix

Test from the latest dev (d6f2000) fail randomly on my local installation (Drupal 7.39 + stable versions of required modules). This happens because the "en/" path prefix is sometimes (randomly) added to the path in drupalGet()/drupalPost() calls.

I'm going to fix this, but first I need to know if this happens with drupal.org testbot too.

CommentFileSizeAuthor
#6 2579083-6.patch2.8 KBLeksat
#2 2579083-2-check_tests.patch258 bytesLeksat
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Leksat created an issue. See original summary.

Leksat’s picture

Status: Active » Needs review
FileSize
258 bytes
Leksat’s picture

Status: Needs review » Closed (cannot reproduce)

Hmm... Test pass here.

Leksat’s picture

Project: Title » Drupal core
Status: Closed (cannot reproduce) » Active

I've dug this a bit more. It's not random.

Some tests fail when running them in the Drupal installation which
- have more than one language
- default language uses path prefix
In general, on non-default installation.

Tests fail because drupalGet() and drupalPost() uses url() to process the request path. The url() is executed and, for some reason, the $GLOBALS['language_url'] is the language from the current Drupal installation. And it is used as the default language for the URL rewrite.

Callstack:

- DrupalWebTestCase::drupalGet()
- url()
- drupal_alter()
- locale_url_outbound_alter()
- locale_language_url_rewrite_url()

The piece of code from the locale_language_url_rewrite_url() that takes wrong language:

  // Language can be passed as an option, or we go for current URL language.
  if (!isset($options['language'])) {
    global $language_url;
    $options['language'] = $language_url;
  }

http://cgit.drupalcode.org/drupal/tree/includes/locale.inc?h=7.39#n423

So, it's a simpletest issue.

Leksat’s picture

Version: 7.x-1.x-dev » 7.x-dev
Component: Code » simpletest.module
Leksat’s picture

Assigned: Leksat » Unassigned
Status: Active » Needs review
FileSize
2.8 KB
Leksat’s picture

Title: Random test fails because of "en/" path prefix » Simpletest does not override languages other than LANGUAGE_TYPE_INTERFACE
Issue summary: View changes

Updated issue summary.

Leksat’s picture

Issue summary: View changes
vasi1186’s picture

  1. +++ b/modules/simpletest/drupal_web_test_case.php
    @@ -1364,10 +1364,13 @@ class DrupalWebTestCase extends DrupalTestCase {
    +    foreach (drupal_language_types() as $language_type => $_) {
    +      $this->originalLanguages[$language_type] = $GLOBALS[$language_type];
    

    This is totally correct PHP code, but not sure if we should use variable names like '$_', even though they are not used for anything. I also haven't seen this in the core elsewhere. In this case, I would suggest to just rename the variable to '$configurable' or something like this.

  2. +++ b/modules/simpletest/drupal_web_test_case.php
    @@ -1377,7 +1380,9 @@ class DrupalWebTestCase extends DrupalTestCase {
    +    foreach (drupal_language_types() as $language_type => $_) {
    

    Same as before

  3. +++ b/modules/simpletest/drupal_web_test_case.php
    @@ -1689,8 +1694,10 @@ class DrupalWebTestCase extends DrupalTestCase {
    +    foreach (drupal_language_types() as $language_type => $_) {
    

    Same as before.