Download & Extend

Testing does not work at all when locale of host session is not English

Project:Drupal core
Version:8.x-dev
Component:language system
Category:bug report
Priority:major
Assigned:kwas
Status:closed (fixed)
Issue tags:needs backport to D7

Issue Summary

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.

Comments

#1

Title:exceptions in locale test» exceptions in locale test when the defualt language is not the built-in language

#2

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.

#3

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

#4

Status:postponed (maintainer needs more info)» active

#5

Status:active» needs review

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

AttachmentSizeStatusTest resultOperations
locale-test-exceptions-276153-5.patch960 bytesIdleFailed: Failed to apply patch.View details

#6

Status:needs review» reviewed & tested by the community

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

Attached patch removes extra white-space.

AttachmentSizeStatusTest resultOperations
locale-test-exceptions-276153.patch874 bytesIdleFailed: Failed to apply patch.View details

#7

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

#8

Status:reviewed & tested by the community» needs work

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

#9

Status:needs work» needs review

#10

@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?

#11

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.

#12

Status:needs review» needs work

The last submitted patch failed testing.

#13

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.

#14

Component:base system» simpletest.module

#15

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.

#16

Status:needs work» needs review

Rerolled #6 - it works for me.

AttachmentSizeStatusTest resultOperations
locale-test-exceptions.patch720 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 19,024 pass(es).View details

#17

Status:needs review» reviewed & tested by the community

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

PS: re-roll against current HEAD

AttachmentSizeStatusTest resultOperations
276153-locale-simpletest-d7.patch779 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 22,200 pass(es).View details

#18

Assuming this passes tests..looks sound. +1

#19

Priority:normal» critical

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

#20

Priority:critical» major

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

#21

This bug is really annoing

#22

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.

#23

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

#24

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

AttachmentSizeStatusTest resultOperations
simpletest-tests-wont-work-with-non-default-language-276153-24.diff1.1 KBIdlePASSED: [[SimpleTest]]: [MySQL] 23,317 pass(es).View details

#25

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.

#26

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

#27

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.

#28

Component:simpletest.module» language system
Priority:major» normal

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

#29

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

#30

#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.

#31

sub

#32

Following...

#33

Subscribing.

#34

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=ove... [: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>

#35

Version:7.x-dev» 8.x-dev
Priority:normal» major

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

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

#36

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

#37

Version:8.x-dev» 7.4
Assigned to:Anonymous» kwas
Status:needs work» reviewed & tested by the community

#24 - помогло

#38

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 :)

#39

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:

<?php
$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.

#40

Status:needs work» needs review

(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

AttachmentSizeStatusTest resultOperations
276153-force-english-language.patch1.04 KBIdlePASSED: [[SimpleTest]]: [MySQL] 33,534 pass(es).View details

#41

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.

#42

Rerolled with a clearer comment and spelling correction.

AttachmentSizeStatusTest resultOperations
276153-force-english-language.patch1.04 KBIdlePASSED: [[SimpleTest]]: [MySQL] 33,577 pass(es).View details

#43

Except I totally uploaded the old patch.

AttachmentSizeStatusTest resultOperations
force-english-language-276153-42.patch1.07 KBIdlePASSED: [[SimpleTest]]: [MySQL] 33,586 pass(es).View details

#44

Added issue summary.

#45

Status:needs review» reviewed & tested by the community

This can't be tested so RTBC

Filed #1232506: Cleanup all array to object conversions

#46

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!

#47

Status:fixed» closed (fixed)

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

nobody click here