Problem/Motivation
A big area of problems of the PHPUnit conversions are the usages of $this->xpath(), because mink uses domdocument objects.
Proposed resolution
Provide a FC layer:
- Add a
::xpathUsingMink()to WTB. This allows people to convert existing WTB without adding the risk to move to BTB - Moving to BTB later is then way easier (again just renaming the base class).
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2809181-28.patch | 6.78 KB | jofitz |
| #17 | 2809181-17.patch | 7.69 KB | hardikpandya |
| #10 | 2809181-10.patch | 6.96 KB | claudiu.cristea |
Comments
Comment #2
dawehnerHere is a try
Comment #4
dawehnerLet's make it actually working
Comment #5
dawehnerComment #6
daffie commentedMaybe a stupid idea, but is it an idea to do #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 first and make all the tests HTML5.
Comment #7
claudiu.cristeaLooking at this change, I don't understand what this FC brings. My initial understanding was that $this->xpathUsingMink() will return exactly the same structure as WebTestBase::xpath() did so that we can completely avoid this kind of change.
Comment #8
dawehnerLet me explain it with more details in the issue summary. I hope this makes more sense.
Comment #9
klausiNice work, that looks easier than I would have expected!
We should mention here that this is a forward compatibility helper for the conversion to BrowserTestBase.
"This method is a forwards compatibility helper for the conversion to \Drupal\Tests\BrowserTestBase".
hm, the DomCrawler component is always available in our case, so this comment should be removed.
Why does this method return something? We are not even interested in the return value?
The method on BrowserTestBase should have an @deprecated tag because people should not use it for new code. They should use the xpath method.
"@deprecated Scheduled for removal in Drupal 9.0.0. Use self:xpath() instead."
Comment #10
claudiu.cristeaFixed #9 issues.
Comment #11
klausiThanks, almost ready! I'm not 100% sold on the method name "xpathUsingMink", but I also don't have a better idea.
Class comment is missing. We should mention here that this is used in WebTestBase::xpathUsingMink() for forwards compatibility. We should also mention that we need to have this class because there is no way to set an artificial response on the Goutte client otherwise because createFromCrawler() is protected.
Comment #12
dawehnerHere is some documentation
Comment #13
klausiJust a round of nitpicks, otherwise looks good to go to me.
The last part of the sentence is broken. Did you mean see the Mink documentation or DOMDocument?
And the data type should be "...|false" because this never returns TRUE.
I think we should avoid uncommon abbreviations such as "FC", let's use forward compatibility layer.
Can be just "Used as part of the forward compatibility layer for BrowserTestBase."
Should be "This class allows you to set the response content manually on a Goutte client."
Should have 2 "::" after self.
Comment #14
dawehnerSorry klausi for the slow response :(
I totally agree.
Comment #15
klausiCool, one minor doc nit pick that can be cleaned up by a novice contributor:
"For future compatibility with BrowserTestBase you can use the method xpathUsingMink() instead."
Comment #16
hardikpandya commentedComment #17
hardikpandya commentedComment #18
klausiThanks, looks god to me.
Comment #21
dawehnerBack to RTBC
Comment #22
alexpottI think we should mark this as deprecated too - so we don't forget to remove it in 9.0.x :)
I think we should deprecate the method specifically so people know to use xpathUsingMink(). So their IDEs tell the easy to upgrade. It would also be useful if this documentation gave the developer some idea about what they might need to change given the new return type.
Should checkout have a comma before it yes or no. It looks like this documentation is hedging its bets :).
Comment #23
mpdonadioJust discovered this issue, and don't want to hijack it, but could this technique be used to update the handful of places where \Drupal\simpletest\AssertContentTrait::setRawContent() is used?
Comment #24
dawehnerYeah I guess we would actually maybe provide an API for that, even I actually don't like it. If you want to set raw content you can use a kernel test IMHO.
Comment #25
klausiNow that #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits landed I think this forward compatibility is not necessary anymore. The hope was that we could use this to convert even more tests with the big bang patch.
Now this forward compatibility layer would just create more work:
1. Update test case to use forward compatibility layer.
2. Move test case to use BrowserTestBase
While without the forward compatibility layer we just do this in one step. Maybe I'm missing something?
Comment #26
Munavijayalakshmi commentedComment #27
Munavijayalakshmi commentedComment #28
jofitzRe-rolled.
Excluded changes to ContactAuthenticatedUserTest.php because they introduced calls to a deprecated function (in favour of the replacement function).
Comment #29
klausiI'm closing this because right now it seems we can work through converting Simpletests without this layer. As I said above it is probably too late for this and just creates more work.