Problem/Motivation

SimpleTest cannot be used on sites in languages other than English, because t() throws exceptions during installation if the language is not set to English.

Proposed resolution

During DrupalWebTestCase installation, manually set the language to the values used as the default in language_default().

Remaining tasks

Revised solution needs committer approval.

A followup on array/object conversion generally is in #1232506: Cleanup all array to object conversions.

User interface changes

None.

API changes

None.

Original report by @pwolanin

first, enable locale module and create a custom language (or alternately, add an known language). Make this other language the default.

rune the existing locale test:

87 passes, 0 fails, 810 exceptions

Appears to be due to a stale static variable, since the exceptions all relate to the "default" language that is set via the UI, e.g. t.language = 'en-US when I added a custom language with this language code or t.language = 'bn' when I added Bengali and made it the default.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Title: exceptions in locale test » exceptions in locale test when the defualt language is not the built-in language
boombatower’s picture

Status: Active » Postponed (maintainer needs more info)

Did you enable to locale module in the test or in the drupal install and then run the test?

The tests should all be running in a separate db instance.

pwolanin’s picture

Locale was enabled in the drupal install (hence adding the language and making it the default). The test enables it also via setUp.

pwolanin’s picture

Status: Postponed (maintainer needs more info) » Active
pwolanin’s picture

Status: Active » Needs review
FileSize
960 bytes

just ran into this again, and forgot I'd even filed this issue!

The attached patch seems to prevent the exceptions - I'm not sure if there is another option. Sadly, this patch didn't help: http://drupal.org/node/274489

boombatower’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
874 bytes

Doesn't seem to break anything with default language of English.

Attached patch removes extra white-space.

Dries’s picture

This looks like a bit of a hack. We can't keep patching things like that -- it won't be a scalable solution.

boombatower’s picture

Status: Reviewed & tested by the community » Needs work

One option would be to just force the default language to be English when running tests.

boombatower’s picture

Status: Needs work » Needs review
pwolanin’s picture

@Dries/boombatower - this basically relates to the broader problem that we have a window between when the test precess starts and when the new Drupal instance is installed where the existing variables and globals may cause errors and exceptions like this. The default language will always be English once the test is actually running.

So, I'm not sure how to solve this sort of problem without some other fundamental adjustments to the way the tests work. For example - (just brainstorming) could you run a clean install of Drupal for use as the environment that runs simpletest? I'm not sure how you would pass through the information about what tests are to be run, however, or pass back the results. Maybe XML-RPC?

boombatower’s picture

Could use the existing mechanism used for simpletest.test.

Another option is to warn users that they should be using a vanilla Drupal install for testing.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

jbrown’s picture

Title: exceptions in locale test when the defualt language is not the built-in language » Testing does not work at all when locale of host session is not English
Component: tests » base system

Enable Locale, set your language to German and attempt to run a test.

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /drupal-7.x-dev/batch?id=11&op=do StatusText: Service unavailable (with message) ResponseText: Additional uncaught exception thrown while handling exception.OriginalPDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal7.simpletest735136locales_source' doesn't exist: SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) de [:version] => 7.0-dev ) in locale() (line 656 of /var/www/drupal-7.x-dev/modules/locale/locale.module).AdditionalPDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal7.simpletest735136locales_source' doesn't exist: SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'; Array ( [:language] => de [:source] => %type: %message in %function (line %line of %file). [:context] => ) in locale() (line 674 of /var/www/drupal-7.x-dev/modules/locale/locale.module). Fatal error: Exception thrown without a stack frame in Unknown on line 0

This is more debugable now that #742246: Handle uncaught exceptions is in.

jbrown’s picture

Component: base system » simpletest.module
jbrown’s picture

Using the patch at http://drupal.org/node/742246#comment-2801896 even more information is revealed:

An AJAX HTTP error occurred.

HTTP Result Code: 500 Debugging information follows. 
Path: /drupal-7.x-dev/batch?id=48&op=do 
StatusText: Service unavailable (with message) 
ResponseText:

Additional uncaught exception thrown while handling exception.

Original
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal7.simpletest784919locales_source' doesn't exist: SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) de [:version] => 7.0-dev ) in locale() (line 656 of /var/www/drupal-7.x-dev/modules/locale/locale.module).

Additional
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal7.simpletest784919locales_source' doesn't exist: SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'; Array ( [:language] => de [:source] => %type: %message in %function (line %line of %file). [:context] => ) in locale() (line 674 of /var/www/drupal-7.x-dev/modules/locale/locale.module).

