API page: https://api.drupal.org/api/drupal/modules!simpletest!drupal_web_test_cas...

Enter a descriptive title (above) relating to protected function DrupalWebTestCase::assertFieldById, then describe the problem you have found:

The docs for assertFieldById() don't say what to pass to $value to skip the checking of the value. I presume this is the same for other assertFieldFOO() methods.

The docs page on assertions at https://drupal.org/node/265828 says to pass in an empty string, but this is wrong.

If you go poking around in https://api.drupal.org/api/drupal/modules!simpletest!drupal_web_test_cas... you can see that it's in fact NULL that must be passed for this. I've confirmed this works.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Novice, +Needs backport to D7

Thanks! This needs to be fixed in Drupal 8 on:
https://api.drupal.org/api/drupal/core!modules!simpletest!lib!Drupal!sim...
first (and on related field assertion functions), and then backported to Drupal 7.

Probably a good Novice project?

yaworsk’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
0 bytes

Attached a patch - wasn't sure if the function signature should be changed from '' to NULL or it was just the preceding comment.

yaworsk’s picture

opps, proper patch attached...

joachim’s picture

Status: Needs review » Needs work

This is purely a documentation issue, so the signature of the function should not be changed.

Also, what needs to be documented here is not what happens when you omit the parameter, but what you should pass in to have the assertion skip the checking of the value.

yaworsk’s picture

opps. thanks for the clarification. Does the new comment make sense?

joachim’s picture

Not quite, sorry.

This isn't about checking for an empty value.

It's about using assertFieldById() when you want to skip the checking of the value -- you ONLY want to check the field exists, and you don't care about the value at all.

yaworsk’s picture

gotcha - no need to apologize... rather than recreating patches, what do you think of this? pending confirmation, i'll redo the patch:

Value of the field to assert. You may pass in NULL to skip checking the actual value while still checking that the field exists.

joachim’s picture

That's perfect :)

yaworsk’s picture

awesome. thanks for the help. patch attached.

joachim’s picture

Status: Needs work » Needs review

Thanks for the patch!

Let's set this to needs review so the testbot checks it applies.

yaworsk’s picture

opps, didn't realize we had changed the status...

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! The documentation change looks good.

But if we're fixing up the docs for this function, could we also fix "id" and "Id" to be "ID"? The problem is that "id" in English is a psychological term (ego, superego, id) and to say "identifier" you need to have two caps ID. That appears several times in this function's documentation.

Also, this issue is about "assertFieldById and friends". So it seems like it would be good to add this to the documentation of:
- assertFieldByXPath
- assertFieldByName

And the assertNoField* methods documentation should also be updated... that's a bit more complicated. It looks like what happens on those methods is that if you don't provide a value, you are asserting that the field itself doesn't exist, and if you do provide a value, you are asserting either that the field doesn't exist or that the value doesn't match.

yaworsk’s picture

no problem, i'll take a stab at those pieces as well...

paulh’s picture

Assigned: Unassigned » paulh
FileSize
9.02 KB

This just covers the assertField* functions and id cleanup. I'll follow this with another patch that includes the assertNoField* functions tomorrow.

jhodgdon’s picture

Hm. We regularly use "nid" and "uid" in docs (sigh) without the caps. I don't really think we should suddenly be changing them to "NID" and "UID", because they're like that all over the place, and the database field names are lower-case, as are the object property names.

I really just want "ID" to always be capitalized.

And in places like this:

    *   The following defaults are provided:
    *   - label: Random string.
-   *   - id: Random string.
+   *   - ID: Random string.

This is giving defaults for keys/values in an array. I do not think the key name is changing to "ID", so this also shouldn't be changed. Similarly:

    *   Name of field or message property to assert. Examples: subject, body,
-   *   id, ...
+   *   ID, ...
paulh’s picture

Ok, will do.

paulh’s picture

Status: Needs work » Needs review
FileSize
7.64 KB

Full patch covering the updated @param $value documentation for assertField* and assertNoField* functions, as well as the requested id capitalisation cleanup.

ToDo: Needs backport to D7

jhodgdon’s picture

Status: Needs review » Needs work

Good work!

So... One thing I thought was a bit confusing. In assertNoFieldByXPath, it says:

+   *   (optional) Value of the field to assert. Asserts that the provided value
+   *   doesn't match, or that the field itself doesn't exist. If there is no
+   *   value provided, this is also asserting that the field doesn't exist.

My read of the code says that if you provide a value, you are asserting that either the field doesn't exist or the value isn't found (which is what your text says, good). But if value isn't provide, you are asserting just that the field doesn't exist, and your text says "is also asserting" -- should say "instead", right?

Then the same thing applies for assertNoFieldByName and assertNoFieldById.

