Problem/Motivation
Many developers still use the Simpletest UI and it is already possible to run PHPUnit-based browser tests there. We want to print out the list of pages a browser test visited in the result of a browser test run in the UI. We want to provide developers with a similar experience as with Simpletest where they get the verbose output of pages in a test run.
We also want to improve the output of phpunit with nl2br() so that the fail messages of PHPUnit are more readable.
Proposed resolution
Run phpunit from the UI with a proper printerClass to catch the verbose output and improve the output in the HTML table with nl2br() or similar.
Before:
After:
Remaining tasks
Patch.
User interface changes
More verbose output in the Simpletest UI when PHPUnit browser tests are run.
API changes
none.
Data model changes
none.
Comment | File | Size | Author |
---|---|---|---|
#42 | simpletest-ui-2809117-42.patch | 4.5 KB | klausi |
#27 | simpletest-ui-2809117-26.patch | 4.52 KB | klausi |
#5 | simpletest_after.png | 79.37 KB | klausi |
#5 | simpletest_before.png | 40.31 KB | klausi |
Comments
Comment #2
klausiComment #3
Mile23Baby steps: #2641632: Refactor simpletest's *_phpunit_*() (and junit) functions etc. to a class, deprecate
Comment #4
klausiThat was fairly easy.
Now we have proper verbose output from phpunit browser tests in the Simpletest UI.
Comment #5
klausiAdding screenshots to issue summary.
Comment #6
Mile23Could use a test or two... There's
Drupal\simpletest\Tests\SimpleTestTest
which might help with test-ception.I was unable to repro the effect but I think it has more to do with my machine configuration than the patch.
Comment #7
Mile23Comment #8
klausiNow with a Simpletest that runs a browser test and then asserts the output is correct.
Comment #9
Mile23Nice. Here's a basic review.
Use $this->container instead of \Drupal
Add @see for UiPhpUnitOutputTest.
Comment #11
klausiFixed that, not sure why the testbot is failing. Trying some debugging.
@see should only be on a test, we don't refer to tests from the implementation class I think?
Comment #12
dawehnerI really like the idea!
Are we sure we want to add this also for the case of running it via the command line?
Comment #14
fgmOne other issue we found out with @klausi when trying this patch : the user-customized version of the phpunit.xml is used by default, which can make or break the UI behavior. For the UI tests, it is apparently necesssary to use phpunit -c phpunit.xml.dist to force use of the default, hopefully non-customized version of the PHUnit config file, instead of relying on the standard behavior which gives precedence to the customized version, likely not to be appropriate for the UI-run tests.
Comment #15
jhodgdon@klausi asked on #2750461: Remove Simpletest UI because we don't want to maintain a graphical test runner if someone would test this patch on, for instance, a failing version of ColorSafePreviewTest and see what happens. As someone who has been affected by this bug, I was glad to oblige. :)
I tested this in 8.2.x that was updated a while back in the dev cycle, so the patch encountered some "fuzz" to apply, but I didn't have a 8.3.x environment handy, so I hope that is OK.
So, what I did was change the line in ColorSafePreviewTest::testColorPreview() that says
to
so that the test would fail.
The output I got was pretty much exactly like the "before" picture in the issue summary. I did not get HTML verbose output like in the "after" picture. Do I need to do something else to make that happen? I do have the verbose setting in Simpletest turned on. Or do I need to be running 8.3.x or a more updated 8.2.x?
Comment #16
klausiYou should use 8.3.x, which has more and better logging committed.
fgm had the same problem, do you have a custom phpunit.xml file copied already?
In the next iteration of this patch we will try to always use the shipped phpunit.xml.dist file.
Comment #17
jhodgdonI did not have a custom phpunit.xml file to my knowledge. Where would that be? I mean, if some script created one when I first ran a PHP Unit test, it is possible I have an old one lying around...
Comment #18
fgmTypically, you get to create one by copying
core/phpunit.xml.dist
tocore/phpunit.xml
when configuring your site to run tests on the CLI, and you then edit that file to customize the Simpletest DB URI and other things.Comment #19
klausiI tried a couple of variants with a copied phpunit.xml in place, but my patch always still worked as advertised. I also tried it in 8.2.x and it worked there as well. I would assume file permission problems at this point, do you have a public files directory the webserver can write to? But then the web tests from simpletest should also fail if the webserver cannot write ...
Comment #20
marcoscanoAlso volunteering to test.
My environment is 8.3.x (not the latest, from some weeks ago) and a customized phpunit.xml. The patch applied cleanly and the output I have is:
The links at the bottom are not shown as links, but the URLs work and show the correct snapshots of each step.
Comment #21
fgmTest done with Klausi sunday:
The important line causing a change seems like it could be adding the custom output plugin.
Comment #22
klausiInteresting, the testbot has the same problem as @marcoscano and does not see proper link tags and br tags. Doing some more debugging on the testbot, this will still fail.
Comment #24
Mile23Some of the way this works might be altered by #2810083: Duplicate test results per fail/exception which helps fix a testbot issue.
Comment #25
klausiSo it looks like my new SimpletestUiPrinter class is never used. Adding some debug statements to it.
Comment #27
klausiFound the problem, the URL regex did not catch "http://localhost/" on the testbot *facepalm*. Simplified it.
This should be good to go now.
Comment #28
dawehnerConceptually this is the same as
\_filter_url
isn't it? I'm wondering whether moving this int its own component would be worth doing.Comment #29
klausiSince it is only 2 lines of code I think it is not worth having in a component. _filter_url() is way more complex and does stuff we don't care about here.
Comment #30
dawehnerIn general we could probably improve that more and more. This is a good start for now.
Fair
Comment #31
xjmSorry for the delay in reviewing this -- it looks great. About to test it manually but meanwhile I have one small nitpick:
Is the
(://)?
grouping really optional? Under what circumstance is a URL without it but starting with http going to be correct?Comment #32
xjmA followup for the filtering question might be worthwhile. I'm okay with hardcoding the parsing and filtering in this initial patch (and maybe always, but it is worth discussing later).
Also it's not clear to me if this was actually tested again with a custom
phpunit.xml
after @klausi's fixes. And a test-only patch for a failing browser test, separately and then rolled with this one, might be helpful to show how it's being reported on DrupalCI (or that it's not changing on DrupalCI if that's the case).Setting NR to see if those suggestions make sense. Thanks! I'll keep an eye on this issue so it doesn't get stuck in a backlog again.
Comment #33
dawehnerHere is the phpunit.xml file I use:
Without patch: https://www.drupal.org/files/issues/Screen%20Shot%202016-11-14%20at%2008...
With patch (and no custom phpunit.xml): https://www.drupal.org/files/issues/Screen%20Shot%202016-11-14%20at%2009...
With patch (and custom phpunit.xml): https://www.drupal.org/files/issues/Screen%20Shot%202016-11-14%20at%2009...
Comment #34
dawehnerOh I wanted to RTBC it
Comment #37
dawehnerSo we see the verbose output:
but well, that's of course not accessible to the outer world. I think the feedback of @xjm got addressed.
Comment #38
xjmThanks @dawehner, that looks great!
The point from #31 is still not addressed I think. I think this:
$url_pattern = '@(http)(s)?(://)?([^\s]+)@';
should be this:
$url_pattern = '@(http)(s)?(://)([^\s]+)@';
Otherwise it would match
httpwww.example.com
.But this is a really minor thing.
Comment #39
xjmOh also, do we need a followup?
From #32 about #28:
Comment #40
xjmComment #41
dawehnerGood point, let's change that. Well ideally we would use a protocol relative URL and be done with it.
Well, I don't think its important to actually use _filter_url. Its a different usecase, as in full text. We have a limited subset of HTML here, to be honest. Its good here IMHO to not share code. At the end its just a random testing UI.
Comment #42
klausiSimplified the URL regex as requested. _filter_url() is way more complex and does stuff we don't care about here.
Comment #43
dawehnerCool, tests are still passing
Comment #45
xjmAh yes, that's much simpler.
Committed and pushed to 8.3.x. Thanks!