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.
Comment | File | Size | Author |
---|---|---|---|
#43 | force-english-language-276153-42.patch | 1.07 KB | xjm |
#42 | 276153-force-english-language.patch | 1.04 KB | xjm |
#40 | 276153-force-english-language.patch | 1.04 KB | andypost |
#24 | simpletest-tests-wont-work-with-non-default-language-276153-24.diff | 1.1 KB | das-peter |
#17 | 276153-locale-simpletest-d7.patch | 779 bytes | andypost |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedComment #2
boombatower CreditAttribution: boombatower commentedDid 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.
Comment #3
pwolanin CreditAttribution: pwolanin commentedLocale was enabled in the drupal install (hence adding the language and making it the default). The test enables it also via setUp.
Comment #4
pwolanin CreditAttribution: pwolanin commentedComment #5
pwolanin CreditAttribution: pwolanin commentedjust 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
Comment #6
boombatower CreditAttribution: boombatower commentedDoesn't seem to break anything with default language of English.
Attached patch removes extra white-space.
Comment #7
Dries CreditAttribution: Dries commentedThis looks like a bit of a hack. We can't keep patching things like that -- it won't be a scalable solution.
Comment #8
boombatower CreditAttribution: boombatower commentedOne option would be to just force the default language to be English when running tests.
Comment #9
boombatower CreditAttribution: boombatower commentedComment #10
pwolanin CreditAttribution: pwolanin commented@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?
Comment #11
boombatower CreditAttribution: boombatower commentedCould 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.
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedThe last submitted patch failed testing.
Comment #13
jbrown CreditAttribution: jbrown commentedEnable 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.
Comment #14
jbrown CreditAttribution: jbrown commentedComment #15
jbrown CreditAttribution: jbrown commentedUsing the patch at http://drupal.org/node/742246#comment-2801896 even more information is revealed:
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.
Comment #16
jbrown CreditAttribution: jbrown commentedRerolled #6 - it works for me.
Comment #17
andypostConfirm that this fixes simpletest when default language is different from English.
PS: re-roll against current HEAD
Comment #18
boombatower CreditAttribution: boombatower commentedAssuming this passes tests..looks sound. +1
Comment #19
andypostThis is a really critical because simpletest is unusable for other languages
Comment #20
catchNot critical, SimpleTest is a developer-only tool, PHP and code comments are unusable in other languages too.
Comment #21
andypostThis bug is really annoing
Comment #22
webchickUp 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.
Comment #23
andypostWe need to reset globals because tested instance functions are related to them. $language http://api.drupal.org/api/function/t/7
Comment #24
das-peter CreditAttribution: das-peter commentedHi 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
Comment #25
klausitrailing white space
Powered by Dreditor.
Comment #26
andypost@das-peter You use the same approach - setting global $language variable without changing it back after test run
Comment #27
das-peter CreditAttribution: das-peter commentedThanks 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.
Comment #28
sun.core CreditAttribution: sun.core commentedThe manually setup language object looks odd. Hope that plach can shed some light on this.
Comment #29
the greenman CreditAttribution: the greenman commentedFor 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:
Comment #30
hass CreditAttribution: hass commented#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.
Comment #31
enikola CreditAttribution: enikola commentedsub
Comment #32
LoMo CreditAttribution: LoMo commentedFollowing...
Comment #33
Freso CreditAttribution: Freso commentedSubscribing.
Comment #34
oriol_e9gSame problem and I can confirm that #24 patch works
EDIT by boombatower: Change
<?php to <code>
Comment #35
plachBugs are fixed in the development version first, backported then.
Hope to be able to have a look to this sooner or later.
Comment #36
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedSubscribe. I reported this too, in #1164042: Simpletest is completely failed when you install a localized Drupal . I think, this is a critical error.
Comment #37
kwas CreditAttribution: kwas commented#24 - помогло
Comment #38
Tor Arne Thune CreditAttribution: Tor Arne Thune commentedkwas, are you going to work on this, or was it just a misunderstanding about the field? It happens :)
Comment #39
webchickA few problems with this patch as-is:
this is introducing whitespace
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?
Let's write this out long-hand like:
(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.
Comment #40
andypostAdded comment pointing to language_default() as templeate for default English language
Comment #41
catchconvertion 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.
Comment #42
xjmRerolled with a clearer comment and spelling correction.
Comment #43
xjmExcept I totally uploaded the old patch.
Comment #43.0
xjmUpdated issue summary.
Comment #44
xjmAdded issue summary.
Comment #45
andypostThis can't be tested so RTBC
Filed #1232506: Cleanup all array to object conversions
Comment #45.0
andypostRewording for clarity.
Comment #46
webchickI'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!
Comment #47.0
(not verified) CreditAttribution: commentedUpdated issue summary.