Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We're going to be doing a lot with SimpleTest over the next few months and taking some things from Rails I'd like to work on using a separate test database that takes a snapshot of the current database (or loads some other fixture data), creates a transaction and then rolls it back before the next test (when running more than one test). We've already patched some smaller things but I'd like to do more and test all this stuff before submitting a patch.
If anyone has any suggestions/feedback/etc., please post them here.
Comment | File | Size | Author |
---|---|---|---|
#25 | simpletest_prefixing.patch | 3.81 KB | boombatower |
#18 | prefixing.patch | 3.86 KB | chx |
#17 | prefixing.patch | 2.67 KB | chx |
#15 | prefixing.patch | 3.15 KB | chx |
#14 | prefixing.patch | 3.07 KB | chx |
Comments
Comment #1
webchickI really love this idea. If your tests are buggy, it's possible to totally fubar your database. :P And while there is a very clear sentence in the README that says NOT to use this on a production database, we all know how many people read READMEs. :P
Comment #2
RobRoy CreditAttribution: RobRoy commentedI hate posting unpolished patches, but here is a patch that we're using in some heavy development and it works great for us. I wish I had more time to totally clean up SimpleTest, but I don't. Hopefully someone can run with this. It's got a ton of fixes and some new features including a new variable 'simpletest_base_url' which if set to 'http://d.local' will use that for running tests from the admin panel (although I just use command line to run tests now, much nicer).
What I do for this idea of "fixtures" is create a couple aliases on my local box:
alias dfixtures='mysqldump -u root dbname > ~/d.test.sql; mysql -u root test < ~/d.test.sql'
alias dtest='/apache2/php/bin/php ~/Sites/dev/chipin/d/manager/trunk/htdocs/sites/all/modules/d/tests/run_d_tests.php d.local'
Then run dfixtures, and then dtest which runs a PHP file like this:
Comment #3
Rok Žlender CreditAttribution: Rok Žlender commentedMaybe we could include this into http://drupal.org/node/210679 .
Comment #4
boombatower CreditAttribution: boombatower commentedThis sounds like something that could be useful for SimpleTest. If so we need to affirm it as a community and update this patch.
Comment #5
webchickHere's a snippet (untested, but something pretty similar is working for another project) that will install a profile.
Comment #6
chx CreditAttribution: chx commentedNote that we want to use a prefix like simpletest_abcdefqw , aka randomname(8) so that if simpletest dies on us then we won't get a lot of angry MySQL errors the next run. Using a prefix makes it simpler, a separate database would be complicated for the users.
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedThis is easy stuff for Drush. I will add it to the new simpletest runner. But which profile to use?
This could be slower than just running a mysql statement to load up a DB but we'll try this first.
Comment #8
moshe weitzman CreditAttribution: moshe weitzman commentedOops - I have to port Drush to D6. I'll do that real soon now.
Comment #9
chx CreditAttribution: chx commentedthe profile you are running right now, it's available from settings.php isn't it? if not, then default or provide an admin ui.
Comment #10
chx CreditAttribution: chx commentedThis is going to be somewhat tricky as you need to edit settings.php for subsequent Drupal boots to keep the new (random) prefix and then, when simpletest is done, we need to make sure it gets reset -- which is tricky if simpletest dies (can happen, we are testing). I think I will set CURLOPT_USERAGENT to "simpletest $db_prefix" and getting the handling of this written to settings.php at form time and adding something which indicates it's there. Something like:
should go to settings.php.
Comment #11
chx CreditAttribution: chx commentedBeware, this patch litters your database as there is no cleanup. Also it does not work -- but why? Add
to settings.php
Edit: "Does not work" mean, the user created (always uid 3) does not get its roles. I still have to figure out why.
Comment #12
chx CreditAttribution: chx commentedHere we go. I have added a few more lines of code from install.php and made sure the useragent-based prefix is safe. It seems working.
Comment #13
chx CreditAttribution: chx commentedOh, and the settings.php part:
we obviously need to work on code to make sure it's there.
Comment #14
chx CreditAttribution: chx commentedReroll.
Comment #15
chx CreditAttribution: chx commentedAnother reroll against HEAD. Also, this adds a safeguard before dropping tables.
Comment #16
boombatower CreditAttribution: boombatower commentedLooks great. Very nice first step.
The way you use the useragent to pass the db_prefix to allow for multiple different test sessions was very clever.
Comment #17
chx CreditAttribution: chx commentedPer test.
Comment #18
chx CreditAttribution: chx commentedNow with bonus whining.
Comment #19
boombatower CreditAttribution: boombatower commentedThis appears to work great.
This patch means that the db will be flushed after each test method is called. Which is exactly what we have been needing.
This patch also works for multiple testing sessions running simultaneously.
Great work chx!
Note: leaving this for further testing, review, and comments.
Comment #20
Rok Žlender CreditAttribution: Rok Žlender commentedPatch works tables are created, used and removed after every test case. I have 2 problems with this patch:
1) page node creation tests I tried don't finish successfully probably this is the reason. I get this "Sorry, unrecognized username or password. Have you forgotten your password?" right after attempt to login simpletest user
2) building and destroying new tables before and after every 2 line unit test might be a bit of an overkill not sure what we can do about it.
Comment #21
dmitrig01 CreditAttribution: dmitrig01 commentedI've read through the patch and it looks GREAT.
+(500500)
Comment #22
pwolanin CreditAttribution: pwolanin commentedlooks good, but haven't actually tested it yet.
Also, is there any security concern with this USER_AGENT method? What happens if I access a site remotely with a browser where I can set HTTP_USER_AGENT- can I get Drupal to run a new install with prefixed tables?
Comment #23
boombatower CreditAttribution: boombatower commented@pwolanin: Good point. I know you can get an extension to do that in Firefox and I believe Konqueror lets you do it by default.
Probably need to generate some sort of key when SimpleTest is installed then pass that along with db_prefix to ensure it is coming from SimpleTest.
@Rok Žlender: Yea that could be an issue. One thought I had was make a different test case that unit tests extend since allot of the DrupalTestCase functionality is for function browser based tests.
If we create a new test case that could fix the issue.
Comment #24
pwolanin CreditAttribution: pwolanin commented@boombatower - one suggestion for a key that can be checked in settings.php: pass (in the query string?) the hash of the drupal private key with the simpletest prefix. Or alternately (since I guess this is all running before bootstrap) on install write such a key private key into settings.php?
Comment #25
boombatower CreditAttribution: boombatower commentedThis patch require a key to set the prefix in settings.php.
This will prevent the situation which pwolanin described.
I have tested and seems to work.
Comment #26
pwolanin CreditAttribution: pwolanin commented@boombatower - something doesn't look right about that code - you are going to set
$GLOBALS["simpletest_ua_key"]
every time settings.php is parsed?Comment #27
boombatower CreditAttribution: boombatower commented@pwolanin: the key needs to be there when SimpleTest starts the chain...which we have no way of knowing before hand...and settings.php must have same key so it needs to be there.
Limits to that yes.
Comment #28
boombatower CreditAttribution: boombatower commentedCommitted.
Comment #29
Rok Žlender CreditAttribution: Rok Žlender commentedI ci a small patch that fixes problems with clean urls. http://drupal.org/cvs?commit=107508
Comment #30
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.