API page: http://api.drupal.org/api/drupal/core%21modules%21simpletest%21lib%21Dru...
Enter a descriptive title (above) relating to WebTestBase::assertText, then describe the problem you have found:
Problem/Motivation
It says 'The text version is the equivalent of what a user would see when viewing through a web browser. '. This is not true, or at least after a user submits a form, what user just input could be seen from browser, but user's input won't be seen from 'The text', meaning user's input won't be fond by assertText, event they could be seen.
Steps to reproduce
- Install the latest Drupal 8.x using the standard profile and built-in English language.
- Enable Language, and Interface Translation module.
- Go to '/admin/config/regional/language', click 'Add language', and choose 'German'.
- Go to '/admin/config/regional/translate/translate', input 'String contains'-- 'Annnn', 'Translation language'--German, 'Search in'--Both.., Click filter.
We can see that while no result shows this string, string 'Annnn' is still in this input field and apparently we can see it, but in this context, when we run test code, $this->assertText('Annnn', t('Test will fail'));
will give false. And $this->assertNoText('Annnn', t('Test will pass'));
will give true. So, I think this problem also involves assertNoText
See http://api.drupal.org/api/drupal/core%21modules%21locale%21lib%21Drupal%... for real instance. I'm working on this test. The original author has fond this issue, but didn't bring it in
381. // assertText() seems to remove the input field where $name always could be
382. // found, so this is not a false assert. See how assertNoText succeeds
383. // later.
384. $this->assertText($name, t('Search found the string.'));
Proposed resolution
The following changes should be applied to the documentation of assertText/assertNoText. Suggestions of comment #1 include:
- The documentation needs to point out that all tags are removed, including the attributes of some html elements
- Add a reference to assertRaw/assertNoRaw, which allows to match to all html,including the attributes
Comment | File | Size | Author |
---|---|---|---|
#21 | interdiff-21.txt | 480 bytes | joshi.rohit100 |
#21 | asserttext_assertnotext-1882788-21.patch | 2.08 KB | joshi.rohit100 |
#18 | asserttext_assertnotext-1882788-18.patch | 2.4 KB | keopx |
#18 | interdiff-asserttext_assertnotext-1882788-15-18.txt | 780 bytes | keopx |
#15 | asserttext_assertnotext-1882788-15.patch | 2.35 KB | jabberwooki |
Comments
Comment #1
jhodgdonThanks for reporting this! I think that, as you've reported, it's a documentation issue:
- assertText/assertNoText do not really show you all the text that a person would see browsing to a page. For instance, form input is a value attribute of an HTML tag, and all tags are stripped out (including attributes), so assertText will not find that. The documentation needs to explain this, and it is currently wrong.
- I think there should be an @see link to assertRaw/assertNoRaw, which you can use for your purposes in this case, since it allows you to match against the full raw HTML (including value attributes of tags).
Comment #2
smiletrl CreditAttribution: smiletrl commentedHi, Currently, assertText works good for me:) And I agree that there should be an @see link to assertRaw/assertNoRaw, which would help the clarification much.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI think I ran into a similar instance of this "bug" over at #1998482: Undefined index: en in locale_requirements() (line 303 of core/modules/locale/locale.install).
Comment #4
gauravkhambhala CreditAttribution: gauravkhambhala commentedAPI Page: http://api.drupal.org/api/drupal/core%21modules%21simpletest%21lib%21Dru... can not be found.
Could you help me get the correct link?
Comment #5
jhodgdonWhat happened is that this issue was filed 2 years ago and the method moved to a different class. So, this situation of a link in an issue to api.drupal.org not working is fairly common in Drupal 8 development, especially for issues as old as this.
To find the new class/method: Go to api.drupal.org and search for "assertText" in Drupal 8. You will find several results; two of them are for methods called assertText and others are for methods called assertText* (with a suffix). Click through to the two methods that are actually called assertText and see which one has the problem; you'll find that it is AssertContentTrait::assertText().
Also note that assertNoText needs a patch; that should be on the same class/trait.
Comment #6
roderikTagging for Amsterdam. Issue summary needs update with what is the actual problem, which jhodgdon explained in #1 - then fixing it (documenting things better).
Comment #7
pieterjd CreditAttribution: pieterjd commentedAs I am attending the mentored sprint session at DrupalCon Amsterdam, I added a proposed resolution section to the original issue post.
Comment #8
pieterjd CreditAttribution: pieterjd commentedComment #9
oenie CreditAttribution: oenie commentedfixing the amsterdam sprint tag to amsterdam2014
Comment #10
jabberwooki CreditAttribution: jabberwooki commentedFirst patch proposal from the Drupal Dev Days Montpellier 2015.
Hope this might help.
Comment #11
jhodgdonGreat start, thanks! I have a few suggestions:
This is factually correct and gives the information that we need, great! But it needs a little editing for English grammar/pronunciation/style... and maybe it is a bit confusing to say the HTML tags are stripped... Maybe we need to change the first line too, so instead of saying "text version" it is clearer?
How about:
Passes if the page (with HTML stripped) contains the text.
Note that stripping HTML tags also removes their attributes, such as the values of text fields.
[I think we can omit the text that says "use assertRaw..." because we have the @see below]
We need to include the namespaced class name here, not just reference the method name.
Same as in assertText.
Needs namespace and class here too.
Comment #12
jabberwooki CreditAttribution: jabberwooki commentedI'm new to namespace concept.
In our current task, does it mean that I have to replace
@see assertRaw()
with
@see core\modules\simpletest\src\AssertContentTrait\assertRaw()
?
Comment #13
jhodgdonIt's actually:
@see \Drupal\simpletest\AssertContentTrait::assertRaw()
Read about namespaces here:
https://api.drupal.org/api/drupal/core!modules!system!core.api.php/group...
(if you need background information, try some of the links in that text, such as the first one that takes you to PHP.net.
Comment #14
jhodgdonYou can find the namespace for a class at the top of the file in a line like
But in documentation we prefix this with a \
and the method should be separated from the class name with a ::
So in summary, the method assertRaw() on AssertContentTrait would look like:
@see \Drupal\simpletest\AssertContentTrait::assertRaw()
Hope this helps...
Comment #15
jabberwooki CreditAttribution: jabberwooki commented@jhodgdon All modifications, as proposed in your comment #11 are done and I've generated the corresponding patch.
Thank you for your patience and your advices to a newbie.
Just a last question.
As mentionned in the link about namespaces you gave, shouldn't the @see mention be written down as follows ?
@see \Drupal\Core\simpletest\AssertContentTrait::assertRaw()
that is, whith ...\Core\..., the simpletest module belonging to Core ?
Comment #16
jhodgdonNo. Take a look at the namespace line at the top of this AssertContentTrait file. ;)
Anyway, the patch looks pretty good! A few things to fix:
This line is incomplete.
Grammar: Should be "doesn't contain"
Comment #17
keopxComment #18
keopxComment #19
jhodgdonLooks good to me, thanks very much!
Comment #20
xjmThanks everyone. Just one thing looks out of place here:
It looks like we're adding an @see on this method to itself?
Comment #21
joshi.rohit100Comment #22
keopxComment #24
xjmThis issue only changes documentation, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x. Thanks!
Comment #25
David_Rothstein CreditAttribution: David_Rothstein commentedComment #29
stefan.r CreditAttribution: stefan.r commentedTagging the backport to 7.x as a novice task