In our planning discussion for the "Testing part 1: Intro to Testing" session in Szeged, webchick suggested using the tests from the node module as examples, because unlike other tests they do not require much additional understanding (underlying structure, security risks, rarely-used features, etc), every one understands what a posting a page should do.
Since node.test will get a lot of attention, and will be used as an example during the presentation, I started doing some clean-up. Some of the changes are purely a matter of style (correct formatting for comments, etc), but some of them are about using the SimpleTest methods correctly, like:
$edit['title'] = $this->randomName(4, 'title_');
instead of
$edit['title'] = "title_" . $this->randomName(4);
I'm setting the issues status to "code needs work" not only so that people look at my suggested changes, but so that other people can add their own and we can get node.test to be perfect.
Comment | File | Size | Author |
---|---|---|---|
#20 | node.test-cleanup.patch | 19.22 KB | boombatower |
#18 | node.test-cleanup.patch | 19.12 KB | boombatower |
#17 | node.test-cleanup.patch | 19.51 KB | mikey_p |
#17 | Testing | head.dev-2.jpg | 35.87 KB | mikey_p |
#16 | node.test-cleanup.patch | 19.52 KB | mikey_p |
Comments
Comment #1
floretan CreditAttribution: floretan commentedSome further points that could be improved:
- Change the "Page" tests into generic node tests using the drupalCreateContentType() method.
- Change the sample text about "UberBabes" to something more... hmmm... generic.
- Take care of the "TODO" in testPageView().
I'm writing this from a McDonald's at the Locarno Film Festival, before going back into a little mountain village, so I won't be able to respond for a couple of days.
Comment #2
boombatower CreditAttribution: boombatower commentedA prefix as in:
Isn't even needed or preferred it would be better to just do
I will try and take a look at this in more detailed and make changes as I see fit later in the week.
Comment #3
boombatower CreditAttribution: boombatower commentedWhile were are in cleanup mode I've made another issue: #295864: SimpleTest: Change randomName() method to randomString()
Comment #4
boombatower CreditAttribution: boombatower commentedWorking on this.
Comment #5
boombatower CreditAttribution: boombatower commentedTook care are a ton of formatting, new API refactoring, poor comments, dumb assertions, etc.
The tests still use page content type, but that can be the next change, if necessary. The tests, as are they sit, are much more worthy to be used as an example.
All node test still pass.
Patch requires #299186: SimpleTest: assertFieldByXPath does not work for selects or textareas with value to work.
Comment #6
boombatower CreditAttribution: boombatower commentedStill applies.
Comment #7
maartenvg CreditAttribution: maartenvg commentedNo long applies.
Comment #8
boombatower CreditAttribution: boombatower commentedWish these patches wouldn't be overlooked so long. Been ready since August 23.
I'll work on re-roll.
Comment #9
boombatower CreditAttribution: boombatower commentedOk..I've re-rolled patch.
Note it still requires: #299186: SimpleTest: assertFieldByXPath does not work for selects or textareas with value.
Ran test suite...all passes!
Comment #10
mikey_p CreditAttribution: mikey_p commentedWith #299186: SimpleTest: assertFieldByXPath does not work for selects or textareas with value All tests pass.
5589 passes, 0 fails, 0 exceptions
I didn't spend alot of time looking at the before, but this definitely cleans up a few things.
A few points, in callNodeTeaser() $expectedTeaser, should probably just be $expected, as in testFirstSentenceQuestion().
Also Line 352, 'consistency,' should probably just be 'presence.'
Other than that, looks good.
Comment #11
mikey_p CreditAttribution: mikey_p commentedComment #12
mikey_p CreditAttribution: mikey_p commentedFigured I might as well roll a patch while I'm at it.
Comment #13
boombatower CreditAttribution: boombatower commentedEssentially the same as my previous patch and it has had two sets of eyes look at it.
Comment #14
webchickI realize this wasn't touched directly by your patch, but that should be done on one line.
+1 for getting rid of that UberBabe stuff, but I'm not sure if the Lorem Ipsum replacement handles the actual edge case that was described. Any idea what that that edge case in fact is? I'd like to see it better documented in the testFirstSentenceQuestion() test above.
Probably edit "tab" found?
That doesn't really make sense. Nodes that are found in the database aren't booleans. In fact, if this test is passing, it probably means we need to fix assertTrue().
Everywhere else it seems this is called $web_user. Let's be consistent.
Comment does not match code.
Comment #15
chx CreditAttribution: chx commentedActually running assertTrue on a $node makes perfect sense. As assertTrue casts to boolean whatever is passed to it, the only case it can fail if that node_load returns FALSE and the only way that can happen is if the node is not in the DB. In this case, think of assertTrue as "assertNotFalse".
Comment #16
mikey_p CreditAttribution: mikey_p commentedNow with 30% more screenshots!!
Reworked most of the descriptions, see screenshot below.
'Edit task..' => 'Edit tab...'
$test_user => $web_user
Re: out of place comment, in code, that reads
No idea about the above edge case for node_teaser().
Comment #17
mikey_p CreditAttribution: mikey_p commentedJust realized that Node preview test doesn't actually create a node, edited description, see screenshot.
Comment #18
boombatower CreditAttribution: boombatower commentedHad
I removed extra $.
I diffed that patches...changes look good.
Comment #19
webchickYeah, except:
That comment still needs clarifying. CVS annotate should do the trick.
Also, I saw this:
NULL? I don't find that more legible than - $this->drupalPost("node/$node->nid/edit", $edit, t('Save'));
Comment #20
boombatower CreditAttribution: boombatower commentedReason for NULL being that we assure that the link clicked work, also 1 less page request, and tests internal framework. As that is the actual flow.
click link -> type values -> submit page
not:
click link -> reload page -> type values -> submit page.
Found original issue and added to comment.
Comment #21
webchickExcellent. Thanks, committed.
I also added a little comment above that drupalPost line.
Comment #22
c960657 CreditAttribution: c960657 commentedAfter this has been applied, I get two failed tests:
Node edit:
24 passes, 1 fail, 0 exceptions
Body field displayed. Browser node.test 288 PageEditTestCase->testPageEdit()
Node preview:
18 passes, 1 fail, 0 exceptions
Body field displayed. Browser node.test 341 PagePreviewTestCase->testPagePreview()
So far I haven't investigated further why they fail.
Comment #23
boombatower CreditAttribution: boombatower commented@c960657: did you apply only this patch? If so that is the problem. This patch requires another, and both have been committed. Do you still get issue when you update to HEAD?
Comment #24
c960657 CreditAttribution: c960657 commentedI still get failed tests with HEAD and a clean database.
It looks as if there is a problem with DrupalWebTestCase::assertFieldByXPath(). It does find the textarea element, but isset($field[0]) returns false.
I am no SimpleXML expert (actually I don't like SimpleXML, because there is far to much magic going on for my taste), but making the following change fixes the problem:
I am using PHP 5.2.0-8+etch11 (Debian) with libxml 2.6.27.
Comment #25
boombatower CreditAttribution: boombatower commentedI'll look into when I get home.
Comment #26
boombatower CreditAttribution: boombatower commentedhmmm both mine pass. open separate issue if this persists.
Comment #27
c960657 CreditAttribution: c960657 commentedThe assertFieldByXPath() problem is now filed as #310113: SimpleTest: assertFieldByXPath() doesn't work in some environments.
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.