Problem/Motivation
We need to convert everything over to BrowserTestBase that needs converting, we need to deprecate everything that isn't already deprecated.
This is the big one, and should probably be postponed until all the other modules have been converted.
As much as possible, we want to leave tests which actually test WTB itself alone. They will eventually be removed as part of the simpletest module deprecation.
Tests which look at the behavior of the UI forms can be moved to functional BTB tests.
Proposed resolution
Add @group WebTestBase to tests of WTB so there is no confusion in the future.
Combine Drupal\simpletest\Tests\UiPhpUnitOutputTest and Drupal\simpletest\Tests\SimpleTestBrowserTest::testTestingThroughUI() into
Drupal\Tests\simpletest\Functional\SimpletestUiTest.
From #14:
@alexpott: I think we should also take opportunity to ensure that all the test coverage that we're not moving to phpunit has corresponding tests in phpunit.
I can't find the equivalent of \Drupal\simpletest\Tests\TimeZoneTest::testAccountTimeZones in BTB but I think there should be. So let's add that to \Drupal\FunctionalTests\BrowserTestBaseTest::testLocalTimeZone().Addressed in #15.Also we should have an equivalent of BrokenSetUpTest since what that is testing - that a broken setUp method doesn't completely delete your site is just as relevant for BTB as it is for simpletest.Follow-up: #2981870: Duplicate BrokenSetUpTest for BrowserTestBaseI agree \Drupal\simpletest\Tests\BrowserTest, \Drupal\simpletest\Tests\MissingCheckedRequirementsTest, \Drupal\simpletest\Tests\SimpleTestTest, \Drupal\simpletest\Tests\SkipRequiredModulesTest, and \Drupal\simpletest\Tests\WebTestBaseInstallTest don't need to be migrated.Each of those tests is tagged w/@group WebTestBase.I think we need to migrate the \Drupal\simpletest\Tests\SimpleTestBrowserTest::testUserAgentValidation() test as well as testTestingThroughUI() method. We use the same user agent protections in BTB. There are also assertions in \Drupal\simpletest\Tests\SimpleTestBrowserTest::testInternalBrowser() that should be in BTB about how we prevent access if .htkey is missing or incorrect.-- See #15 regardingtestTestingThroughUI().I think \Drupal\simpletest\Tests\SimpleTestInstallBatchTest should have a BTB equivalent.Addressed in #15.Do we have lower level testing of \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest?seetestGetTestsInProfiles
Remaining tasks
- #2942633: Move KernelTestBaseTest out of simpletest module
- #2981870: Duplicate BrokenSetUpTest for BrowserTestBase
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | 2932909-33.patch | 29.78 KB | lendude |
| #33 | interdiff-2932909-32-33.txt | 1.69 KB | lendude |
| #32 | interdiff-2932909.txt | 5.26 KB | dawehner |
| #32 | 2932909-32.patch | 30.76 KB | dawehner |
| #30 | interdiff-2932909.txt | 678 bytes | dawehner |
Comments
Comment #2
dawehnerGiven that we still need to maintain the simpletest UI for longer maybe it would make sense to copy these tests. This is just a random though which popped into my head.
Comment #4
mile23After some analysis, here's the result.
First, there's a KTB test hiding in there: #2942633: Move KernelTestBaseTest out of simpletest module
Most of the remaining WTB tests in simpletest module are tests of WTB or the UI form behavior.
Tests where we run tests through the form can be converted to BTB, which we should do because we might need the form into D9, tho likely not. #2750461: Remove Simpletest UI because we don't want to maintain a graphical test runner
The rest of the WTB tests can be left as-is, because the goal is to get rid of WTB. Some of the test class names are ambiguous, and really should be cleaned up so we know what they test, but that should be a very (VERY) low priority. For instance, there's
BrowserTestandSimpletestBrowserTest, which cover similar areas, but you couldn't tell what based on the class names.Attached is a patch which adds @groups to WTB tests and @todos for which tests/methods to move.
Updating IS.
Comment #5
mile23After some work, it turns out that
Drupal\simpletest\Tests\UiPhpUnitOutputTestis tricky as a BTB test. It callssimpletest_phpunit_run_command()which exec()s PHPUnit with--printer SimpletestUiPrinter. If you have your phpunit.xml set up to useHtmlOutputPrinter(which you should...), then PHPUnit will useHtmlOutputPrinterinstead, failing the test.So since this test is a WTB test, it bypasses all that by virtue of not running under PHPUnit. So we can't move it to be a BTB test without changing it radically.
But it turns out the reason for the test existing is to make sure the output from the test is filtered to have clickable URLs and so forth. This can be unit tested, so this patch adds the unit test of
SimpletestUiPrinter. If that's enough to replaceUiPhpUnitOutputTestthen we can remove it a future patch here.The rest is fairly straightforward.
Drupal\simpletest\Tests\SimpleTestBrowserTest::testTestingThroughUI()was loading the simpletest UI form twice per each test it ran, so that's about a minute and a half more than it needed. That's fixed.Comment #6
mile23Oh yeah, there's one other thing.
HtmlOutputPrinter(the Legacy one) didn't have the same constructor signature as the superclass.This woudn't matter for testing
SimpletestUiPrinterif we just mocked the class and bypassed the constructor. However, if you look atHtmlOutputPrinter(the not-Legacy one), you'll see that we use aclass_alias()to switch the namespace of the class before it's defined.I think this confuses the PHPUnit mocking system, because I was unable to mock
SimpletestUiPrinter, which inherits from one of these two classes, depending.So the easy solution is to just add all the constructor defaults, copied from the superclass and
newone into being.Comment #7
mile23Fixed CS and adds @covers annotation.
The question still remains from #5: We could just remove the UI test for the output printer, if we're OK with relying on the unit test. No harm in leaving it in, since it doesn't actually spend 20 seconds generating the test form or any such.
Comment #8
lendude@Mile23++, just some nits I see
nice destinction
Can just be {@inheritdoc}
Every method needs a docblock
About
\Drupal\simpletest\Tests\UiPhpUnitOutputTest, I agree that\Drupal\Tests\simpletest\Unit\SimpletestUiPrinterTestis a great minimal conversion. I think we should leave it in for now, the @group simpletest marks it as something we can remove once we remove simpletest, or should we look for something more distinctive to indicate this?Comment #9
mile23This is a good point, because some of these tests might belong in the tests/Drupal/Core/Tests directory or similar.
PhpUnitErrorTest,SimpletestPhpunitRunCommandTestshould be moved out of simpletest in #2641632: Refactor simpletest's *_phpunit_*() (and junit) functions etc. to a class, deprecateTestDiscoveryTestshould get moved in #2863055: Move TestDiscovery out of simpletest module, minimize dependenciesA few other tests don't deal directly with simpletest module concerns, so I've moved them to tests/ or the system module.
AssertContentTraitTestwas testing the deprecatedDrupal\simpletest\AssertContentTraitTestand now it's not.Someone might be counting on the simpletest group somewhere, and they'd get a false positive if these tests fail, so I left those in. We don't really gain anything by taking them out, and when we finally remove simpletest for real we can remove them.
Fixed nits, too.
Comment #10
borisson_This looks really solid.
Comment #11
larowlanAny reason why we don't just post all three at once?
Comment #12
mile23That test method is copied over verbatim from core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php. It seems like you'd want to know which test was the problem without spending time running the other two.
Comment #13
larowlanFair nuff
Comment #14
alexpottI think we should also take opportunity to ensure that all the test coverage that we're not moving to phpunit has corresponding tests in phpunit. I can't find the equivalent of \Drupal\simpletest\Tests\TimeZoneTest::testAccountTimeZones in BTB but I think there should be. So let's add that to \Drupal\FunctionalTests\BrowserTestBaseTest::testLocalTimeZone().
Also we should have an equivalent of BrokenSetUpTest since what that is testing - that a broken setUp method doesn't completely delete your site is just as relevant for BTB as it is for simpletest.
I agree \Drupal\simpletest\Tests\BrowserTest, \Drupal\simpletest\Tests\MissingCheckedRequirementsTest, \Drupal\simpletest\Tests\SimpleTestTest, \Drupal\simpletest\Tests\SkipRequiredModulesTest, and \Drupal\simpletest\Tests\WebTestBaseInstallTest don't need to be migrated.
I think we need to migrate the \Drupal\simpletest\Tests\SimpleTestBrowserTest::testUserAgentValidation() test as well as testTestingThroughUI() method. We use the same user agent protections in BTB. There are also assertions in \Drupal\simpletest\Tests\SimpleTestBrowserTest::testInternalBrowser() that should be in BTB about how we prevent access if .htkey is missing or incorrect.
I think \Drupal\simpletest\Tests\SimpleTestInstallBatchTest should have a BTB equivalent.
Do we have lower level testing of \Drupal\simpletest\Tests\InstallationProfileModuleTestsTest?
Comment #15
mile23Converting
SimpletestUiTest::testTestingThroughUI()to a BTB test will mean converting it within the simpletest module. That's fine if we're going to maintain the UI form beyond D9.0.0. So if we are going to maintain the UI form beyond D9.0.0, then we want to either replace or otherwise not deprecate the test runner it uses: #2748967: Trigger E_USER_DEPRECATED for BC support in simpletest_run_tests() #2750461: Remove Simpletest UI because we don't want to maintain a graphical test runnerWe duplicate
testAccountTimeZones()toBrowserTestBaseTestbecause we're checking BTB and WTB integrating withFunctionalTestSetupTrait.For the same reason,
SimpleTestInstallBatchTestgets left behind and we also addDrupal\FunctionalTests\Core\Test\ModuleInstallBatchTest. Both are tests of base classes usingFunctionalTestSetupTrait::installModulesFromClassProperty(). This requires moving simpletest_test module to test_batch_test under system module's fixture modules so it's not dependent on simpletest module.Still to do:
BrokenSetUpTest,testUserAgentValidation. ThetestInternalBrowserconversion will end up testing our mink integration.Comment #16
borisson_Based on that, I'm setting this issue back to needs work.
Comment #17
mile23BrokenSetUpTest, viaWebTestBase->isInChildSite(), relies on the behavior ofDrupalKernelto setDRUPAL_TEST_IN_CHILD_SITEwhich looks like this:So these things should happen here:
1) We should leave
BrokenSetUpTestwhere it is, annotated with@group WebTestBase, because it's a test of whether WTB throws an exception against the host site when using the Simpletest UI form. The last meaningful non-CS change was 2014: #2171683: Remove all Simpletest overrides and rely on native multi-site functionality instead BTB does not throw an exception in such a case.2) Factor that
DRUPAL_TEST_IN_CHILD_SITEbehavior out ofDrupalKernel::bootEnvironment(), into a separate method that we can deprecate along withWebTestBase: #2969741: Deprecate simpletest within DrupalKernel (DRUPAL_TEST_IN_CHILD_SITE)3) A little bit boggled that I can't find where anyone tested that
BrowserTestBase->setUp()/tearDown()doesn't demolish the host DB either. It doesn't help that many of these tests aren't named for the class they're testing. I think this should also be a follow-up, since there's no test to convert. I'm not filing it yet in hopes that someone knows which tests are doing this.Comment #18
mile23Added a follow-up: #2981870: Duplicate BrokenSetUpTest for BrowserTestBase
Updated IS to be clear on what else needs to happen.
Comment #20
lendudeThis addresses the remaining points (I think).
testUserAgentValidation moved to its own test
InstallationProfileModuleTestsTest moved to BTB (takes forever to run, but green locally)
added testHtkey to test the relevant part of testInternalBrowser
BrokenSetUpTest has a follow up so leaving that for now.
Comment #21
alexpottThe current patch looks really good and I agree with the scope in the issue summary. Yes we could do each of step in a separate issue but I see the scope of this issue as sorting out the WebTestBase tests of the Simpletest module and therefore doing these tasks here is in scope.
Comment #22
dawehnerGreat work!
I'm confused, why is this in system now?
Nice increase of the test coverage!
Nitpick: whitespace error :(
Is there a reason you couldn't create a
Urlobject?Note: You can use
assertRegExpinsteadComment #23
borisson_Back to needs worked based on @dawehner's comment in #22.
Comment #24
lendudeThanks for taking a look at this.
#22.1 It is only used by
\Drupal\Tests\system\Unit\TraitAccessTestwhich is also moved to system, since it has nothing to do with Simpletest, maybe moving it to /core/tests/Drupal/Tests makes more sense. Removed the @group simpletest in any case.#22.3 bah, for some reason PHPStorm didn't want to remove it just by saving
#22.4 lets use the available api, $this->buildUrl
#22.5 it's also using the preg_match to generate $matches for the next line $this->agent = drupal_generate_test_ua($matches[0]); So don't think that works in this case.
Comment #25
jibranThis is ready.
Comment #26
alexpottThis will now conflict.
I don't think that this is a simpletest UI test per se. I think we need test coverage to prove that
We might already have this type of test discovery test but it is worth proving and adding a comment to the WebTestBase if we do. If we don't that we need to convert this to a better test and one outside of the Simpletest module.
I seem to have asked this before - ie #14.
Let's remove the @group simpletest here - they are no longer part of simpletest.
Comment #27
dawehnerGoing through the list of installation profiles it doesn't look like we have this tested already.
Comment #29
lendudesome unrelated stuff snuck into #27
Comment #30
dawehner@Lendude Good point. Sorry I also realized I moved the wrong file.
Comment #32
dawehnerI had a quick chat with @alexpott and we agreed it is good enough to expand the test coverage of
TestDiscovery.Comment #33
lendudeThanks @dawehner!
Just removing some whitespace that got in.
And removed the FakeAutoLoader since that doesn't seem to be necessary, we can just pop the ClassLoader in there. Or was that serving a specific testing purpose that I'm overlooking?
Comment #34
dawehnerNope, your fix seems totally reasonable.
Comment #35
jibranStrikethrough some more things from IS. Had a quick discussion with @Lendude in slack and it seems like everything from @alexpott's reviews has been addressed so setting it to RTBC.
Comment #37
alexpottCommitted 06076a3 and pushed to 8.7.x. Thanks!
Fixed coding standards.
Comment #39
lendudeWow! Massive thanks to all involved in getting this to land!