Uncaught exception thrown in session handler.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'uid' cannot be null: INSERT INTO {sessions} (uid, cache, hostname, session, timestamp, sid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5) ON DUPLICATE KEY UPDATE uid=VALUES(uid), cache=VALUES(cache), hostname=VALUES(hostname), session=VALUES(session), timestamp=VALUES(timestamp); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => 0 [:db_insert_placeholder_2] => 192.168.1.4 [:db_insert_placeholder_3] => batches|a:48:{i:1;b:1;i:2;b:1;i:3;b:1;i:4;b:1;i:5;b:1;i:6;b:1;i:7;b:1;i:8;b:1;i:9;b:1;i:10;b:1;i:11;b:1;i:12;b:1;i:13;b:1;i:14;b:1;i:15;b:1;i:16;b:1;i:17;b:1;i:18;b:1;i:19;b:1;i:20;b:1;i:21;b:1;i:22;b:1;i:23;b:1;i:24;b:1;i:25;b:1;i:26;b:1;i:27;b:1;i:28;b:1;i:29;b:1;i:30;b:1;i:31;b:1;i:32;b:1;i:33;b:1;i:34;b:1;i:35;b:1;i:36;b:1;i:37;b:1;i:38;b:1;i:39;b:1;i:40;b:1;i:41;b:1;i:42;b:1;i:43;b:1;i:44;b:1;i:45;b:1;i:46;b:1;i:47;b:1;i:48;b:1;} [:db_insert_placeholder_4] => 1270292119 [:db_insert_placeholder_5] => b4fd326c417fc74ecab9556685018d09 ) in _drupal_session_write() (line 171 of /var/www/drupal-7.x-dev/includes/session.inc).

There is also this warning in the testing log: Trying to get property of non-object Notice session.inc 151 _drupal_session_write()

It is trying to write the session when $user hasn't even been set.

jbrown’s picture

Status: Needs work » Needs review
FileSize
720 bytes

Rerolled #6 - it works for me.

andypost’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
779 bytes

Confirm that this fixes simpletest when default language is different from English.

PS: re-roll against current HEAD

boombatower’s picture

Assuming this passes tests..looks sound. +1

andypost’s picture

Priority: Normal » Critical

This is a really critical because simpletest is unusable for other languages

catch’s picture

Priority: Critical » Major

Not critical, SimpleTest is a developer-only tool, PHP and code comments are unusable in other languages too.

andypost’s picture

This bug is really annoing

webchick’s picture

Up in #7, Dries already stated he doesn't like this solution. I agree that anything messing with $GLOBALS sounds like a tremendously bad idea. :)

I'll see if I can grab him later to figure out if he has another suggestion.

andypost’s picture

We need to reset globals because tested instance functions are related to them. $language http://api.drupal.org/api/function/t/7

das-peter’s picture

Hi there,

currently I use the attached modification to run the tests.
Frankly speaking I've absolutely no clue about the deeper impact of this - but it's not messing with GLOBALS and it works for me ;)

Cheers,
Peter

klausi’s picture

Status: Reviewed & tested by the community » Needs work
+++ modules/simpletest/drupal_web_test_case.php	1 Sep 2010 10:11:48 -0000
@@ -1155,6 +1155,9 @@
     $clean_url_original = variable_get('clean_url', 0);
+    ¶
+    //Set to english to prevent utf8_truncate to load semaphore / session stuff

trailing white space

Powered by Dreditor.

andypost’s picture

@das-peter You use the same approach - setting global $language variable without changing it back after test run

das-peter’s picture

Thanks for the feedback - just want to post the link to the other issue I opened some time ago: #874824: Testrun fails with non-english language
There you'll find how far I investigated. If it's really just the problem with the comments of the scheme's it's probably the best way to keep them untranslated or use the save translation function st.

sun.core’s picture

Component: simpletest.module » language system
Priority: Major » Normal

The manually setup language object looks odd. Hope that plach can shed some light on this.

the greenman’s picture

For people who are stuck with this issue and want to automate their tests, I have created some drush commands for managing languages. It's not a solution, but, it can help.

http://drupal.org/project/drush_language

I have a wrapper for run-tests.sh that will switch the language before running the tests:

#!/bin/bash
drush locale-enable en
drush locale-default en
sudo -u www-data php ./scripts/run-tests.sh --url http://example.com
drush locale-default en-gb
drush locale-disable en
hass’s picture

#1015042: Simpletest tables are not created has been marked as a duplicate of this case here. I tried the patch in #17 and it WFM.

enikola’s picture

sub

LoMo’s picture

Following...

Freso’s picture

Subscribing.

oriol_e9g’s picture

Same problem and I can confirm that #24 patch works

