Closed (fixed)
Project:
SimpleTest
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
26 Dec 2007 at 04:05 UTC
Updated:
14 Jan 2008 at 09:14 UTC
Jump to comment: Most recent file
The main work for this task is to write a small suite of tests to check the basic functionality of the Forum module.
Suggested tests:
1. admin/content/forum/add/container Add a forum container.
2. admin/content/forum/add/forum Add a forum.
3. admin/content/taxonomy/edit/vocabulary/# Edit the forum vocabulary.
4. node/add/forum Create a new forum topic.
5. node/add/forum Attempt to add a forum topic to a container, rather than a forum (this should not work).
6. node/#/edit Move a forum topic from one forum to another.
7. node/#/edit Move a forum topic from one forum to another, leaving a shadow copy (confirm existence of shadow copy).
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | forum_module.test.txt | 12.77 KB | Smartys-1 |
| #19 | forum_module.test.txt | 13.58 KB | Smartys-1 |
| #17 | forum_module.test.txt | 13.61 KB | Smartys-1 |
| #14 | forum_module.test.txt | 14.08 KB | Smartys-1 |
| #13 | forum_module.test.txt | 14.08 KB | Smartys-1 |
Comments
Comment #1
pwolanin commentedGHOP issue: http://code.google.com/p/google-highly-open-participation-drupal/issues/...
Comment #2
Smartys-1 commentedOK, I'm attaching the code for the tests.
One note: there is a lot of repeated code for, for example, submitting a form and creating forums/containers. The reason is that 4 of the tests require a forum to work, 2 others require a container, and I couldn't find a function that would create the forum/container for me. If I missed the function, I'll be more than happy to take some of the repetition out of my code. :)
Comment #3
pwolanin commentedOk - looks like a good start. However - the 7 tests don't actually have to be separate DrupalTestCase objects - you can have all of this together in one "test" as long as these 7 pieces of functionality are tested. Or group them in 2 or 3 tests as seems most logical.
Also, if you still have repeated code, you could play the trick I used here: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/simpletest/...
The latter tests extend the first object which defines common method in addition to those already in DrupalTestCase.
Comment #4
Smartys-1 commentedOoh, interesting, thanks a lot :)
Comment #5
Smartys-1 commentedOK, I've reduced it down to 3 classes, the last of which extends the first. The size has been cut quite a bit as a result. :)
Comment #6
pwolanin commentedok - looking better.
A couple minor suggestions to start-
I'd rename AddForumTest to something like DrupalForumTestCase.
This should have no "testX" methods, since I think they will get run twice if a later object extends it. It should only have common methods like your function createForum().
Also, the second object should extend DrupalForumTestCase also, this way you can omit:
since the setup function will run.
Finally - minor code style issue - don't have any white space between the function name and parens in the function definition.
Comment #7
Smartys-1 commentedI actually don't think the methods would be run twice unless you were to redeclare the function in the subclass and call the parent function in there. Otherwise, simpletest would be showing duplicate tests for you to choose from, which it doesn't.
In any case, here's the code with the changes made. The one thing to note here is that the new class, DrupalForumTestCase, needed a get_info function even though there are no tests in it. So, I just clarified what it is a little bit.
Comment #8
pwolanin commentedok- obviously I'm not paying attention. You're right about the tests not running twice. Sorry.
How about merging the first two objects together so there is no get_info() that doesn't run an actual test?
Comment #9
Smartys-1 commentedI actually think we're wrong. I just made the changes and suddenly my number of passes jumped. Looking at the list of passes, it seems like the first two tests (the ones in the class that is extended) are being run in every class.
Comment #10
pwolanin commentedtesting this now - it's weird with the menu tests, they only run once, but if I add a trivial additional test it runs multiple times.
Comment #11
pwolanin commentedoh wait - I see - I used the same function name in both classes in menu_module.test. I'm too clever for myself...
Comment #12
pwolanin commentedOk, a minor problem with the tests for the expected text like:
This will break if localization is turned on. You need to write it with t() mimicking the exact form from forum module like from modules/forum/forum.admin.inc line 90:
So your code needs to be like:
There are several spots with this problem.
Comment #13
Smartys-1 commentedAlright, thanks :)
Here's a corrected version
Comment #14
Smartys-1 commentedAnd a new copy to correct a small capitalization error pwolanin found.
Comment #15
pwolanin commentedLooking better - all tests pass.
Comment #16
pwolanin commentedsome code style issues still - for example an extra space in array declarations like:
array ()which should bearray()as before (http://drupal.org/node/201134#comment-669753) try running coder on this.
also, some code could be made more compact, like this:
could be rewritten as something much simpler like:
There's probably no reason to use db_rewrite_sql for simpletests.
There are a couple cases of this.
Also - you generally want to write all query strings with double quotes ( " not ' ) since you need to wrap single qoues around %s placeholders.
Comment #17
Smartys-1 commentedThe coder module seems to not like me, it still says the code looks perfectly fine. :/
I've corrected the parenthesis spacing and made those queries more compact.
Comment #18
pwolanin commentedlooks better- though a couple code comments like:
that should be changed since there is no looping. Maybe just:
Comment #19
Smartys-1 commentedWhoops, I KNEW there was something I forgot to change :P
I changed it for one of the loops and then didn't for the others. New version, coming right up:
Comment #20
pwolanin commentedok - looks very close. A suggestion after reviewing the code again.
This part:
could probably be simplified to a single API call like:
rather than re-testing the thing we tested before. It doesn't matter much, but as it is now will give a redundant failure message.
Comment #21
Smartys-1 commentedFair enough :)
New version with the change
Comment #22
pwolanin commentedI don't see any other problems - good job.
Comment #23
Rok Žlender commentedThanks for you great work Smartys and pwolanin. Committed.
Comment #24
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.