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.
I have made a patch that introduces Simpletest tests for the Image CAPTCHA module.
This required an small tweak on the base (abstract) CaptchaBaseWebTestCase::setUp()
method, so that this very same class can be subclassed to implement tests for other modules.
The introduced tests only check that the source image URL is being generated correctly by actually trying to fetch it. Checking that an image is correct is a tough task, so the test just check if any data were generated at all. This helped to confirm the #2462479: Captcha - No image displayed bug and fix.
Comment | File | Size | Author |
---|---|---|---|
#19 | captcha-7.x-1.x-image_captcha_simpletest-2468539-19.patch | 3.12 KB | AohRveTPV |
#15 | captcha-7.x-1.x-image_captcha_simpletest-2468539-15.patch | 3.12 KB | AohRveTPV |
#13 | interdiff.txt | 1.92 KB | flaviovs |
#13 | captcha-7.x-1.x-image_captcha_simpletest-2468539-13.patch | 3.12 KB | flaviovs |
#9 | interdiff.txt | 2.11 KB | AohRveTPV |
Comments
Comment #1
flaviovs CreditAttribution: flaviovs commentedComment #3
AohRveTPV CreditAttribution: AohRveTPV commentedVery cool.
The
func_get_args()
is a little different from what seems to be used throughout core:I wonder if it might be better to use that code for consistency. (I don't know if you got your
func_get_args()
from somewhere?) A difference with the code in the patch is the patch will allow a module to be passed as a string for the first argument.Comment #4
flaviovs CreditAttribution: flaviovs commentedLest try again with some fixes to please testbot:
Comment #6
flaviovs CreditAttribution: flaviovs commented@AohRveTPV,
I understand your point. Here is a final patch that implement the change more concisely (using the pattern you suggested).
BTW, I think also I fixed the issues that prevented testbot to run the tests as expected. Now, the test is doing the right thing, though it won't pass past testbot until the fix in #2462479: Captcha - No image displayed is tested and committed.
Comment #7
flaviovs CreditAttribution: flaviovs commentedPlease review.
Comment #9
AohRveTPV CreditAttribution: AohRveTPV commented- Shorten function short description to <=80 characters per coding standards.
- Make few other changes to comply with coding standards.
- Remove now-incorrect
@see
tags.Comment #11
AohRveTPV CreditAttribution: AohRveTPV commentedNot sure why
assertNonEmptyImage()
is public instead of protected? I am not good at OOP so maybe I am missing why it should be public.Otherwise, patch in #9 looks good to me. Having these tests would be much better than not.
Comment #12
flaviovs CreditAttribution: flaviovs commentedYep,
assertNonEmptyImage()
was originally atest*()
function, so that's why it is (forgotten) public. It should be protected for sure.BTW, there are other improvements related to the change I mentioned. The assert function is simply doing too many things. As an assert function, it should not include any test code in the "act" test phase, but it currently does. I will send an improved patch in a couple hours or so.
Comment #13
flaviovs CreditAttribution: flaviovs commentedHere it goes.
assertNonEmptyImage()
togetImageCaptchaForm()
. This change makes the methods much more flexible for adding new tests in the future.test*()
methods "protected"Comment #15
AohRveTPV CreditAttribution: AohRveTPV commentedChange to one blank line between functions for consistency.
Two lines were used between functions in two places. If it was intentional, please disregard this patch.
Comment #17
AohRveTPV CreditAttribution: AohRveTPV commentedComment #18
wundo CreditAttribution: wundo commentedComment #19
AohRveTPV CreditAttribution: AohRveTPV commentedChange imperative function short descriptions to third-person singular per coding standards.
Also, I think it would be clearer if the functions read from top to bottom, but I did not make this subjective change.
One test fail expected, due to #2462479: Captcha - No image displayed.
Comment #21
AohRveTPV CreditAttribution: AohRveTPV commentedExpected fail.
Comment #23
wundo CreditAttribution: wundo commentedNow that the other issue is committed, re-testing
Comment #25
wundo CreditAttribution: wundo commented