Then one other thing. The ByName and ById functions, for some reason ??? have defaults of $value = '' instead of $value = NULL. This value is passed directly into the ByXpath functions, bypassing the default of NULL that is in those functions. So I think we need to make that distinction clear in the docs. In the ByXpath functions, if you just omit $value, you will not be checking the field value. But in the other functions, if you omit $value you will be checking that the field value is explicitly ''. If I'm reading the code correctly, that is? Check my logic...

Anyway, I think the "if there is no value provided" wording may need to be changed to "if you pass in NULL". Please check on that.

The rest (the "ID" fixes) looks great, thanks!

paulh’s picture

Status: Needs work » Needs review
FileSize
7.78 KB

I agree with your logic conclusion and I've got to admit, I found the '' and NULL discrepancy confusing. Note also that assertNoFieldByName() has a $value = '' and assertFieldByName() has a $value = NULL.

I think I've got it right now. Thanks for your help @jhodgdon.

jhodgdon’s picture

Status: Needs review » Needs work

OK... I think most of this is correct now... but I'm not sure it is quite as clear as it could be? For instance:

+   *   (optional) Value of the field to assert. You may pass in NULL to skip
+   *   checking the actual value, while still checking that the field exists.

This seems very clear to me, and correct.

+   *   (optional) Value of the field to assert. Asserts that the provided value
+   *   doesn't match, or that the field itself doesn't exist. Providing a NULL
+   *   value or not providing a value at all, asserts that the field doesn't
+   *   exist.

This doesn't seem as clear. Would it be better to say something like "A field value to check: the assertion will pass either if the field doesn't exist, or if it exists but the field's value doesn't match the provided value. You may pass in NULL (default) to skip the value check; in this case, the assertion will only pass if the field doesn't exist." ?

I also think that some of the "No" methods got the documentation a bit backwards, such as:

+   *   Value of the field to assert. Asserts that the provided value doesn't
+   *   match, or that the field itself doesn't exist. Providing a NULL value
+   *   asserts that the field doesn't exist. Note that if no value is provided,
+   *   this asserts that the field value is ''.

because in this case, it's asserting that the field value is *not* '', right?

Jalandhar’s picture

Assigned: paulh » Unassigned
Status: Needs work » Needs review
FileSize
7.86 KB
1.64 KB

Updating the patch with the changes mentioned in #20. Please review.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Now it all looks good to me. Some of the wrapping could be a little closer to 80 characters, and these functions are weird about the '' vs. NULL (we should probably file a separate issue on that), but I think the docs are clear and match the current function behavior. Good work!

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

Hm... I applied the patch and looked over these docs one more time to make sure.

I think we should do one more pass:

a) We should fix the wrapping in assertNoFieldByXPath (as close to 80 characters as possible)

b) assertFieldById should have the note about '' added to it.

c) In assertFieldByXPath (and other functions where NULL is the default), we should say "... pass in NULL (default)... " instead of just "pass in NULL" to make that clear. This is only done on some of the functions, not all.

d) Documentation in a @param statement should only pertain to that parameter. Documentation that pertains to the function as a whole should go outside the @param. So ... There is wording in assertFieldByXPath that is good:

   * @param $value
   *   (optional) Value of the field to assert. You may pass in NULL to skip
   *   checking the actual value, while still checking that the field exists.

But the way it is worded in assertNoFieldByXPath is bleeding into talking about the behavior of the function as a whole... The part about "the assertion will pass either if the field doesn't exist, or if it exists but the field's value doesn't match the provided value" is documenting the behavior of the method, and should be outside the @param. Then the part about "you may pass in NULL" can go in the @param, but it should probably be worded more like the assertField method, something like "You may pass in NULL to skip checking the actual value, and therefore only checking that the field doesn't exist." Same applies to the other assertNoField* methods.

e) And really... Maybe we should just suggest that people use assertField and assertNoField to check the existence without checking the value?

lokapujya’s picture

Status: Needs review » Needs work

The last submitted patch, 24: 2039449-24.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
7.87 KB
4.92 KB

retry.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks for the new patch! This is mostly great. A few small things to fix:

a) Our documentation standards state that every documentation block must start with a one-line, up-to-80-character summary. Additional documentation should be in following paragraphs.

