Problem/Motivation
Over in #2232271: [Meta] Use Behat for validation testing we're proposing adding Behat to enable JavaScript testing.
But as a first step we don't need Behat to utilise the Selenium/Sahi/Zombie/PhantomJs drivers, we need Mink.
Proposed resolution
- Create a BrowserTestBase that is run on top of Mink.
- Use the Goutte driver (pure php) but build the functionality in a driver-agnostic fashion.
- Port some tests as a proof of concept.
This will open the door for step 2: Add JavaScriptTestBase with an alternate session implementation.
The pitch
In the Drupal 8 cycle we have invested a lot of time into writing tests. We are now writing unit tests for our logic and acceptance tests for our scenarios, but what about our frontend (Javascript) testing?
Originally Drupal's WebTestBase evolved from SimpleTest but over the years it has morphed and transformed into a mutant beast of difficult to maintain custom code.
Whilst we've been off on our island, the PHP community at large have been working together on solving the same problems we've been adding additional band-aids and bolt-ons to SimpleTest for.
One such solution is Mink.
Say hello to Mink
Many of us are familiar with Behat's gherkin syntax but you may not be aware that the real power of Behat is powered by Mink. Most of the built in step-definitions are added by the Mink extension, which is a Behat Extension that wraps Mink.
The core of Mink is the DriverInterface which allows a swappable back-end for functional testing.
Much of the custom code we have in SimpleTest can be handled by existing functionality in Mink, but in a back-end independent manner.
Since Early April 2014, we have been working on a new functional test base that uses phpunit as the runner and Mink as the browser.
At present in WebTestBase when a test calls $this->drupalGet()
the implementation is hard-wired to use curl.
This means that we are limited in our web-testing to things that Curl can handle. As a result we have some interesting work-arounds for JavaScript/Ajax handling (we are looking at you drupalPostAjaxForm()
).
With BrowserTestBase architected on top of Mink, we maintain a Mink session for browser interactions. The default implementation of this uses the Goutte driver, which is simple web-scraper that wraps Guzzle and the Symfony DomCrawler component. This abstracts away the browser implementation to the various Mink drivers.
So how does this help Drupal?
- We get rid of loads of custom-code for parsing/manipulating the dom and just use widely adopted implementations.
- We get rid of loads of custom Curl handling code and let Goutte and Guzzle worry about it.
- Any issues we find strengthen those code-bases. We've already ported Goutte to Guzzle 4 - i.e. Goutte 2.0. We've found and fixed bugs in Guzzle 4. PIE for the win.
- We can move towards real JavaScript testing
Wait how does this help JavaScript testing?
So imagine JavaScriptTestBase extends BrowserTestBase but instead of using the Goutte driver in our session, we instead use the Selenium, Sahi or Zombie drivers - these drivers understand JavaScript - they are either headless browser implementations or they control real browsers.
Or in code terms.
$button = $this->getSession()->getPage()->find('css', '#my-button');
$button->mouseOver();
$button->press();
$this->getSession()->dragTo(CssSelector::toXPath('#my-target'), CssSelector::toXPath('#my-destination'));
Future issues
A) HttpTestBase - Work on creating HttpTestBase that uses Guzzle direct but doesn't need the Mink/DomCrawler elements - for things like Rest and Rss tests - where no browser is required
B) META - Create a meta listing each of the un-converted tests and create issues for each un-converted test
C) Javascript - we recommend PhantomJS as its a real headless browser built on top of WebKit - its just a binary and there are composer libraries so we could foresee-ably use it without any significant overhead on our testing infrastructure.
User interface changes
None
API changes
BrowserTestBase
is built on top of Mink and PHPUnit so the asserts are different to WebTestBase. Form submits are handled by Mink so instead of drupalPostForm()
and drupalPostAjaxForm()
new tests that extend this class will use submitForm()
instead. If the Mink driver supports AJAX it will handle submitting form using AJAX.
How to run
$ cd core
$ sudo -u www-data SIMPLETEST_BASE_URL=http://d8.dev ./vendor/bin/phpunit --testsuite functional
# Or with run-test
$ sudo -u www-data php ./core/scripts/run-tests.sh --url http://d8.dev --class "Drupal\Tests\simpletest\Functional\BrowserTestBaseTest"
Beta phase evaluation
Issue priority | Major because automated tests are important, but Drupal currently lacks the ability to test javascript code. Not critical because Drupal has never tested javascript code, and this has historically not been considered to be a blocking issue. |
---|---|
Unfrozen changes | Unfrozen because it affects automated tests. |
Disruption | Not disruptive. It adds a new base class which can be used to write browser based tests. Some changes were made to the way Drupal recognizes whether it is running as part of an automated test, but this does not affect existing code. |
Comment | File | Size | Author |
---|---|---|---|
#261 | interdiff.txt | 6.6 KB | pfrenssen |
#260 | 2232861.260.patch | 67.97 KB | alexpott |
Comments
Comment #1
sunSince I've worked on many similar simpletest issues, I'd like to prevent you from running into insanity ;-)
For the sake of making progress, I think it would be best to try whether an initial step here can be architected and implemented (sort of) in an "opt-in" way; for example, by extending
WebTestBase
with a new class that usesMink
instead of cURL.That will make all existing tests run against the current code (for now), and we can focus on getting the Mink based version to work first.
Comment #2
larowlanRoger that
Comment #3
larowlanMaking progress here
Comment #4
larowlanBumping priority based on some discussions and adding API change now that approach is clearer and there is a patch
Comment #5
sunCreated #2257519: Move content assertion methods into a trait, so DUTB can consume it, too
Comment #6
larowlanwoohoo Goutte with Guzzle 4 was merged so this is open again.
https://github.com/fabpot/Goutte/commit/2735d2400aab84e5c26bc1c854478d5f...
Comment #7
larowlanHave a working implementation on Guzzle 4
Will keep running tests in #2083741: IGNORE: Patch testing issue till less fails.
Comment #8
rcross CreditAttribution: rcross commentedJust curious if there is any consideration for using http://codeception.com/ (or any reasons against it)
Codeception seems to allow for a most consistent interface for both acceptance, functional and unit tests and is utilising popular libraries underneath including mink, phpunit, etc.
Comment #9
benjy CreditAttribution: benjy commented+1 for Codeception, i'd be interested in hearing more thoughts on this.
Comment #10
sunSorry, but Codeception is off-topic here. This issue is about making a first big leap towards leaving the Simpletest sphere.
Anything beyond this step is a pipe-dream at this point. So let's stay focused here, please.
(You can, however, create a dedicated issue with a proper proposal, outlining the pros and cons, in order to discuss that idea.)
Comment #11
larowlanComment #12
larowlanComment #13
larowlanComment #14
jibranIt's green yay!! #2274167-96: [ignore] Patch testing issue. Now reviews.
Comment #15
larowlanHere's where we're at, we about-faced from converting everything and introduced a BrowserTestBase that's based on Mink and Goutte.
We moved over some existing tests.
The plan from here is to
a) work on refining BrowserTestBase - posting here for reviews
b) Build a trait containing the common hunks between WebTestBase and BrowserTestBase, we didn't sub-class off WebTestBase because we didn't want to rely on it and we eventually want to get rid of it (we've marked it @deprecated) - so the patch as it stands contains lots of duplication that belongs in a trait.
c) split off sub-issues to add the required libraries we need in their own issues
d) work on creating HttpTestBase that uses Guzzle direct but doesn't need the Mink/DomCrawler elements - for things like Rest and Rss tests - where no browser is required
e) Create a meta listing each of the un-converted tests
f) Create issues for each un-converted test
Attaching 'core-only' and 'whole biscuit' patches (which includes all the vendor changes).
Comment #17
larowlanHere's a start on cleanup we need to do
We can revert this too, now https://github.com/Behat/MinkGoutteDriver/commit/428df9dd75c56b0d76a5308...
We can revert this now and return to using Guzzle as released, they merged our PR
We can pin both of these now
We should open a dedicated issue for updating Guzzle, 4.1.3 includes @grom358's upstream fixes (https://github.com/guzzle/guzzle/releases/tag/4.1.3)
is *a* workaround
<3 - so much cleaner
out you go
We can rename this now, to something more appropriate
This can go - any test that relies on this is ajax and belongs on JavaScriptTestBase
I think it's called setRawContent now
This can go to, ajax forms aren't responsibility of BrowserTestBase » defer to JavaScriptTestBase issue
This can go into HttpTestBase - needed for Rest etc, non-form implementations
Bump to » JavaScriptTestBase issue
@todo can go
goodbye
mmm cleaner
We have a decorator for BC, because ::xpath returns SimpleXML element in HEAD, but now returns a Mink NodeElement, this keeps all the old SimpleXML methods/array access valid.
much cleaner :)
We're stuck with this, Mink is read-only, lets remove the todo
Yep none of these share anything in common with AssertContentTrait so had to be duplicated
We should remove reference to curl.
Looks like a merge gone wrong
Please Please Please can we?
This is how you monkey the dom - the Mink interface/DomCrawler is read-only, so you can't diddle the dom to e.g. submit option values for select fields that aren't in the dom - so we use a request event and intervene. Note this is Guzzle only.
Comment #18
larowlanShould fix failing test.
Comment #19
larowlan17.4 #2304081: Upgrade Guzzle to version 4.1.3
Comment #20
nod_epic.
Comment #21
grom358 CreditAttribution: grom358 commentedFYI I have started a new branch over here https://github.com/grom358/drupal/tree/mink-testing-2232861 where I have made a clean BrowserTestBase. It has no mention of drupalPost or curl stuff etc. It only supports what mink does and in theory should work with any mink driver.
Currently it has a drupalGet method, but thinking it should be renamed to drupalVisit to keep with the mink lingo.
I did some refactoring by pulling up a bunch of non browser methods (ie. drupalCreateRole, etc) from WebTestBase into FunctionalTestBase. And WebTestBase and BrowserTestBase extend this. But down the line would have a HttpTestBase that uses Guzzle with no browser stuff that extends it. With WebTestBase being removed at some point.
One thing have to sort out with HttpTestBase is how to support drupalLogin. The REST tests use this, but currently drupalLogin relies on parsing a form in order to submit the user login form.
Comment #22
moshe weitzman CreditAttribution: moshe weitzman commenteddrupalLogin should definately not do any http. it should create a session and any other fiddly bits that are needed. that gets stored away for future web requests.
Comment #23
grom358 CreditAttribution: grom358 commentedPatch with BlockHtmlTest ported to the new BrowserTestBase on the branch I outlined before.
Comment #25
grom358 CreditAttribution: grom358 commentedComment #26
dawehnerIt would be great if you guys could provide a patch which does not have the mink code but everything else.
I would be cool to describe that this is for front tests, not API ones.
Comment #27
jibranJust for the record you can review/view changes here https://github.com/grom358/drupal/pull/1/files
Comment #28
nick_schuch CreditAttribution: nick_schuch commentedAs per a meeting @larowlan, @grom358 and myself had with @sun, we are working on test class to runs side by side with current simpletest. Between this and @sun's KernelTestBaseNG work well be the lot running on PHPUnit. This is a rough patch on @grom358 and my work.
Here is a demonstration of how to run this work:
Still do to
Currently we need to add more test coverage.
Comment #30
grom358 CreditAttribution: grom358 commentedSome cleanup and polish.
Comment #31
grom358 CreditAttribution: grom358 commentedSmall fix
Comment #36
grom358 CreditAttribution: grom358 commentedComment #38
nick_schuch CreditAttribution: nick_schuch commentedIf anyone is willing to sprint on this issue, we are looking for someone to write the test suite that ensures that this new functionality is working. We have a class for these tests (https://github.com/nickschuch/drupal-phpunit-mink/blob/phpunit-mink/core...) and a module (https://github.com/nickschuch/drupal-phpunit-mink/tree/phpunit-mink/core...).
The kinds of test we are looking for are:
Comment #39
moshe weitzman CreditAttribution: moshe weitzman commentedJust to follow-up, we sprinted on this at Badcamp. Half a day was lost to getting it to work. Thanks to @grom for waking up and helping get the right webAssert class fired up for submitting our forms.
We ended up submitting a PR at https://github.com/nickschuch/drupal-phpunit-mink/pull/5.
I'm not sure that a second class that proves or disproves session bleed is possible. The second class needs to depend on the first and thats not really what the @depends annotation means in phpunit.
Comment #40
nick_schuch CreditAttribution: nick_schuch commentedI just mean we write 2 separate test case classes to ensure that we don't have the same mink session between one test class and another.
Comment #41
nick_schuch CreditAttribution: nick_schuch commented@grom, looks like it's not the port, it's more to do with that domain variable not being set in BrowserTestBase.
I got the run-tests.sh command from the bot output.
/usr/bin/php ./core/scripts/run-tests.sh --concurrency 25 --php /usr/bin/php --url http://ec2-54-179-121-168.ap-southeast-1.compute.amazonaws.com/checkout --keep-results --all --clean 2>&1
Can be found here: https://qa.drupal.org/pifr/test/902993
Comment #42
grom358 CreditAttribution: grom358 commentedComment #44
grom358 CreditAttribution: grom358 commentedComment #46
grom358 CreditAttribution: grom358 commentedComment #48
grom358 CreditAttribution: grom358 commentedComment #49
grom358 CreditAttribution: grom358 commentedComment #52
grom358 CreditAttribution: grom358 commentedComment #53
grom358 CreditAttribution: grom358 commentedSo it runs on testbot via run-tests.sh now :)
But for those running directly with phpunit, please note I changed it to use environment variable SIMPLETEST_BASE_URL and its a url to base url for your site and you can run directly from inside the core directory too. Eg:
Test suite still needs to test more of BrowserTestBase, eg. logging in (drupalLogin) etc.
Comment #54
phenaproxima@moshe told me he would take that on (the login stuff, adding more advanced self-test cases).
Comment #55
jibranHere is something reviewable without vendor libraries.
Comment #56
jibranYay!!! it is green now. Some minor stuff.
Tests simpletest module.
I think we can make this better.
Not needed now.
Hello Drupal :D
LOL
Contains \Drupal\Tests\simpletest\Functional\BrowserTestBaseTest.
Comment #57
larowlanUpdating commit mentions in issue summary
Comment #58
larowlanComment #59
phenaproxima@jibran, glad you enjoyed my editorializing in #5 ;-)
Comment #60
moshe weitzman CreditAttribution: moshe weitzman commentedThis followup verifies that drupalLogin() is working in a BrowserTestBase case. BrowserTestBase is now well tested enough for initial commit, IMO.
Comment #61
nick_schuch CreditAttribution: nick_schuch commentedMyself, @larowan, @grom358 and @phenaproxima had a call a couple of days ago with the goal of putting together a list of things we would like to see on a "Simpletest roadmap". These are the notes, @moshe is there anything you would like to add? If all good I would like to formalise these in a separate ticket / groups.drupal.org post.
----------
Simpletest - Roadmap
https://www.drupal.org/node/2304461 - kerneltestbaseng to make kernel test base run on phpunit
Step 1: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/DrupalKernel...
No seriously. The kernel needs to be dependency injected before the rest happens. :-)
https://drupal.org/node/2232861 - mink + phpunit to replace webtestbase
follow ups for phpunit+mink
To do on kerneltestbaseng
Comment #62
grom358 CreditAttribution: grom358 commentedComment #64
grom358 CreditAttribution: grom358 commentedComment #65
grom358 CreditAttribution: grom358 commentedComment #67
grom358 CreditAttribution: grom358 commentedComment #68
dawehnerIt's a bit odd that we point to goutte driver master ... don't we have a proper stable release for it?
# BrowserTestBase
Just be clear, we have an interface for that.
Comment #69
daffie CreditAttribution: daffie commentedMy first observations:
Why do you change that?
Can we rewrite that as
Where is the documentation inherit from?
I have a few concerns about the naming of files. We have an example module simpletest_test with a form ExampleForm. We also have the simpletest module with the form SimpletestTestForm. For me it is a bit confusing. Can we rename the simpletest_test module to simpletest_example. Can we also rename BrowserTestBaseTest to SimpletestExampleTest. So that for developers that are new to our PHPUnit-behat-mink testing, they can easily find the example module and testfile.
Comment #70
daffie CreditAttribution: daffie commentedOverall a great patch! I like it very much.
Comment #71
daffie CreditAttribution: daffie commentedThere is no
use Drupal\Simpletest\WebAssert;
Comment #72
larowlan#71 - same namespace - so no need for use stmt
re-roll and also a core-only patch.
Comment #73
jibranIt is sad that there is no fix for #56 yet :( here is another review.
Contains \Drupal\simpletest\BrowserTestBase.
Do we have a type?
Is it in seconds? Please update the doc block.
I think this should be self::prepareEnvironment().
@var line missing.
Full namespace please.
Creates
Can we use static create/load methods here?
Logs
Full namespace please.
Fills
Please add comment for this.
Can we add a use statement on top and call it MinkWebAssert?
not field button.
not field select.
We don't need this file anymore.
Comment #74
daffie CreditAttribution: daffie commentedMy points from comment #69 are still open.
Comment #75
grom358 CreditAttribution: grom358 commentedComment #76
grom358 CreditAttribution: grom358 commentedComment #77
grom358 CreditAttribution: grom358 commented@dawehner comment #68 . Rely on DrupalKernel::rebuildContainer() so currently can not use the interface, since it doesn't define that as part of interface. Suggested solutions?
@daffie comment #69 I believe those ifs are due to getting redefined DRUPAL_ROOT constants when phpunit does it test discovery. Have to check with nick_schuch on that one since he was one that dealt with getting this to work with phpunit.
About comment #71 . There a \Drupal\simpletest\WebAssert that extends the \Behat\Mink\WebAssert and adds some additional methods. Should try get this added upstream.
As for proposed changes @daffie and @jibran I just uploaded another patch updated according to your reviews.
Comment #78
daffie CreditAttribution: daffie commented@grom358: Can you add an interdiff for the drupal files.
Comment #79
grom358 CreditAttribution: grom358 commentedComment #80
grom358 CreditAttribution: grom358 commentedComment #81
jibranCore only patch
Comment #82
amateescu CreditAttribution: amateescu commentedI'm not sure how well tested this new BrowserTestBase is, but at least this method is clearly broken since 'sid' is not stored in {users} anymore for quite a few months.
Instead of copy-pasting methods from WebTestBase and having to maintain both in the future, wouldn't it be better to extract the similarities in a trait?
Comment #83
grom358 CreditAttribution: grom358 commented@amateescu yeah some of these (ie. the random methods) could be moved to a trait. Though the idea is for BrowserTestBase to replace WebTestBase so we don't have to maintain so much code for a test framework. Also we do need more test coverage. Having said that... drupalLogin calls
So mmmmm. Get back to you on that one.
Comment #84
grom358 CreditAttribution: grom358 commentedUpdated drupalUserIsLoggedIn and fix couple other minor things.
Comment #86
grom358 CreditAttribution: grom358 commentedPatch reroll
Comment #89
grom358 CreditAttribution: grom358 commentedpatch reroll
Comment #90
daffie CreditAttribution: daffie commented@grom358: Can you add interdiff.txt to your patch. It will be easier for others to follow what your changes are.
Comment #91
benjy CreditAttribution: benjy commentedAny specific reason BrowserTestBase has a handful of class properties using camel case and then others with lowercase and underscores?
Comment #92
grom358 CreditAttribution: grom358 commented@benjy no... leftover cruff from WebTestBase . Will fix.
@daffie patch reroll so there is no interdiff if I'm not mistaken. I am kind of noob to the whole interdiff thing still.
Comment #93
daffie CreditAttribution: daffie commented@grom358: A tutorial on how to make an interdiff.txt.
Comment #96
daffie CreditAttribution: daffie commentedComment #97
grom358 CreditAttribution: grom358 commentedReroll and changed to lowerCamel property names
Comment #98
grom358 CreditAttribution: grom358 commentedPatch without vendor for review purpose
Comment #99
benjy CreditAttribution: benjy commentedI had a quick read over the code, mainly just syntax based stuff below, I realise much of the code came across from WebTestBase soI apologies for anything that might not have been new. I'll try have a full test of this over the weekend. Look good!
These don't need to be initialised to NULL, and you don't do it for other properties on the same class.
Absolute class name.
Is this needed? Do we use the, don't pass an Id use case and therefore default to NULL use case?
No reason not to use a strict check here.
So parse_url() successfully handles the xpath objects? It would seem to me that we should cast it first?
Don't actually need the else block here.
Description should be on the next line.
Does this need a separate issue to discuss?
Comment #100
daffie CreditAttribution: daffie commentedI would like to help to get this patch committed. In the remaining tasks you state that you want to "Write a test suite to test itself". If I then look at the code I come to the conclusion that that will become very difficult. My idea would be to start writing tests and to see what the problems are and fix those. After we write some non trivial tests and we get the results that we want we can say that this patch is RTBC. I have selected the tests in core/modules/simpletest/src/Tests for this. The first big problem I encountered was that the class Drupal\simpletest\WebAssert needs a lot more methods for all kinds of asserts. The second problem is that we use the GoutteDriver and that does not support javascript.
If anyone has other/better ideas please lets hear them.
Comment #101
grom358 CreditAttribution: grom358 commented@daffie the test suite testing itself is BrowserTestBaseTest. It covers a basic page controller and form at the moment. Basically its an example on how to use BrowserTestBase. Ideally I would like to port tests using WebTestBase to BrowserTestBase.
Can you expand on what methods for all kinds of asserts? That class extends the WebAssert from Mink and has all sorts of asserts. Ideally I would want Drupal\simpletest\WebAssert to disappear and have those additional methods go upstream into Mink.
As for support of javascript... there are some issues that need resolving for that. The current testbot infrastructure to my knowledge can't support adding in something like phantomJS. So that means stuck with GoutteDriver for now.
It would be nice to be able to register sessions with BrowserTestBase via YML config. Then in the test when need javascript support can do something like..
and then all the mink commands/asserts will be using the Javascript driver.
Comment #102
pfrenssenI think providing a driver that supports javascript is out of scope for this issue. Once this is in It will be easy enough to override this class and use PhantomJS / Selenium / ZombieJS. We can always add support for this in a future issue.
The same goes for adding assert methods, or a non-trivial test case. Those things are out of scope for this issue. This issue is just about getting a basic browser test framework in which is incredibly valuable in itself. We can always add followups to port existing non-trivial tests over and the need for additional assert methods will become apparent then. I actually doubt whether we need much more than what Mink offers out of the box in the base class.
Going to have a look at the patch now during my lunch break.
Don't rely on branch heads, since these might contain major changes at some point in the future. It's better to specify version numbers or tags.
If you do need to rely on the master branch because you need some unreleased features / fixes, then "pin" the most recent commit ref (eg. "dev-master#a23adb345").
Is this needed to avoid notices being thrown when Drupal is bootstrapped twice during a browser test run? It might be a good idea to add a comment here explaining why these constants may already be defined.
Maintain alphabetical ordering.
I would rename this property to
$originalSiteDirectory
to better convey its contents and be consistent with$siteDirectory
.I know it's glaringly obvious what this contains, but we need a description for this ;)
I got only half way through the patch, my lunch break is over :)
Comment #103
grom358 CreditAttribution: grom358 commentedReroll and code cleanup based on suggestions from @benjy and @pfrenssen
I agree with what pfrenssen stated. This issue is just concerned with getting BrowserTestBase into core. The other things I mention are other issues to go into a meta issue about deprecating simpletest.
Comment #104
larowlanCan we add a deprecated tag to WebTestBase here? Earlier patches had it.
Comment #105
hussainwebRerolling... I worked from the
-do-not-test.patch
in #103 and after rerolling, rancomposer install
and created the patch. I have also attached a similardo-not-test.patch
.Comment #106
daffie CreditAttribution: daffie commented@hussainweb: Can you add an interdiff.txt. I think that it is best to use the do-not-test patches for that.
Comment #107
hussainweb@daffie: It is complicated (and sometimes meaningless) to get interdiffs for rerolls. That is the reason I usually don't change anything in a reroll. For changes and additions, I will definitely use an interdiff.
Comment #108
daffie CreditAttribution: daffie commented@hussainweb: Thank you for telling that you did a straight reroll and no other changes or additions!
Comment #109
daffie CreditAttribution: daffie commentedI removed the test module simpletest_example. I did this because there are other test modules in the system module that we can use for this patch. I have chosen test_page_test and form_test. I have changed the test BworserTestBaseTest a bit so that it uses the new test modules. If you think that this is wrong please let me know.
Comment #110
grom358 CreditAttribution: grom358 commented@daffie do you have an interdiff so I can apply to repo? also are you on github. Could add you to the github repo working on this issue with
Comment #111
hussainwebI'm attaching the interdiff between #105 and #109.
Comment #112
hussainwebSorry, I didn't mean to have that go to test. I saved it as .patch by mistake.
Comment #114
grom358 CreditAttribution: grom358 commented@hussainweb can also add you to the github repo.. just need to know github username
Comment #115
hussainwebIt's hussainweb. Thanks!
Comment #116
daffie CreditAttribution: daffie commented@grom538: My github account is daffie1.
Comment #117
larowlanComment #118
pcambraPlain reroll of this, only the composer.lock file had conflicts
Comment #120
pcambraI don't seem to reproduce the fails of the testbot locally (it fails for me on t() being redeclared) but they seem related to https://www.drupal.org/node/2407153
Comment #121
benjy CreditAttribution: benjy commentedThe BrowserTestBaseTest errors are likely this:
$config->getEditable('system.file') should fix that.
EDIT: I didn't test that, i just had a similar issue elsewhere earlier.
Comment #122
pcambraUsing getEditable from the config factory as @benjy suggests.
Comment #123
grom358 CreditAttribution: grom358 commented@daffie and @hussainweb have add you to github repo https://github.com/nickschuch/drupal-phpunit-mink/
Happy to add anyone else that wishes to contribute via github, having said that I will still gladly take interdiffs/patches.
Comment #124
grom358 CreditAttribution: grom358 commented@pcambra you attached the wrong interdiff there it seems. I believe I have made the same changes however on the github repo.
Comment #125
benjy CreditAttribution: benjy commentedha, #122 is my interdiff from another issue :)
@grom358, where are you at with this issue, are you simply waiting on reviews at this point?
Comment #126
grom358 CreditAttribution: grom358 commented@benjy yes just waiting on reviews.
As far as I am concerned the functionality meets the goal of this particular issue. That is a test base that uses phpunit + mink. There are further goals which are related to this issue but this issue is step 1. One of which is to support other drivers and hence javascript. Longer term the goal is to move away from having to maintain the custom testing framework that is simpletest.
Comment #127
pcambraI don't think so... unless you guys see another file there: https://www.drupal.org/files/issues/interdiff_9537.txt
Patch in #124 is 1.9M and the original is 1.02M but the interdiff is 1.69Kb, there's something happening there.
Comment #128
benjy CreditAttribution: benjy commentedYeah that was showing me the wrong file, I added a ?t=1 on the end and get the right version. Guess it was cached.
Comment #129
bojanz CreditAttribution: bojanz commentedTime to get this in, and start practising the dance we'll perform on simpletest's grave?
Comment #130
grom358 CreditAttribution: grom358 commented@pcambra the increase in file size is most likely from reroll and changing of composer.json. Previously I was using dev-master and I changed to use stable releases. I can't see anything else in the patch to explain the change in filesize. The do-not-test patch has not varied in size.
I am looking into it as double check.
Comment #131
benjy CreditAttribution: benjy commentedThis code has been mentioned twice in this issue but I can't see a response.
Can we add a comment as to why this is now needed. I don't see why bootstrap.inc is included twice so i'm guessing something else has already defined them?
Comment #132
alexpottAdding new libraries is a Dries decision. So please assign to Dries upon re-rtbc.
Also it looks like the issue summary is in need of an update/rewrite since I'm not sure that the API changes listed are happening. PLus the suggested commit message is out of date - however since everyone has contributed a file to the issue I suggest removing it since the auto-generated one looks good.
Comment #133
benjy CreditAttribution: benjy commentedSpent an hour testing this today. I think the issue summary needs some instructions to make this easier for people to test. I noticed that tests running BrowserTestBase cannot be run from the UI or run-tests.sh, was that intended?
This should be protected inline with how WebTestBase was previously.
Should be protected like WebTestBase.
Maybe we could copy this out of TestBase into BrowserTestBase? Many tests likely use this function and inherit it through WebTestBase? Also configImporter(), copyConfig().
Interdiff attached shows the changes I had to make to get MigrateAggregatorConfigsTest working, pretty easy.
Comment #134
grom358 CreditAttribution: grom358 commentedComment #135
grom358 CreditAttribution: grom358 commented@benjy can you provide more details on using run-tests.sh and simpletest UI. That is definitely something that should be working, they are working for me here locally and parts of the patch was to make it work with them. You can see the test bots runs BrowserTestBaseTest which is using run-tests.sh
Comment #136
benjy CreditAttribution: benjy commented1. Simpletest UI - This is still broken for me. I had the patch #124 applied on top of 1e985b0 plus the interdiff from #133 and tried to run MigrateAggregatorConfigTest which failed with Drupal\Core\Installer\Exception\AlreadyInstalledException: (screenshot attached).
2. run-tests.sh - Yes this is working for me now since my last re-install, not sure what was going on before.
I also tried without my interdiff using BrowserTestBaseTest for both run-tests and UI. Same result, UI fails, run-tests works.
Comment #137
phenaproximaPatch rerolled with invaluable assistance from @grom358.
Comment #138
grom358 CreditAttribution: grom358 commentedSetting status to needs review so bot tests rerolled patch.
Comment #141
daffie CreditAttribution: daffie commentedComment #142
daffie CreditAttribution: daffie commentedComment #143
hussainwebComment #144
hussainwebComment #145
benjy CreditAttribution: benjy commentedTest request has been sent for #143, back to NW for #136
Comment #147
grom358 CreditAttribution: grom358 commented@benjy RE #136 what error do you get for BrowserTestBaseTest with SimpleTest UI? Haven't been able to get hold of you on IRC. What is your environment setup? Considering the UI and run-tests.sh call the same code for running the test, I thinking could be something around SIMPLETEST_BASEURL environment variable and so configuration doesn't come through correctly.
Porting of existing tests such as MigrateAggregatorConfigTest I want to make out of scope of this particular ticket. Once this test base is in, I was going to make a Meta and go from there so we can start phasing out SimpleTest. Having said that though, perhaps there is a bug with BrowserTestBase. BrowserTestBaseTest may need more test cases if so.
Comment #148
daffie CreditAttribution: daffie commentedIt all looks good to me.
The problem of @benjy that he cannot run his own migrated tests is something for a follow-up issue.
The patch adds the basic functionality to do functional testing. There is a basic test in the patch to prove that it works.
The patch adds a two new libraries to core: behat/mink and behat/mink-goutte-driver. These need a @Dries approval.
All documentation is in order.
It gets a RTBC from me.
Comment #149
alexpottNew libraries are for Dries to approve.
I'm extremely ++ to this change.
Comment #150
benjy CreditAttribution: benjy commented@daffie, no the screenshot showed the migrate test, the exact same problem also occurs with BrowserTestBaseTest as I mentioned in #136. (http://i.imgur.com/0yqzOXB.png)
Also, the issues from #133 still haven't been fixed either.
Comment #151
daffie CreditAttribution: daffie commented@benjy: Running the BrowserTestBaseTest is working for me. With run-tests.sh an with the SimpleTest UI. Did you try the suggestion of @grom358?
For #133.3 and #133.4: I think that those should be addressed in followups.
Comment #152
daffie CreditAttribution: daffie commentedApplied the requested changes from #133.1 and #133.2. The functions BrowserTestBaseTest::setup and BrowserTestBaseTest::teardown are now protected.
Comment #153
benjy CreditAttribution: benjy commented@daffie, awesome thanks for making those changes.
@grom358 didn't offer any possible solutions only a suggestion that it might be SIMPLETEST_BASEURL. We discussed this in IRC earlier today, it dies early in the installation process, I said I would try to debug this further. I use the UI for running tests every day and i've never had the install fail like this with WebTestBase.
I tested this in a container and the test passes, the problem is when you have Drupal installed in a sub directory that the tests fail from the UI.
Comment #154
daffie CreditAttribution: daffie commented@benjy: Do you have any objections on putting this issue back to RTBC?
Comment #155
ParisLiakos CreditAttribution: ParisLiakos commentedI have it installed in a subdirectory but the test passes for me. Probably the problem is too localized to hold up this issue
Comment #156
alexpottSo this works for me in a sub directory - through the UI, run-tests, and phpUnit.
Obviously we have a massive regression wrt to the output that is available to the user through both phpUnit and run-tests / Simpletest UI. We now longer see the pages if verbose is on etc. However trying to implement all of that is step 1 is unrealistic and will hinder rather than help effort. What this does mean is that no Simpletests should be converted until we have a way to achieve feature parity (and hopefully enhancements).
Comment #157
alexpottBefore assigning this issue to Dries again it'd be great it someone can update the issue summary to reflect the patch and sell the vision.
Comment #158
lokapujyaI had to hardcode the SIMPLETEST_BASEURL and run phpunit from d8/core and as an admin(well I added _www to the admin group) to get phpunit to work from command line. So, I tried hardcoding the $phpunit_bin to a relative path like this: "./vendor/bin/phpunit" (since it works like that from command line) and I still get the same error as benjy running from UI.
Comment #159
larowlanAdded some sizzle to the issue summary
Comment #160
larowlanAs per #157
Comment #161
daffie CreditAttribution: daffie commentedIt all looks good to me.
The patch adds the basic functionality to do functional testing. There is a basic test in the patch to prove that it works.
The patch adds a two new libraries to core: behat/mink and behat/mink-goutte-driver. These need a @Dries approval.
All documentation is in order.
I know that you are not allowed to give your own patch a RTBC, but my change is so minor that I think that it is allowed. So it gets a RTBC from me.
Comment #162
benjy CreditAttribution: benjy commentedIn that case, +1 for RTBC.
Comment #163
alexpottWe have a problem with using
Drupal\Tests\
as a namespace start. At the moment this is used inTestDiscovery::getTestInfo
to assign the group if it is a PHPUnit test. Whilst in some ways this is not wrong, it is a PHPUnit test, I don't think it is correct.I think we should add a new namespace to help us determine what type the test is. We can not use reflection here because we have too many tests - a good problem to have. See #2422019: Don't use reflection for parsing test annotations for more.
Can we get a code comment about the fact that WebTestBase tests are still the way to do functional testing that requires a browser as we've not achieved feature parity yet.
Comment #164
grom358 CreditAttribution: grom358 commented@lokapujya and @benjy I would like to fix this issue having... unfortunately I haven't been able to replicate it yet. Until then its very hard for me to fix the issue.
If you could debug and find the point it breaks that maybe might make me dig into the code at the point on possible causes.
@alexpott in addition to no verbose output (which I already have ideas on how to add), the other issue is Goutte driver also doesn't do AJAX requests where Simpletest has some implementation that mimics what the javascript code does. This is just a driver issue though and be solved by new Drupal CI being worked on.
Comment #165
daffie CreditAttribution: daffie commentedFor #163.1: All tests in the namespace "Drupal\Tests\" are now grouped together in the group "PHPUnit". I think that that grouping is wrong. The more PHPUnit tests are added the bigger that group will get. Tests need to be grouped for what they tests and not how they are tested. A PHPUnit test that tests some block functionality needs to be grouped in the group "block" and not in "PHPUnit".
With that in mind I think that the problem is in the grouping and not the namespace that this patch is using.
User @grom358 addressed #163.2. So for me the issue can go back to RTBC.
@alexpott do you have any objections for setting this issue back to RTBC?
Comment #166
tstoecklerThe subdirectories between
$modulename/tests/src
where we currently only haveUnit
where originally envisioned to become separate PHPUnit test suites. Regardless, I think - in lou of a real Simpletest UI revamp - it would at least make sense to make the "test suite name" part of the group as it shows up in the Simpletest UI. I.e. what is now PHPUnit would become PHPUnit: Unit tests and then with this patch we would also have PHPUnit: Functional tests. Or maybe just Unit and Functional, but you get the idea. I think that would solve @alexpott's concerns and also be fairly easy to implement without postponing this further on improvements to the Simpletest UI.Comment #167
daffie CreditAttribution: daffie commentedI created #2427191: Test-runner ignores @group annotations for PHPUnit-based tests in modules. for solving the grouping of PHPUnit tests.
Comment #168
alexpott#167 / #2427191: Test-runner ignores @group annotations for PHPUnit-based tests in modules. is a sort of duplicate of #2301481: Mark test groups as belonging to modules in UI
Comment #169
alexpottThe groups not only affect the simpletest UI but also run-tests.sh
Comment #170
tstoecklerRe #169: Right, good point!
Comment #171
daffie CreditAttribution: daffie commentedCan someone explain why that is important? With run-tests.sh you can also test as a group. The same as with the simpletest UI.
Comment #172
lokapujyaI think I discovered the cause the webUI problem. phpunit was working from run-tests.sh, but not from webUI. Running on a mac. The tests are both run as the same user so you would think that if CL works that webUI should work.
In addition to the other things in #158, I hardcoded an export path command into the exec() before calling phpunit so that the webUI uses the same path as the CL. Now my webUI tests seem to be working.
So in simpletest_phpunit_run_command(), I had to do this:
$setpath = 'export PATH=[MY PATH FROM COMMAND LINE]';
$ret = exec($setpath.$the_command, $output);
Comment #173
alexpottOnly modules can have functional tests? Also won't the unit test suite also contain the functional test suite?
Comment #174
daffie CreditAttribution: daffie commentedTalked to @dawehner on IRC. He wanted the private functions BrowserTestBase::changeDatabasePrefix() and BrowserTestBase::prepareDatabasePrefix() made protected.
Comment #175
alexpottTestDiscovery::registerTestNamespaces()
.It is a shame that
./core/tests/Drupal/Tests
is not./core/tests/Drupal/Unit
or./core/tests/Drupal/Tests/Unit
but changing that now would be painful and very disruptive.[Edit: completed sentence]
Comment #177
daffie CreditAttribution: daffie commentedLooks good to me.
Do we need these two lines in <testsuite name="functional">. With Functional instead of Unit?
Comment #178
alexpottre #177
That fail is real shame - it works locally for me. How to debug that... not sure atm.
Comment #179
benjy CreditAttribution: benjy commentedWhile there is some re-rolling going on, i've noticed it mentioned three times in this issue but no answer or response from what I can tell:
Why do we need these?
Comment #180
grom358 CreditAttribution: grom358 commented@benjy you are correct. That question has not been addressed yet.
Comment #181
larowlanThe reasoning was that phpunit loads the actual files during discovery and hence the unit test suite has some instances where these are (hackily) declared to ensure they pass.
When we get to functional tests we bootstrap drupal, and hence some of the earlier unit tests might have already declared these.
It might not be a problem any more with separate test suites.
Comment #182
daffie CreditAttribution: daffie commentedWhats needs to be done for this issue
These two changes need to be removed from the patch. See comment #181.
These two lines are also needed in the new testsuite named "functional". With one minor change. See comment #177.
Who will help?
After these changes will I do a good review.
Comment #183
alexpott@daffie fixing #182.2 will break running tests in you just run all the phpunit tests. Splitting them into testsuites does not fix that.
The biggest problem we have is that the test running the new functional test through the UI fails. In fact we've managed to reproduce @benjy's problems on testbot. It is working through run-tests.sh but not the UI.
Comment #184
alexpottRe ##182.1 BrowserTestBase is just following TestBase - I think this is fine and the methods should remain private.
Comment #185
alexpottActually wrt. to #183 and #182.2 this problem is pretty insurmountable as long as we allow side effects in unit tests. if I run all the tests together then I get...
So the long and the short of it is that we need to run the functional and unit test suites completely separately right now.
Comment #186
alexpottI've done some testing in #2095771: alexpott's test issue - something is failing in BrowserTestBase::setUp pretty hard. Basically we're getting no test results when we try to run the test through the simpletest ui. Using exceptions I've proved that
SIMPLETEST_BASE_URL
is fine both when run from run-tests.sh and from the UI. And the error occurs somewhere between the check thatSIMPLETEST_BASE_URL
is set and the first drupalGet() in BrowserTestBaseTest. So it must be set up - but what? atm no idea.The quickest way to find out would be to work with @`basic or @isntall to get access to the testbot logs whilst running the patch in https://www.drupal.org/node/2095771#comment-9640255 - but they are busy people.
Comment #187
daffie CreditAttribution: daffie commentedDid some work with the testbot. The error that I got from the testbot is:
Hopefully this is helpful to some testbot guru. :)
Comment #188
Dries CreditAttribution: Dries commentedI think this is a good idea but I'm worried that it introduces a lot of distractions (people will have to learn about this tool, people will be inclined to rewrite existing tests, etc). In the end, I think the impact is bigger than the disruption so let's go ahead and commit it. But please, let's not embark on a whole-scale conversion of existing tests until after 8.0. Let's just use it for things we couldn't test before. Can we agree on that?
Comment #189
daffie CreditAttribution: daffie commented@Dries: Can we start whole-scale conversing in 8.1 or do you want to wait for 9.0?
Comment #190
webchick8.1.x would be fine. Tests aren't part of the public API.
Comment #191
daffie CreditAttribution: daffie commented+1. Then I can completely agree with Dries' proposal.
Comment #192
daffie CreditAttribution: daffie commentedSome observations after testing:
Comment #193
daffie CreditAttribution: daffie commentedWhen #2363341: Throw exception in Drupal::service() and friends, if container not initialized yet. lands the patch needs updating.
Comment #194
alexpottJust learnt about
@runTestsInSeparateProcesses
all functional tests are going to need that otherwise we'll have problems with running multiple functional tests using the phpunit command. Also we should open an issue to add that tag to all phpunit tests which add functions to the global namespace. See https://phpunit.de/manual/current/en/appendixes.annotations.html#appendi... for more.Comment #195
larowlanalexpott++ that is the secret sauce
Comment #196
alexpott@daffie pointed out that when the parent site was not installed the functional test was failing! So we need to somehow get the db connection in the phpunit environment.
Comment #198
daffie CreditAttribution: daffie commentedThe tests with no parent site are failing for me.
I made two changes:
Changed this line to
\Drupal::unsetContainer();
.Part of #2363341: Throw exception in Drupal::service() and friends, if container not initialized yet..
Lets try again!
Comment #199
daffie CreditAttribution: daffie commentedI am not sure what the exact namespace is for a Wobbly. So I am changing it to throw an InvalidArgumentException. :)
Comment #200
daffie CreditAttribution: daffie commentedThe last two patches are mine. But the changes are very small.
It all looks good to me.
All documentation is in order.
There are two new libraries in this patch. We have a Dries okay for that.
The testbot gives it all right.
So it gets a RTBC from me.
Comment #201
daffie CreditAttribution: daffie commentedAdded alexpott to the suggested commit message.
Comment #202
daffie CreditAttribution: daffie commentedOpps wrong patch. Should have removed this part earlier:
Comment #203
daffie CreditAttribution: daffie commentedThe last two patches are mine. But the changes are very small.
It all looks good to me.
All documentation is in order.
There are two new libraries in this patch. We have a Dries okay for that.
The testbot gives it all right.
So it gets a RTBC from me.
Comment #204
alexpottI think we should create a separate issue to add the vendor components. We can get that committed now that we have approval from Dries and then the patch on this issue becomes more reviewable.
I think we need at least some discussion of the solution to the problem. Adding database parameters to an environmental variable is kinda icky.
[Edit: for some unknown reason I asked @daffie to create the new issue - of course anyone can do it :)]
Comment #205
phenaproximaCreated a sub-issue. (This is the first issue I've filed in core, so I apologize if anything is missing from it.)
Comment #206
hussainweb@phenaproxima: Thanks for creating the issue. I just tweaked the IS a little bit. It was all good. :)
The patch is there in #2433009: Add Mink, with Goutte driver, to core and under tests. I don't expect it to fail. We can come back to this as soon as that goes in?
Comment #207
daffie CreditAttribution: daffie commentedOn getting the libraries
behat/mink
andbehat/mink-goutte-driver
committed in #2433009: Add Mink, with Goutte driver, to core.Comment #208
daffie CreditAttribution: daffie commentedIn the current patch is the settings.php file first checked to see if there are database connections. If there are none then the script will look if there is a script argument dburl. This is of course the wrong sequence.
This patch should test green after #2433009: Add Mink, with Goutte driver, to core lands.
Comment #209
alexpott@daffie I debated #208 when I wrote the code. Reading run-tests.sh I now think you've got it right...
Comment #210
alexpottThis should not be added here then since this is done later. This means that "simpletest_original_default" connection is then correct.
Comment #211
daffie CreditAttribution: daffie commented#2433009: Add Mink, with Goutte driver, to core has landed.
Comment #213
daffie CreditAttribution: daffie commentedChanges:
Comment #214
alexpottI think we should encapsulate this on the database class or some other and also the code in run-tests.sh that does the of this opposite code .
Comment #215
alexpottThis is the same code as we have in run-tests.sh too :)
Comment #216
daffie CreditAttribution: daffie commented@alexpott: I understand your willingness to combine similar code into a single implementation. The problem as far as I can see is as follows:
Comment #217
alexpott@daffie the patch attached is what I was getting at. Manipulating database connection info is the responsibility of the Database class not run-tests or browsertestbase or simpletest.module.
Comment #218
alexpottLet's keep
DRUPAL_ROOT
out of theDatabase
class.Comment #219
neclimdulThe --dburl part of this exception should only live in run-test. This is a problem in both versions of the patch.
Comment #220
alexpott@neclimdul nice catch. Now who wants to write some nice unit tests for these methods... actually that could be a nice followup.
Comment #221
daffie CreditAttribution: daffie commentedFollowup for #220 is created: #2434567: Create PHPUnit tests for Database::convertDbUrlToConnectionInfo() and Database::getConnectionInfoAsUrl().
Comment #222
alexpottCouple of minor things I noticed whilst reviewing the patch.
Comment #223
webchick#2433009: Add Mink, with Goutte driver, to core has now re-landed. :)
Comment #224
pfrenssenFinally found the time to review this in earnest. I reviewed everything in detail except WebAssert, BrowserTestBaseTest, and a part of BrowserTestBase (got up to GetRandomGenerator()). I have no time left unfortunately. Hopefully I can continue the review tomorrow.
This documentation could use an update. It only mentions detecting a test run by checking the user agent, but we can now also indicate a test run by setting a cookie.
It's interesting to document this because this change now allows third party test frameworks to make use of test diagnostics such as reporting of PHP errors.
Maybe 'SIMPLETEST_USER_AGENT' is not the best name for this cookie, especially since it will not even be used by Simpletest, but only by Mink, and in the future by Behat.
I guess this is chosen to be consistent with the regex check on the user agent. We cannot change the contents of the user agent anyway since this would be an API change.
It would be good to rename this cookie and user agent string for D9.
Can we get a bit of documentation to explain this weird "strip the leading slash and then check if we have another leading slash and are using SQLite" logic?
This code has been factored out from the
run-tests.sh
script. In that script this is explained in the documentation for the--db-url
option: this allows to make a distinction between relative and absolute paths for SQLite databases. However now that this code is divorced fromrun-tests.sh
it is no longer clear.Set (-the +)up an environment
"typical Drupal tests" lol?
@var int
@var \Drupal\Core\Session\UserSession
@var array
@var \Behat\Mink\Mink
These outer parentheses are useless.
This doesn't seem to be needed. When $path is set the trailing slashes are trimmed with rtrim(), so it will never contain '/'.
Both of these calls to trim() do not need the ' ' argument, by default trim() will strip whitespace.
This reads a bit strange. Better is "(optional) Name of the session. Defaults to the active session."
This is not a session object. Maybe just say "Returns Mink assert object".
Not strictly the internal browser as was the case with Simpletest. This may well be an external browser controlled via Selenium web driver.
Also missing period.
The else is not needed, just return FALSE.
YES!!!!
Not the internal browser, the Mink browser.
If we are using double quotes you can put the $form_html_id variable inline, no need to concatenate the different parts of the string.
@param \Behat\Mink\Element\NodeElement
@param \Behat\Mink\Element\Element
Is this method needed at all? The parent method also will call $this->createResult() if $result is NULL.
This is a duplicate of randomMachineName(). I would suggest to remove this and keep randomMachineName().
Coding standards: use 'elseif' instead of 'else if'.
Missing period.
This is duplicating code, we can put the different tests in an array and loop over it.
The documentation of this method also needs to be updated.
Comment #225
pfrenssenContinued review:
This call to
error_log()
seems to be debugging cruft.This method is now called by
BrowserTestBase::setUp()
.This gives
$this->drupalPostForm()
as an example but we won't be using this any more. The new method is called$this->submitForm()
.Let's add a type hint to $account.
This is optional and defaults to the current page. Wouldn't be bad to mention this since this will be the example that all upcoming test methods will be based on.
Very minor but Yoda conditions are nowhere else used in D8 core.
We usually say "Contains..." and not "Definition of...".
Is this "@modern" group intentional, or is this a leftover from debugging?
SWEET!!!
Comment #226
daffie CreditAttribution: daffie commentedThank you for the extensive review pfrenssen!
I have tried to make an interdiff.txt file, but I did not succeed. :(
Comment #227
daffie CreditAttribution: daffie commentedFor the testbot.
Comment #228
pfrenssenHere's the interdiff between #222 and #226.
Off-topic: you can generate these interdiffs easily if you create a branch before you start working:
In case you want to generate an interdiff between two patches, just make a branch for each patch and generate the diff between them:
Comment #229
daffie CreditAttribution: daffie commented@pfrenssen: Thank you for explaining. Going to use git to make interdiffs in the future. I was only using the interdiff command.
Comment #230
pfrenssenLet's explain the 'why' rather than the 'how'. Maybe something like this:
"A valid Simpletest request will contain a hashed and salted authentication code. Check if this code is present in a cookie or custom user agent string."
It's special in that it supports both relative and absolute paths, these are indicated by a leading slash. See the examples in the documentation for the '--dburl' parameter in run-tests.sh.
Maybe this would be better:
"A SQLite database path with two leading slashes indicates a system path. Otherwise the path is relative to the Drupal root."
By changing this logic it is now no longer possible to use double slashes to provide a system path.
For example if I run the tests with the option '--dburl sqlite://localhost//home/pieter/db.sql' then the database path is now invalid since it will be prefixed with the Drupal root path.
The original logic was correct but just needed to have some documentation to explain the strange business with the double slashes.
Typo: "controlled" instead of "controled".
Typo "controlled".
Typo "controlled".
Typo "controlled".
Comment #231
pfrenssenIf people have trouble running the tests through PHPUnit, you need to set the environment variable and run the tests as your webserver user. For example if your base URL is 'http://drupal.local' and your webserver runs as the user 'www-data':
Comment #232
daffie CreditAttribution: daffie commentedThank you again for the reviewing pfrenssen.
Comment #233
pfrenssenThanks! I reviewed the interdiff and my remarks have all been addressed. This looks to be near completion.
I want to do a few final tests before signing off on this: seeing that the patch in #226 was green despite having broken SQLite support I want to test it with a SQLite database passed as relative and absolute path in run-tests.sh, and I would like to test it without having a preinstalled Drupal installation (using the --sqlite option). Adding SQLite test coverage for run-tests.sh is out of scope for this issue, but I want to at least try it out.
I also intend to do a final review of the entire patch.
Comment #234
pfrenssenManual SQLite tests pass without problems:
Comment #235
daffie CreditAttribution: daffie commentedThere is no SQLite support before #2318191: [meta] Database tests fail on SQLite lands.
Comment #236
pfrenssenI ran this through its paces extensively. I encountered two problems but both are out of scope: test failures messages are not displayed when running the tests through the Simpletest UI, and for some bizarre reason when I enable xdebug the tests finish in a split second and always return green. Without debugger they run fine, and I can debug normal Simpletests without problems. But not BrowserTestBaseTest :-/
I also reviewed the code again and checked coding standards with PHPCodeSniffer. Made some updates to documentation and applied coding standards fixes. Did not touch the code, so I can still RTBC this.
The patch looks ready to me.
Leaving on "Needs review" since we still need to update the issue summary and write a change record.
Comment #237
pfrenssenComment #238
larowlanTagging for DrupalSouth and added tasks
Comment #239
pfrenssenAdded beta phase evaluation.
Comment #240
pfrenssenBrought issue summary up to the current state. Will start on the change record now.
Comment #241
alexpottGiven this code I think @pfrenssen's xdebug problems need further investigation.
Also we are not going to be telling anyone to use BrowserTestBase tests atm so please no change record yet. Nothing has changed - if you want to do functional testing you should still be writing simpletest tests. This is step 1.
Comment #242
pfrenssen@alexpott, this part of the code is not the cause of on my inability to debug these tests. Once I enable my debugger all PHPUnit tests are skipped, the test's
setup()
methods are not even running. I did not look into it since I was testing on my arch linux system which is running the very latest versions of all software packages. It's not unusual for me to encounter weird incompatibilities that are then solved a few days later. I will dig a bit deeper tomorrow and try to find the real cause.I had already started on the change record, will post my work in progress here so it can perhaps be used as inspiration later:
Comment #243
pfrenssenRemoved contributor task to write a change record.
Comment #244
daffie CreditAttribution: daffie commentedPutting it back to "need review".
Comment #245
pfrenssenAm back from holiday and have been looking into the Xdebug problem.
With the latest Xdebug 2.3.2 on PHP 5.6.6 the problem still occurs: when I enable the Xdebug listener in PHPStorm and start the PHPUnit tests then the tests finish instantly and are always green. What is interesting is that if I am not listening on the Xdebug port the tests work fine. I am using the option
xdebug.remote_autostart
so an Xdebug session should always be present with every request.I updated PHPUnit to 4.4.4 but this did not help.
I started downgrading to older versions of PHP and Xdebug and apparently it only happens on PHP 5.6, once I get down to PHP 5.5 I can debug again:
It seems like this issue is not to blame, but rather the problem seems to be with Xdebug on PHP 5.6. I'll start digging to see if I can pinpoint where exactly it goes wrong.
Comment #246
alexpottSo I think we have an @pfrenssen environment issue. I can run PHPUnit with xdebug on all of those PHP version. I don't use
xdebug.remote_autostart
Added #2459155: Remove REQUEST_TIME from bootstrap.php to deal with REQUEST_TIME
Comment #247
mpdonadioPer http://xdebug.org/docs/all_settings, the default value for xdebug.remote_autostart is 0, which may limit the impact of the problem.
Comment #248
pfrenssenThat setting doesn't change anything for me, if I turn
xdebug.remote_autostart
off and start the debugging session manually the problem still occurs.I have been reviewing the build options of PHP and Xdebug on Arch Linux but I do not see anything out of the ordinary. It is built from source with generic options. I tried with and without profiling (option
xdebug.coverage_enable
) but this does not change anything.I am using the following extensions:
I can replicate the problem using this command, note that my web server runs as the user "http":
sudo -u http SIMPLETEST_BASE_URL=http://drupal.local/drupal ./vendor/bin/phpunit --testsuite functional
Or, with
xdebug.remote_autostart
disabled:sudo -u http XDEBUG_CONFIG="idekey=PHPSTORM" SIMPLETEST_BASE_URL=http://drupal.local/drupal ./vendor/bin/phpunit --testsuite functional
When I enable the listener in PHPStorm the tests finish instantly which isn't normal, it should run around a minute or so.
Comment #249
pfrenssenAnyway since this debugging problem is unique to my environment this shouldn't hold up this issue any more. I was already satisfied with the state of the patch in comment #236. The issue summary has been updated and a change record is not needed as per #241.
This means this is ready!!
Comment #250
alexpottLet's wait for #2459155: Remove REQUEST_TIME from bootstrap.php so we don't have to do the define wrapping.
Comment #251
pfrenssenPostponing on #2459155: Remove REQUEST_TIME from bootstrap.php.
I have tested it in combination with that issue and it works perfect. I had to solve a merge conflict, am uploading the rerolled patch so we do not have to fix this again once #2459155: Remove REQUEST_TIME from bootstrap.php is in.
Note that this will fail now, but once #2459155: Remove REQUEST_TIME from bootstrap.php is in this can be retested and should turn green.
Comment #252
pfrenssen#2459155: Remove REQUEST_TIME from bootstrap.php is in!
Comment #254
pfrenssenRebased on latest HEAD.
Comment #255
pfrenssen... and removed the
if(!defined('REQUEST_TIME'))
wrapper.Comment #256
pfrenssenBack to RTBC.
Comment #257
alexpottIs this actually necessary? And if so why?
Comment #258
pfrenssenNo that shouldn't be needed.
Comment #259
pfrenssenComment #260
alexpottWe need another annotation to allow all PHPUnit test suites to run at the same time. See https://phpunit.de/manual/current/en/appendixes.annotations.html#appendi...
Now if you have
SIMPLETEST_BASE_URL
andSIMPLETEST_DB
this will run all the tests.Patch also improves error messages and removes usage of
Drupal\Component\Utility\String
Before this patch if phpunit and the webserver were being run by the different users you would see the following error:
With the new patch:
Comment #261
pfrenssenThis was confusing me but it appears this is missing from the interdiff. Here's the complete interdiff between #258 and #260.
Comment #262
pfrenssenThis is indeed needed, we want to run our entire PHPUnit test suite in one go on the test bots, and without disabling
@preserveGlobalState
we would get notices about constants that are already defined.WIth that annotation in place I am able to successfully run the entire suite:
SIMPLETEST_DB
, and remove my database credentials fromsettings.php
, then I get the helpful error message that I need to setSIMPLETEST_DB
. Since it would otherwise not be obvious what the problem is this is a very nice addition.String
class is deprecated because it will become a reserved keyword in PHP7. The environment variables are now suggested rather than having garbage defaults.Thanks a lot @alexpott! This looks really good now.
Comment #263
grom358 CreditAttribution: grom358 commented@alexpott and @pfrenssen I haven't gotten back to this issue in awhile. Good to see people are still keeping this patch going. In regards to comment #257 I think that had something todo with earlier on during test detection it would try to define that constant again when BrowserTestBase bootstrap after having ran a unit test that defined that constant. So probably unnecessary now and if I recall correctly DRUPAL_ROOT has largely been replaced with asking the container for the drupal root instead of global constant.
Comment #264
Wim LeersThe notes in #262 are extremely helpful and make me go into "can't wait to use this" mode :)
Comment #265
alexpott@Wim Leers - a note of caution about the
This is step 1 - we need to lots of work integrating how we report test results into our existing test infra.
Comment #266
alexpottI think it is acceptable for me to commit this patch because I have written very little of it. My contributions have been tidying up around the edges - for example ensuring that running PHPUnit from the CLI works as expected and reports good errors when it does not. I've also ensured that this patch does not make unnecessary changes to runtime code. Also this is the first step - we have some ways to go before we can deprecate simpletest and use this to replace that - let's get on with that. The dream of javascript testing and decoupling our tests from code using behat is extremely worthwhile and there is no point being held up on step 1.
Committed 300f14e and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to issue summary.
Comment #268
XanoI'd like to thank the contributors to this issue for all their time and efforts :) I've only lurked here, but enough to realize it's been a lot of work getting this into core.
Comment #269
phenaproximaI second #268. Congratulations to everyone who worked on this patch!
Comment #270
jibranThis is a start now we need a big big meta issue to convert all the WebTest to BrowserTest.
Comment #271
fagoWow, that's really great. However, it's left a bit unclear now what this means for people writing functional tests. Should they use the new test base class, or is it likely you run into problems. When would you use it and when not? Are there any docs to help picking the right test base class?
Comment #272
jibranThis might help you https://www.previousnext.com.au/blog/drupal-testing-roadmap.
Comment #273
chx CreditAttribution: chx commentedShould've been postponed to Drupal 8.1. This is a feature.
Edit: or at least BrowserTestBase and WebTestBase needs documentation to very very clearly tell people which one to implement.
Comment #274
larowlanQuoting Dries at #188
So you can use it in contrib if you like, but not in core until 8.1.
Comment #275
larowlanOh and to @grom358, @daffie, @alexpott, @pfrenssen, @hussainweb, @pcambra, @jibran, @phenaproxima, @moshe weitzman, @nick_schuch and @benjy - thanks for all your work on this - see you over in #2469713: Step 2: Create a JavaScriptTestBase using PhantomJs Driver/Binary
Comment #276
chx CreditAttribution: chx commentedor at least BrowserTestBase and WebTestBase needs documentation to very very clearly tell people which one to implement.
There is 0 documentation to this extent. I am sorry for not reading a 200+ comment issue throughly.
Comment #277
larowlanAnd in #2469717: Step 3: Create a KernelWebTestBase base class/driver
Comment #278
larowlan/me starts on change record for this issue
Comment #279
larowlanOpened #2469721: Add functionality to store browser output to BrowserTestBase for verbose output
Comment #280
larowlanDraft change record is here https://www.drupal.org/node/2469723 - could someone please review?
Comment #281
chx CreditAttribution: chx commentedCritical doxygen issue filed at #2469731: Document when to use BrowserTestBase.
Comment #282
nick_schuch CreditAttribution: nick_schuch commentedDraft change record looks good @larowlan!
Comment #283
jibranI published the change notice. Maybe we can add some thing related ajax form post methods as well.
Comment #284
larowlanThere are no Ajax form methods until step 2. I will add that to the feature parity section of the change notice.
Comment #285
RoySegall CreditAttribution: RoySegall commentedWell... There is a couple of things that this patch don't prove or missing:
1. There is no option to log events during the tests. For example if i'm using the assertSame method the message argument is missing from the test results.
2. When i use the debug function to debug variables then the tests is failing.
Someone else has also got this issue?
Comment #286
larowlan1. Can you open a follow up?
2. debug() calls trigger_error() so without the
set_error_handler
logic in the Simpletest runner to catch and log these - its phpunit, you can just print the output or use xdebug to set a breakpoint in the runner. If you're calling debug() in the child site (not the runner) and its causing failures, then that is an issue - can you open a follow up?We don't have feature parity with WebTestBase yet.
Comment #287
RoySegall CreditAttribution: RoySegall commented1. Yeah sure, i'll open one.
2. No, i don't have a debug inside the site only through the test methods but it's worth checking.
Comment #288
neclimdulSorry for the post commit review but was there a reason this went into core/modules/simpletest/src instead of /core/tests/Drupal/* ? I don't see any connection to simpletest other then the environment variables.
Comment #289
larowlan@neclimdul, happy for a follow up to move, can't recall there being any reason
Comment #290
neclimdulThat's what I figured but I wanted to check first. A bit bare but follow up created. #2473269: Move Mink BrowserTestBase classes into Drupal\Tests
Comment #291
Fabianx CreditAttribution: Fabianx commentedSo I have a new concern with using phpunit to run this new BrowserTestBase:
So far the distinction was pretty clear:
- phpunit - fast, easy, isolated tests -- run before each commit
- junit - fast simple JS tests, tests behavior of one class - run before committing JS code
- mink - JS tests often operating on simple pre-made pages integrating several complex JS together.
- simpletest - Database driven integration tests, let testbot / test engine / jenkins run those, sometimes run locally, quite slow
- behat - behavior driven very slow web tests with full integration, tests mainly behaviors that are specified by a customer.
--
Now if I run phpunit I suddenly startup simpletest, have to set a SIMPLETEST_BASE_URL and need to deal with users, etc.
Also the runs take suddenly 1.02 minutes and 172 MB instead of several seconds before ...
Unit tests _need_ to be fast.
Can we perhaps make a follow-up that if SIMPLETEST_BASE_URL is not set, we don't do all the slow things and just issue a warning or ignore instead of an error?
That would be great ...
Comment #292
dawehnerIts a common misconception that phpunit === unit tests, I would see phpunit as a testing framework, given that it also powers behat under the hood.
Phpunit itself already has the abstraction of testgroups, of we have two now:
and once #2304461: KernelTestBaseTNG™ is in, we have a third one.
Comment #293
Fabianx CreditAttribution: Fabianx commented#292: Oh thank you!
That is great and I did not know.
Can we update the change notice with that, please?
Thanks!
Comment #294
znerol CreditAttribution: znerol commentedFollow-up: #2478167: Generate proper value for sessionName property in BrowserTestBase
Comment #295
Mile23Follow-up dealing with SIMPLETEST_BASE_URL: #2478247: SIMPLETEST_BASE_URL is an environmental requirement which should not fail tests
Comment #297
jibranCreated #2503547: Contrib can't run Functional tests.
Comment #298
klausiLet's start the conversion: #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)