While converting automated tests to class WebTestBase in Drupal 8, several of the assertions were failing. This was happening in spite of the fact that none of the theme templates, element ids, or other relevant code had changed.
These assertions had been implemented with assertRaw(), which does literal string matching against the raw HTML of the response pages. It turns out that in D8, some form elements may be generated differently even though the final rendering is pretty much the same.
As a slightly simplified example, here's a tag that is output by the Drupal 7 version of the module.
<input disabled="disabled" type="text" id="edit-optimizely-project-code" name="optimizely_project_code" value="Undefined" size="30" />
But in D8, the corresponding tag is
<input aria-describedby="edit-optimizely-project-code--description" disabled="disabled" type="text" id="edit-optimizely-project-code" name="optimizely_project_code" value="Undefined" size="30" aria-required="true" />
Obviously, these two strings don't match.
The intent of the assertion is to check that the particular input tag exists, that it is disabled, and that it has a value of "Undefined". The other attributes are irrelevant.
So I re-wrote the assertion using assertPattern() instead, which takes a regular expression as its first parameter.
':<input .*? disabled="disabled" .*? id="edit-optimizely-project-code" .*? value="Undefined" .*? />:', ...);
This is not perfect. For one thing, it still relies on the three attributes being in a certain order. It also has some extra space characters that could break the match, but I'm leaving them here to make the regex more readable.
However, I believe implementing with assertPattern() makes the test more robust in the face of future changes as well as making the code better self-documenting.
abstract class WebTestBase