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.
Comment | File | Size | Author |
---|---|---|---|
#45 | 2870452-45.patch | 26.65 KB | Anonymous (not verified) |
Comments
Comment #2
Ujin CreditAttribution: Ujin commentedComment #3
Ujin CreditAttribution: Ujin commentedComment #4
Ujin CreditAttribution: Ujin as a volunteer commentedComment #7
dawehnerHi @Ujin, thank you for your contribution!
First tip: Try to use the following git configuration:
[diff]
renames = copies
This detects renames, see https://www.drupal.org/documentation/git/configure for more details. This will make the patch size significantly smaller.
This requires #2795085: Add assertNoCacheTag to assertLegacyTrait to be in. Note: you could convert the function calls manually.
Comment #8
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #9
Ujin CreditAttribution: Ujin as a volunteer commentedHi @dawehner,
Thank you for the help, I am new to Drupal 8 testing, I am testing using this line
php core/scripts/run-tests.sh --verbose --browser chrome --url http://my-url/ --class --color "\Drupal\Tests\menu_ui\Functional\MenuTest"
and see errors like this:
What could be the issue ?
Thanks!
Comment #10
dawehnerYou probably run the tests with the wrong user, see the documentation on https://www.drupal.org/docs/8/phpunit/running-phpunit-tests
Comment #11
andypostInlined
assertCacheContext
Comment #13
andypostComment #14
andypostComment #15
andypostAnother try
Comment #17
andypostAnd another one
Comment #19
andypostEmulate
drupalPost()
Comment #21
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedQuick review to see what's going on here.
As it's actually testing Javascript things, shouldn't we move it to a JavascriptTestBase test?
Same for these changes.
Comment #22
andypostYep, both cases means that tests needs split some how (maybe on per method basis)
Comment #23
naveenvalechaThis issue is blocked by #2795085: Add assertNoCacheTag to assertLegacyTrait
Comment #24
dawehnerThis is in, yeah!
Comment #25
dawehnerComment #27
jofitz CreditAttribution: jofitz at ComputerMinds commentedApplied suggestions from #21 - created FunctionalJavascript/MenuWebTestBase and FunctionalJavascript/MenuTest to contain testBlockContextualLinks() and testMenuParentsJsAccess () from Functional/MenuTest.
Comment #29
claudiu.cristeaFew points:
\Drupal\menu_ui\Tests\MenuWebTestBase
should not be removed as is a base class and it's possible that some contribs are extending it. Instead it should be deprecated.MenuWebTestBase
has only a method,::assertMenuLink()
and that is used in the new BTB and new JTB classes. Thus we should not create a base class, neither for BTB, nor for JTB new classes but we should move::assertMenuLink()
in a trait because is pure code reusing between BTB and JTB.
::assertMenuLink()
signature parameters should be swapped because in PHPUnit the expectation should come first.Menu*
is wrong because the module is "Menu UI". So I renamed all the classes that I'm converting to use theMenuUi*
prefix.MenuUiJavascriptTest
is using specific UI actions (as contextual links) to perform the test.I posted an interdiff but I don't think it's too relevant.
Comment #30
claudiu.cristeaUnseles modules are enabled in the JTB test.
Comment #31
claudiu.cristeaAdding @trigger_error() to the deprecated base class.
Comment #32
dawehnerI'm wondering whether its really the right step to rename test classes, etc. The patch could be way smaller than it actually is right now.
Comment #33
claudiu.cristeaOn all, except one, we're adding
use MenuUiTrait;
in the proximity of the class statement. So the patch would not decrease to much (only with 2 x 2 lines plus 1 hunk.Comment #34
LendudeNice work on this one! But pffff hard to read/review diff here.
No need for the 'The ' before the __NAMESPACE__
The docblock also needs a @see to the CR
The fact that this adds something named phpUnitXXXX to a simpletest class should indicate that this might not be the right way to do this. I'd opt to not change the existing base class except for adding the deprecation. Yes this gives us some code duplication for now, but will allow us to do PHPUnit specific code in the new trait without having to worry about Simpletest BC stuff.
This method gets removed and then added back to the same class (it was moved to the JS test, where it was rightly removed from again). But lets not remove it in the first place.
Try to avoid assertWaitOnAjaxRequest, try to waitForElement()
Comment #35
andypostFiled CR https://www.drupal.org/node/2917910 as mentioned it
Fixed #34 1,2,4
3) I think better to have it as example showing how to migrate tests instead of code duplication
5) Why avoid it, it explicitly tests & throws exception when ajax goes wrong
Comment #36
LendudeThanks for working on this @andypost!
Well this example actually clearly illustrates why this doesn't work. When you use
\Drupal\menu_ui\Tests\MenuWebTestBase
after applying this patch and callassertMenuLink
, internally it will callassertEquals
which doesn't exist on WebTestBaseNow there is PHPUnit code inside a Simpletest test => fatal error. So that is exactly why we need a Simpletest version and a PHPUnit version for these things. And yeah this leads to some code duplication, but since one is deprecated we only have to really maintain one version.
I was proven to be a really unstable way of testing for AJAX activity and lead to a fair number of random fails, see #2829040: [meta] Known intermittent, random, and environment-specific test failures and some discussion in #2809161: Convert Javascript/AJAX testing to use JavascriptTestBase. It's just better to wait for something specific if you can, it also makes the test more explicit.
edit: fixed the second link
Comment #38
Anonymous (not verified) CreditAttribution: Anonymous commented#34.3/5 Done!
#34.3: Absolutely agree. The realization as #35 binds us hands
foreverbefore Drupal 9. Because we need to think about BC every time when we make changes in MenuUiTrait. It's much easier to just leave this class in the dust, as we do in all other cases of similar conversion.Also, I absolutely support the idea of converting *TestBase to a Trait (not to class). Perhaps even it is worth including this practice in the official recommendation on writing drupal tests. Because specialized help-methods can be useful in any other test, but we can not use multiple inheritance in PHP.
#34.5: Yep. And although at the current time the combination
drupalGet / assertWaitOnAjaxRequest / clickContextualLink
is fairly common in the core, there is no reason to continue this tradition.Comment #39
Anonymous (not verified) CreditAttribution: Anonymous commentedThis approach has 3 drawbacks:
Another approach, is always wait cotextual links inside of
clickContextualLink()
method. Once we get rid of all the drawbacks of the previous approach.I even locally checked it on the #2924201: Resolve random failure in LayoutBuilderTest so that it can be added to HEAD, where we have custom workaround of
clickContextualLink()
because of the instability of the default version. And everything worked just fine! So I especially like this approach)Comment #40
andypostRTBC++
Comment #41
LendudeNice! Yes much better this way.
All feedback has been addressed, looks good to me now.
Comment #42
claudiu.cristeas/8.5.x/8.6.x
Also the link should point to CR, not to the issue. (https://www.drupal.org/node/2870452 is the issue)
Comment #43
Anonymous (not verified) CreditAttribution: Anonymous commented#42.1: Why not in 8.5.x?
#42.2:
Done.Edit: My bad. It was necessary to change on https://www.drupal.org/node/2917910. It will be corrected after clarifying the first question about 8.5.x/8.6.x.+ fix nit typo in test.
Comment #44
claudiu.cristea@vaplas, you're right. I see the test conversions are committed to both, 8.5.x and 8.6.x (see #2863626: Convert web tests to browser tests for image module). Still need to change the CR address.
Comment #45
Anonymous (not verified) CreditAttribution: Anonymous commented@claudiu.cristea, thanks for feedback! Done.
Comment #46
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #47
Lendude@claudiu.cristea thanks for catching that and @vaplas thanks for fixing it!
Feedback has been addressed, back to RTBC.
Comment #48
alexpottCommitted and pushed 51afa6813a to 8.6.x and ee7d05c318 to 8.5.x. Thanks!