Child to #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)
Problem/Motivation
Proposed resolution
Postponed on #2855942: Create ::checkForMetaRefresh() on BrowserTestBase
Remaining tasks
User interface changes
API changes
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 2757023-34-2.patch | 8.17 KB | naveenvalecha |
Comments
Comment #2
jibranOnly cache tests are remaining.
Comment #4
klausiCan you create the patch with "git diff -M25%" so that we can see that this file has been moved?
Let's not change this lines if they don't break, only makes patch review harder and is out of scope for this conversion issue.
Looks like you are changing many lines just to remove the assertion messages. I think we should not do that here and just convert the test. A later cleanup can convert the assertions to proper $this->assertSession()->... calls that are not deprecated.
Comment #5
klausiComment #6
jibranComment #7
klausiSo this method should be enabled again, right?
Looks like getRawContent() is missing on BrowserTestBase, can you add it there similar to getTextContent()?
looks like this is changing the logic of the assertion. The new call should search in the specific table cell and link, right?
Same here, we should look in the table cell like the original assertion did.
Also elsewhere.
Ah, you are getting XML back, so you should probably use SimpleXml on the result of drupalGet() to navigate it.
Comment #8
jibranThank you for all your reviews. Please feel free to grab any of these. :-)
AssertLegacyTrait.Comment #9
claudiu.cristeaOK, fixed all from #7.
@jibran, that failure (#8.1) is because Mink is getting the plain text from the browser in a different way. We were wrong in WebBaseTest. Mink thinks every time that the test is a human using a real browser. So, now
assertText($test)converts the HTML entities in the character actually viewed by a human.Let's say the the returned page contains this piece of markup:
<p>Bad html <script>alert(123);</script></p>In WebTestBase this is passing:
$this->assertText('<script>alert(123);</script>')because it wrongly consider that the text means only stripping tags.In BrowserTestBase will fail but
$this->assertText('<script>alert(123);</script>')will pass because Mink is putting in plain text the text as is displayed to a human, in browser. And that is<not<.Comment #10
dawehnerWhy can't we use $this->xpath instead? Also IMHO we should continue to use
$this->assertEqualsas we do in every other place in core.Do we really have to change this line? In case we do, we should IMHO drop the
t()statement.I'm wondering whether mink actually implements the same kind of logic internally already. It feels as if it would belong on that level
Comment #11
claudiu.cristeaThis I will postpone on #2773733: Fix AssertLegacyTrait::assert(No)Text to handle html encoded strings (part 3). There are several conversions that need that, so let's fix it in a dedicated issue.
Comment #13
jmuzz commented+1 for checkForMetaRefresh().
It would make it possible to make functional tests on stuff that uses the batch API without requiring JavascriptTestBase and without adding the same function to every module that needs it.
It doesn't need to be recursive. A loop would use less memory.
I did some grepping around in /vendor and /core/lib/Drupal/Component for stuff like redirect and refresh and I don't think it is built into Mink.
Look at how Mahara does it: https://git.mahara.org/mahara/mahara/blob/16.04.3_RELEASE/htdocs/testing... in i_wait_to_be_redirected().
Similar example from Behat Drupal Extensions: https://www.drupal.org/node/2011390 .
Comment #14
claudiu.cristeaUn-postponing because #2773733: Fix AssertLegacyTrait::assert(No)Text to handle html encoded strings (part 3) is in.
@dawehner,
#10.1
Because
$this->xpath()doesn't handle non-HTML pages. Here we have OPML so we need this workaround.#10.3: I searched but no luck. But if you find something..
Comment #15
dawehnerThose ones are part of the move issue, so let's skip that here.
At least those should be able to leverage #2809181: Provide forward compatibility layer for BrowserTestBase::xpath
Do we have a dedicated issue for those changes? These should be for example tested separately
Comment #17
jofitzRe-rolled.
Comment #18
klausiThis is an old base class and must not be removed. It is depreacted but it must stay. Sorry for not telling you earlier :)
This should have a comment why we have to use simplexml_load_string() here. Example: // We can't use Mink XPAth queries here because it only supports HTML pages, but we are dealing with XML here.
not sure if we should add this method in this issue or create a new one for that ...
we decided to not add this method to BrowserTestBase. Use the CronRunTrait for test cases that need cron instead.
this method is only used by 2 tests in Drupal core. Let's not add it on BrowserTestBase, let's create a new issue to have a trait with that method instead that can be used by Simpletest's WebTestBase and the converted tests.
Comment #19
claudiu.cristeaComment #20
claudiu.cristeaHm. I think we should move the trait creation back here for the reasons I mentioned in #2855942-5: Create ::checkForMetaRefresh() on BrowserTestBase. What you think, @klausi?
Comment #21
klausiYes, checkForMetaRefresh() is only used by aggregator and big_pipe, so I think is fine to do here.
Comment #22
goz commentedi'm working on this to merge with #2855942: Create ::checkForMetaRefresh() on BrowserTestBase
Comment #23
goz commentedComment #24
klausiWe shouldn't change this line, we should have the getRawContent() method on BrowserTestBase or AssertLegacyTrait. The original getRawContent() method is in AssertContentTrait, so I vote to implement it in AssertLegacyTrait. We should open an issue for that and add test coverage for it to BrowserTestBaseTest.
Postponing on that, please open an issue and link it here.
Comment #25
goz commentedIssue already exists. getRawContent() should be discussed on #2795111: WTB to BTB, add getRawContent() in BTB
Comment #26
dawehnerThis issue can be worked on again ...
Comment #27
goz commentedComment #28
dawehnerLet's postpone it on #2855942: Create ::checkForMetaRefresh() on BrowserTestBase for now
Comment #29
dawehnerComment #30
michielnugter commentedComment #31
naveenvalechaThis landed #2862885: Batch: Convert system functional tests to phpunit and it unblocked this issue.
//Naveen
Comment #33
naveenvalechaAssigning to myself for fixing the failures.
//Naveen
Comment #34
naveenvalechaI have added two patches
2757023-34-2.patch: This is the straightforward conversion of the WTB to BTB
2757023-34-remove-AggregatorTestBase-class.patch: This patch removes the "src/Tests/AggregatorTestBase" Class from the codebase as no other test is using it. What're the thoughts on removing the deprecated Base class? However, tests are not the API as per the BC policy.
//Naveen
Comment #35
dawehnerI think the discussion to remove the base class should be its own issue. Its one less thing to deal with for reviewers/committers ...
Comment #36
naveenvalecha#35: Filed a follow-up #2886547: Add trigger_error to deprecated TestBase base classes/traits that have none, reference CR
2757023-34-2.patch is ready for review. Is it RTBC?
//Naveen
Comment #37
dawehnerI'd say so
Comment #40
catchThanks for the separate deprecation issue, makes this a much easier commit for the substantive change, then that one is just yes or no eventually.
Committed/pushed to 8.4.x and cherry-picked to 8.3.x. Thanks!