Hi ha hagut un error HTTP d'AJAX. Codi de resultat HTTP: 200 A continuació hi ha informació de depuració. Camí: /batch?render=overlay&id=14&op=do StatusText: OK ResponseText: Additional uncaught exception thrown while handling exception.OriginalPDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mediateca.mt_simpletest161513semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => locale_cache_ca ) in lock_may_be_available() (line 164 of /home/web/imatgesbeta.gracianet.cat/htdocs/includes/lock.inc).AdditionalPDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mediateca.mt_simpletest161513watchdog' doesn't exist: INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => php [:db_insert_placeholder_2] => %type: !message in %function (line %line of %file). [:db_insert_placeholder_3] => a:6:{s:5:"%type";s:12:"PDOException";s:8:"!message";s:231:"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mediateca.mt_simpletest161513semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => locale_cache_ca ) ";s:9:"%function";s:23:" lock_may_be_available()";s:5:"%file";s:60:" /home/web/imatgesbeta.gracianet.cat/htdocs/includes/lock.inc";s:5:"%line";i:164;s:14:" severity_level";i:3;} [:db_insert_placeholder_4] => 3 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://imatgesbeta.gracianet.org/batch?render=overlay&id=14&op=do [:db_insert_placeholder_7] => http://imatgesbeta.gracianet.org/batch?op=start&id=14&render=overlay [:db_insert_placeholder_8] => 195.76.106.145 [:db_insert_placeholder_9] => 1302261414 ) in dblog_watchdog() (line 154 of /home/web/imatgesbeta.gracianet.cat/htdocs/modules/dblog/dblog.module).Uncaught exception thrown in shutdown function.PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mediateca.mt_simpletest161513semaphore' doesn't exist: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 10370608784d9eeea67648c3.06908018 ) in lock_release_all() (line 246 of /home/web/imatgesbeta.gracianet.cat/htdocs/includes/lock.inc).Uncaught exception thrown in session handler.PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mediateca.mt_simpletest161513sessions' doesn't exist: SELECT 1 AS expression FROM {sessions} sessions WHERE ( (sid = :db_condition_placeholder_0) AND (ssid = :db_condition_placeholder_1) ) FOR UPDATE; Array ( [:db_condition_placeholder_0] => Xizq3nGE_VaqclF5RpmBDPfpsdRnoIZWGcZR-FFESLc [:db_condition_placeholder_1] => ) in _drupal_session_write() (line 203 of /home/web/imatgesbeta.gracianet.cat/htdocs/includes/session.inc).

EDIT by boombatower: Change <?php to <code>

plach’s picture

Version: 7.x-dev » 8.x-dev
Priority: Normal » Major
Issue tags: +Needs backport to D7

Bugs are fixed in the development version first, backported then.

Hope to be able to have a look to this sooner or later.

Zoltán Balogh’s picture

Subscribe. I reported this too, in #1164042: Simpletest is completely failed when you install a localized Drupal . I think, this is a critical error.

kwas’s picture

Version: 8.x-dev » 7.4
Assigned: Unassigned » kwas
Status: Needs work » Reviewed & tested by the community

#24 - помогло

Tor Arne Thune’s picture

Version: 7.4 » 8.x-dev

kwas, are you going to work on this, or was it just a misunderstanding about the field? It happens :)

webchick’s picture

Status: Reviewed & tested by the community » Needs work

A few problems with this patch as-is:

+++ modules/simpletest/drupal_web_test_case.php	1 Sep 2010 10:11:48 -0000
@@ -1155,6 +1155,9 @@
+    ¶

this is introducing whitespace

+++ modules/simpletest/drupal_web_test_case.php	1 Sep 2010 10:11:48 -0000
@@ -1155,6 +1155,9 @@
+    //Set to english to prevent utf8_truncate to load semaphore / session stuff

1. Comments need to have a space between // and the next letter.

2. English is a proper noun and should be capitalized.

3. I have no idea what "load semaphore / session stuff" means. :) Can you clarify?

+++ modules/simpletest/drupal_web_test_case.php	1 Sep 2010 10:11:48 -0000
@@ -1155,6 +1155,9 @@
+    $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');

Let's write this out long-hand like:

$language = new stdClass;
$language->language = 'en';
$language->native = 'English';
....

(I'm not sure why we're casting an array to an object here; can we just create an object directly?)

13 days to next Drupal core point release.

andypost’s picture

Status: Needs work » Needs review
FileSize
1.04 KB

(I'm not sure why we're casting an array to an object here; can we just create an object directly?)

Added comment pointing to language_default() as templeate for default English language

catch’s picture

convertion should be conversion, but I don't think we need a comment - could we just leave it as it was but open a separate issue for moving away from $foo = (object) array(1, 2, 3); - we do that in lots of places.

I dread to ask but is there any chance this is testable in the simpletest module tests themselves, if the answer is 'no' or 'I don't care' that would be fine though - the fact those tests exist at all saddens me a bit.

xjm’s picture

Rerolled with a clearer comment and spelling correction.

xjm’s picture

Except I totally uploaded the old patch.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Added issue summary.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

This can't be tested so RTBC

Filed #1232506: Cleanup all array to object conversions

andypost’s picture

Issue summary: View changes

Rewording for clarity.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I'm still not sure if this would pass Dries's muster, but this bug has been sitting around for months now. We need a solution, even if it's not the prettiest (we're at least not using $GLOBALS anymore :P).

Committed and pushed to 8.x and 7.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Needs backport to D7

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.