So, in assertNoFieldByXPath:

   /**
-   * Asserts that a field does not exist in the current page by the given XPath.
+   * Asserts that a field does not exist in the current page by the given XPath,
+   * or if it exists but the field's value doesn't match the provided value.

This needs to be split into two paragraphs or shortened. Maybe:

Asserts that a field doesn't exist or its value doesn't match, by XPath."

would be good?

b) And then in the @param for the same method:

  * @param $value
   *   (optional) Value of the field to assert. You may pass in NULL (default)
   *   to skip checking the actual value, while still checking that the field
   *   doesn't exist.

I think this is still confusing... Maybe the first sentence could be changed to: "(optional) Value for the field, to assert that the field's value on the page doesn't match it." ? Or maybe you can think of a better wording?

c) assertFieldByName

    * @param $value
-   *   Value of the field to assert.
+   *   Value of the field to assert. You may pass in NULL (default) to skip
+   *   checking the actual value, while still checking that the field exists.

This parameter should be marked (optional).

d) Same as (c) in: assertFieldByID

e) assertNoFieldByName

   * @param $value
   *   (optional) Value of the field to assert. Providing a NULL value asserts
   *   that the field doesn't exist. Note that if no value is provided, this
   *   asserts that the field value is not ''.
 

This is OK, but I think it could be even clearer if it said:

(optional) Value for the field, to assert that the field's value on the page doesn't match it. You may pass in NULL to skip checking the value, while still checking that the field doesn't exist. However, the default value ('') asserts that the field value is not an empty string.

f) I think we should do the same update as (e) for assertNoFieldByID.

g) assertFieldByID:

   * @param $value
   *   Value of the field to assert. You may pass in NULL to skip checking the
   *   actual value, while still checking that the field exists. Note that if no
   *   value is provided, this asserts that the field value is not ''.
 

That "not" on the last line is wrong, oops! Also I think we can rewrite this as:

(optional) Value for the field to assert. You may pass in NULL to skip checking the value, while still checking that the field exists. However, the default value ('') asserts that the field value is an empty string.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
7.86 KB
3.11 KB

Updated the patch as mentioned in #27.
Please review now.

lokapujya’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -3222,15 +3222,13 @@
-   *   (optional) Value of the field to assert. You may pass in NULL (default)
-   *   to skip checking the actual value, while still checking that the field
-   *   doesn't exist.

The note should probably go back in.

+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -3358,9 +3358,10 @@
+   *   (optional) Value for the field, to assert that the field's value on the ¶
+   *   page doesn't match it. You may pass in NULL to skip checking the value, ¶
+   *   while still checking that the field doesn't exist. However, the default ¶
+   *   value ('') asserts that the field value is not an empty string.

should remove the blank space at the end of these lines.

joachim’s picture

> You may pass in NULL to skip checking the value, while still checking that the field doesn't exist.

How about:

> To have the value be ignored, and merely check that the field [exists / does not exist], pass in NULL.

That puts the thing the reader may want to do first, which to my mind improves readability.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
1.48 KB
1.48 KB

updated as #29. Please review.

jhodgdon’s picture

Status: Needs review » Needs work

The new patch is missing -- uploaded the interdiff twice by mistake?

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
7.92 KB

I am so fool ...ah
Upload the patch. Please review now.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks!

There are still several of the assertNoField methods that didn't get the updated wording. Can you please update them too? See #27 for details. Not all of the changes I suggested there actually got made.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
7.96 KB
1.7 KB

Updated the patch. Please review now.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs review » Patch (to be ported)

This looks good! Thanks everyone! Committed to 8.x.

Now we need to backport this to 7.x, as much as possible.

  • Commit 4a13614 on 8.x by jhodgdon:
    Issue #2039449 by joshi.rohit100, joachim, lokapujya, Jalandhar, paulh,...
joshi.rohit100’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.65 KB

Added D7 patch. Check it.

jhodgdon’s picture

Status: Needs review » Needs work

Looks good, thanks!

The only problem is that this patch is missing fixes for two methods:
- assertNoFieldByXPath
- AssertNoFieldByName

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
6.86 KB
1.31 KB

Updated the patch.
Please review now.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks!

But the new wording for assertNoFieldByXPath does not match the wording we've put on the other "No" methods, such as:

+   *   (optional) Value for the field, to assert that the field's value on the
+   *   page doesn't match it. You may pass in NULL to skip checking the
+   *   value, while still checking that the field doesn't exist.

I think this wording is clearer than what is in the latest patch?

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
6.96 KB
720 bytes

Updated patch. Please review now.

Status: Needs review » Needs work

The last submitted patch, 42: d7-2039449-42.patch, failed testing.

joshi.rohit100’s picture

42: d7-2039449-42.patch queued for re-testing.

joshi.rohit100’s picture

Status: Needs work » Needs review

some bot glitch.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, this looks good now!

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again everyone! Committed to 7.x.

  • jhodgdon committed 066c628 on 7.x
    Issue #2039449 by joshi.rohit100, joachim, lokapujya, Jalandhar, paulh,...

Status: Fixed » Closed (fixed)

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