tag:blogger.com,1999:blog-5023448542823447711.post3524023629073707196..comments2023-09-22T04:05:16.253-07:00Comments on Optimizely Module: Notes on Converting to Drupal 8: Use assertPattern() for testingEarl Fonghttp://www.blogger.com/profile/05682372868411855409noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5023448542823447711.post-56831216441185896232014-08-05T14:16:33.171-07:002014-08-05T14:16:33.171-07:00I revisited the regex I posted in my previous comm...I revisited the regex I posted in my previous comment and made it even less likely to produce a false positive. This one is intended to match only within a single HTML tag.<br /><br />:<input( [^>]*? | )disabled="disabled"( [^>]*? | )id="edit-optimizely-project-title"( [^>]*? | )value="Default"( [^>]*?)?/>:<br /><br />I really did not do enough testing when I wrote the original expression. <br /><br />But I found this online regex evaluator, which is a huge, huge help. It says it's "for Perl", but for the kind of basic regex that I wrote, it works fine.<br /><br /><a href="http://www.regexplanet.com/advanced/perl/index.html" rel="nofollow">http://www.regexplanet.com/advanced/perl/index.html</a>Earl Fonghttps://www.blogger.com/profile/05682372868411855409noreply@blogger.comtag:blogger.com,1999:blog-5023448542823447711.post-21938502469679289912014-07-29T13:11:08.028-07:002014-07-29T13:11:08.028-07:00It bothers me that markup changes that are out of ...It bothers me that markup changes that are out of our control and not relevant to the Optimizely module can break the automated tests and make it necessary to change our code.<br /><br />In the current scenario, we are converting from one major version of Drupal to another, which is not going to happen often.<br /><br />But what about minor releases of Drupal? Of if the user switches to a different theme? I don't know the answers.<br />Earl Fonghttps://www.blogger.com/profile/05682372868411855409noreply@blogger.comtag:blogger.com,1999:blog-5023448542823447711.post-53011443190961233772014-07-29T13:00:00.397-07:002014-07-29T13:00:00.397-07:00That's a very good point about the possibility...That's a very good point about the possibility of false positives. It can be hard to write a regular expression that is exactly correct.<br /><br />Unlike the rather simplistic one that is in this post, here's one that I actually committed.<br /><br />:<input( .*? | )disabled="disabled"( .*? | )id="edit-optimizely-project-title"( .*? | )value="Default"( .*?)?/>:<br /><br />Your comment prompted me to take another close look at this regex. I can see now that it could match across multiple html tags and therefore be a false positive. <br /><br />On the other hand, it seems extremely unlikely for that to happen.<br />Earl Fonghttps://www.blogger.com/profile/05682372868411855409noreply@blogger.comtag:blogger.com,1999:blog-5023448542823447711.post-62962867370103366822014-07-29T11:06:44.338-07:002014-07-29T11:06:44.338-07:00Does testing for a pattern open up the possibility...Does testing for a pattern open up the possibility of the test returning a false positive? Would it not be better that the test breaks if the markup changes thus confirming the change as been applied and the test needs adjusting? Your solution sounds like a good approach for an application but perhaps not for a test?Anonymousnoreply@blogger.com