-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass strict/verbose constructor args to HTML::Form #256
Conversation
Thanks so much for this. Should we add a test that demonstrates that |
Also, it would be great to document this new behaviour in the best practices section as well as the |
I think I have this actually.
|
I was looking specifically for |
Line 228 in the new test file should have been 0, my bad. The name of the
text is correct. I'll fix this tomorrow. At the London Perl tech meeting
now.
|
Thanks! Enjoy your meeting. :) |
I've updated my commit to fix the test.
I've done the best practices, but I am not sure about the From the amount of questions I've answered about Mech on Stack Overflow I believe a lot of new users start by copying the On the other hand, it helps to keep these new users on track. I've added it as a separate commit so we can cherry-pick it out if needed. I do not think we should be talking about verbose mode a lot. Catching these warnings is quite an advanced topic. Having it documented as an option is probably enough for people who know what they are doing. |
I think it would be good if the docs explained what the strict/verbose flags do when passed through to HTML::Form. It doesn't need to replicate the docs, but a one-sentence summary would be helpful to the reader. And is verbose not a best practice? |
I included that. Please see https://github.com/libwww-perl/WWW-Mechanize/pull/256/files#diff-9b033b946ad0ade000c98612745f570eR248.
I guess it should be, but it's not the default in HTML::Form and I believe we should not just turn on a new feature that will introduce fatal errors where none were there before. That would break a lot of users' code. |
Sorry, my mistake. That looks good. As to verbose being a best practice, I didn't think that listing it in "best practices" would include making it be the default. We'd just be specifying that it's a good idea, right? Note that I haven't used either of these features myself, but will be eager to play with them when they go live. |
Oh, I misunderstood. Sorry about that. However, was already in the best practices section. I've extended it in my commit. Please see https://github.com/libwww-perl/WWW-Mechanize/pull/256/files#diff-9b033b946ad0ade000c98612745f570eR3219. |
Is there anything you'd like me to do to test this out? |
If you're asking me, feel free to play with it. I wrote unit tests, but I didn't actually use it. I don't use Mech a lot lately as my focus at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Olaf was looking for volunteers to review this PR. I suspect he's trying to draw more attention to this dist. Very clever Olaf! Anyway, here's my two cents.
lib/WWW/Mechanize.pm
Outdated
=item * C<< strict_forms => [0|1] >> | ||
|
||
Globally sets the HTML::Form strict flag which causes form submission to | ||
croak if any of the passed fields don't exist on the page, and/or a value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"any of the passed fields don't exist on the page" seems slightly inaccurate. Perhaps something like "all passed fields can't be found in a single form on the page"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think neither is fully correct. This is not about searching for forms as far as I understand. It's for once it's found a form, that form will be strict, so it will not silently ignore if you try to pass in extra fields. It doesn't matter how it found that form. If you use a method that will find a form based on fields, then it simply won't find it if you ask for superfluous (or maybe misspelled) fields. That behaviour hasn't changed, it was already there.
I believe saying any of the passed fields don't exist on the form makes more sense.
|
||
This behavior can also be turned on globally by passing C<< strict_forms => 1>> to | ||
C<<WWW::Mechanize->new>>. If you do that, you can still disable it for individual calls | ||
by passing C<< strict_forms => 0>> here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
password => 'lost-and-alone', | ||
extra_field => 123, # field does not exist | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good docs.
); | ||
isa_ok( $form, 'HTML::Form' ); | ||
is($form->attr('name'), '4th_form_1', 'fourth form matches'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems very similar to the one two blocks above. Does it test different functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied all of those from the existing form_with_fields.t, because I wanted to make sure all the tests we already have also pass when strict is on. I did not actually prove those tests to be correct in this PR. I think the idea for these two is that in the 1st_form
test, it tests the outcome of calling form_with_fields()
with one argument, while the 4th_form_1
test calls it with two arguments. I'd like to keep those in for consistency.
isa_ok( $forms[0], 'HTML::Form' ); | ||
isa_ok( $forms[1], 'HTML::Form' ); | ||
is($forms[0]->attr('name'), '3rd_form_ambiguous', 'first result of 3rd_form_ambiguous'); | ||
is($forms[0]->attr('name'), '3rd_form_ambiguous', 'second result of 3rd_form_ambiguous'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how this is different from the previous line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot. See above please. This seems to have been broken in form_with_fields.t already, but I missed it. I will fix it in both tests.
I'd like to suggest/request that when all this is churned over that a new PR gets made with all the changes and feedback. It's difficult to look over multiple commits on something like this. |
I agree. When everyone's happy, I'll squash down the branch and create a single-commit new PR. |
One other request: I'd like it if we used proper capitalization and punctuation in comments, so that instead of:
we have
Makes it easier to read. (Also, it's "non-existent" not "non-existant".) |
Is there a timeframe for making a release of WWW::Mechanize with this PR in it? I'm going to put out a release of Test::WWW::Mechanize soon, and I'd like to mention in it that the underlying WWW::Mechanize has new features in it that may be useful to testers. |
I can release this on the same day as this gets merged. I'm happy with the current state of things. The code comments could be cleaned up here or in a different merge. I'm not picky about that. |
I just ran a small subset of our test suite using this Mech branch and the new options enabled and already turned up a couple of problems.
👍 to this level of pickiness. I'll start testing in earnest once it hits the CPAN. |
I don't want to nitpick, but it seems that actually most of the code base has single sentence comments that start with a capital letter, but do not have a full stop. There are only full stops if the comment has more than one sentence. However, this is in the synopsis. So it's not even a real comment. I am all for consistency, so I'll change that. @oalders, do you want me to merge them down and create a new PR or are we OK with a bit of history going in? |
@simbabque in the interest of getting this done, I'm going to merge what we have here and get a release out there. I think it looks good. |
Thanks @simbabque, @petdance and @PatrickCronin! |
New version is now on CPAN. |
Closes #255