Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We do not have test coverage of the Simpletest UI - we should test sessions and logging in a Webtestbase, and running KernalTestBase and PHPUnit tests so we don't break it (whilst we have a UI).
Proposed resolution
Add test coverage and fix PHPUnit tests.
This patch:
- extends SimpleTestTest::stubTest() to also test user logging in thereby testing the browser and session system when testing through the UI
- tests running KernalTestBase through the UI (this was broken for months due to sessions bleeding from the parent enviroment)
- fixes and tests running PHPUnit through the UI
- makes SimpleTestTest a bit simpler to understand by moving tests that are not run in the test in test to another test.
Remaining tasks
Review patch.
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#23 | 2272879-tolboom.22.patch | 18.75 KB | alexpott |
#19 | interdiff-2272879-13-19.txt | 3.81 KB | clemens.tolboom |
#19 | can_not_run_a-2272879-19.patch | 18.74 KB | clemens.tolboom |
#15 | can_not_run_a-2272879-15.patch | 18.14 KB | clemens.tolboom |
#14 | can_not_run_a-2272879-14.patch | 11.87 KB | clemens.tolboom |
Comments
Comment #1
alexpottSo the error in the web test is "file_get_contents(/Volumes/devdisk/dev/sites/drupal8alt.dev/sites/simpletest/254593/.htkey): failed to open stream: No such file or directory" which seems like we fail to properly set up a webtest once we're inside a webtest.
The patch attached shows just how messed up things currently are.
Comment #2
alexpottThe patch attached fixes running webtestbase tests from the UI in a webtestbase - aka testception :)
We need #2239969: Session of (UI) test runner leaks into web tests in order to fix KernelTestBase tests - but that patch broke WebTestBase testing in the UI so I suggest we commit this one before that.
Comment #5
alexpottComment #6
sun1. Web tests are covered by
SimpleTestTest
already.2. If those changes to
drupal_generate_test_ua()
are actually relevant in any way, then that (whichever?) edge-case MUST trigger a fatal error (by throwing an uncaught exception, whatever).3. In short, the proposed patch looks very dubious to me. The
drupal_generate_test_ua()
/drupal_valid_test_ua()
logic was and is invoked in a very controlled way. There MAY be bugs in the (dated) UI test runner, but not in this code.The code explicitly prevents any further code execution in case conditions are not met. In case that logic was muddied through follow-up patches that I'm not aware of, then we have a much larger (security) problem.
Comment #8
alexpottWell the SimpletestTest::stubTest never tests making a call to anything that makes a request and this is exactly what was broken in #2239969: Session of (UI) test runner leaks into web tests so our test coverage is not enough.
In fact the SimpleTestTest is a mess - the test methods testInternalBrowser() and testUserAgentValidation() should not be in there since they impact the output of stubTest() that is run from testWebTestRunner() when we're in test inception. Having these additional do nothing test methods results in the child test running three test methods two of which do nothing accept print additional
Enabled modules: non_existent_module
messages.As you can see from the patches attached in #0 we have a problem using the internal browser once DRUPAL_TEST_IN_CHILD_SITE is set to TRUE (constants which change values - I always disliked that in the simpletest multisite patch). The moment we do a request to the internal browser it will fail - this is because we have a new database prefix but the code in drupal_generate_test_ua() makes it utterly impossible to generate a .htkey file for the child site.
It seems impossible for this exception to be thrown since drupal_valid_test_ua() is called with the child test prefix in TestBase::prepareEnvironment() - therefore the condition
$parent_prefix != $prefix
will never be met.I would argue that this method of test the test runner is completely false and overly complex to understand and very liable to produce false positives - for example at the moment we're not even testing the ability to enable modules successfully when running tests through the UI since the only thing in setUp that we do (when in a childsite) is enable a module that does not exist. It would be far more realistic to just run one of the thousands of tests we have.
The only advantage of
SimpleTestTest::testWebTestRunner()
andSimpleTestTest::stubTest()
is that it makes our assumptions clear. The 2272879.8.patch attached:BUT: I've attached 2272879-better.8.patch that does not generate the .htkey in from stubTest but includes the same fix as in #2 because I think this is the correct fix...
... since "this logic" Is directly responsible for this bug.
The better patch also includes a new test that just runs other tests - this would just fail if it was included in 2272879.8.patch.
Comment #9
alexpottComment #10
alexpottRerolled patch and we can now test both WebTestBase tests and KernelTestBase tests. Went for the option that is not change bootstrap.inc so that should make this patch acceptable to @sun - since test coverage of UI is more important.
Comment #12
alexpottOkay we need to add PHPUnit test coverage and there is no need to cover WebTestBase tests since this is already covered in SimpleTestTest through it's testception.
Test only patch available on #2306649: Running phpunit tests via the UI results in a fatal
Comment #13
m.stentaPatch in #12 worked for me!
Comment #14
clemens.tolboom1 space to many
Comment #15
clemens.tolboomI missed the new core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php completely :(
Comment #16
alexpottre #14
In my mind all the changes in the interdiff attached to #14 are out of scope since the
fail
andpass
properties were not added or changed by this patch but it improves test readability so I'm ok with it.Comment #17
alexpottComment #18
dawehnerso finally I have proper internet connection to post it.
Ha, so annoying that I though this is a feature ;)
Good idea!
let's directly fix the visiblity of the methods.
It would be great to move the comment below. The first is just about checking that the logout changes the UID as well.
undefined variables.
Comment #19
clemens.tolboomFixed issues from #18
Comment #20
vijaycs85+1 to get this in ASAP. This is really going to save my time...
meanwhile,
Step 1: Install drupal
Step 2: Enable debug to see what's wrong with admin/config/development/testing by http://drupal.stackexchange.com/questions/127182/how-to-enable-developer...
Step 3: Go to simpletest.module and make below change:
Comment #21
dawehnerLet's get it in!
Comment #23
alexpottrerolled - context conflict with #2322889: Various setUp() and tearDown() methods are not protected
Comment #24
webchickCommitted and pushed to 8.x. Thanks!