minkphp / MinkBrowserKitDriver

Symfony2 BrowserKit driver for Mink framework
MIT License
550 stars 80 forks source link

`Undefined offset: 12` when disabled checkboxes are present for array field #150

Open acoulton opened 4 years ago

acoulton commented 4 years ago

With the latest behat/mink-browserkit-driver 1.3.4 and symfony/dom-crawler 4.4.5 there's an incompatibility that causes a fatal error in our testsuite.

We have HTML containing checkboxes with an array field name, some of them disabled - e.g.:

<input type="checkbox" name="permitted_recruiters[]" value="6620" disabled checked>
<input type="checkbox" name="permitted_recruiters[]" value="5340" disabled checked>
<input type="checkbox" name="permitted_recruiters[]" value="6639">
<input type="checkbox" name="permitted_recruiters[]" value="6672">

And we have a step that uses the standard And I check "Major Tom" step in MinkContext.

This has been working fine, but is now giving an Undefined offset: {number} error from BrowserKitDriver.

The error comes from this line

As far as I can see, the issue is that BrowserKitDriver's getFieldPosition() method just enumerates all checkboxes with that name on the page.

However the latest dom-crawler release includes this commit which appears to skip over fields that are disabled hence the array indices are different.

I suspect this can be fixed by duplicating that logic so that getFieldPosition also skips disabled fields, but it might be better to try and make it more robust so that it's not relying on matching just by the array index?

aik099 commented 4 years ago

Here is what needs to be done:

  1. please create a PR to https://github.com/minkphp/driver-testsuite, that will add missing tests to cover handling of disabled checkboxes in general
  2. after some testing and review from other people it will be merged
  3. after I'll re-run last build for every driver on Travis CI to see if they fail to comply with new test
  4. corresponding per-driver PR will be created with a fix