assertText() and assertNoText() allow me to check if some text is present or not.
How about checking if the text is unique or present more than once?

Here is a patch which allow you to do that.

    $this->drupalGet('some/path');
    $this->assertUniqueText('forum');
    $this->assertNoUniqueText('download');

If this sounds interesting, please change the status to "patch need review".

Thank you.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

roychri’s picture

FileSize
3.05 KB
RobLoach’s picture

Status: Active » Needs work

Well done. It might be good to provide a test that actually uses this assertion though, so we're not just adding stuff that's never used. One use case that might be fitting is a test on form_clean_id which would check to see if multiple IDs of the same name become unique when being added.

roychri’s picture

FileSize
5.53 KB

Thank you Rob,

Here is a new patch with a test.
Maybe there is a better way to do that test. A simpler way?
Improvement Suggestions/Recommendation are welcome.

boombatower’s picture

Status: Needs work » Needs review

#2: dealt with, lets see what bot says.

Dries’s picture

I wonder if we can think of a better real-world test. This test doesn't seem very useful. Do we have a _real_ use case for this function?

webchick’s picture

webchick’s picture

Status: Needs review » Needs work

A couple minor things:
- Comments should wrap at 80 characters. Also, when doing PHPDoc comments, they should be done like this:

/**
 * One sentence summary, < 80 characters.
 *
 * The rest of the details. This can be as long as you want, and
 * span many lines.
 * ...
 */
function...

- If assertUniqueTextHelper isn't intended to be called, how about rename it to _uniqueTextHelper or similar? Right now in IDEs and whatnot it would come up and look like another assertion function which is confusing.

- This should be drupalGet (weird; how is that not generating a fatal error?):

+    $this->drupalget('form_test/form_clean_id');

- +function form_test_form_clean_id_page() { and +function form_test_test_form(&$form_state) { both need a one-liner of PHPDoc to explain what they do.

boombatower’s picture

Just make assertUniqueTextHelper private as that is one of the nice things about OO.

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
5.57 KB

Fix code style. Add documentation to the mock module functions.

We don't use "_" conventions for determining visibility, but rather proper private/protected/public modifiers. In that case, assertUniqueTextHelper() is modelled against assertTextHelper(), which has exactly the same help text. We can't make those private, because they could be useful for a subclass. It is not dangerous to call those functions directly, it's just not recommended.

Damien Tournoud’s picture

And fix a drupalget() -> drupalGet() and some whitespace nitpicking.

webchick’s picture

Status: Needs review » Fixed

Ok, cool. There are some other things about this that I'd like to see fixed (the comments are SHOUTING AT ME, for instance) but what's there is consistent with the rest of DWTC so out of scope for this patch.

Committed to HEAD. Thanks!

roychri’s picture

My very first patch committed to HEAD! I am so excited :)

Thanks all for reviewing/fixing things up.

Drupal has a great community and I am proud to be part of it.

webchick’s picture

Awww. :) Yay!! :D

May it be the first of many more. :)

chx’s picture

Status: Fixed » Needs work

This is wrong because we do not change the message based on the assert failing or not. If you read "found once" failed then you know it's not been found once. If you read "found more than once" and a FAIL what does that mean?

chx’s picture

Status: Needs work » Fixed

disregard me. i misunderstood.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.