CommentFileSizeAuthor
#45 interdiff-43-45.txt1.24 KBAnonymous (not verified)
#45 2870452-45.patch26.65 KBAnonymous (not verified)
#43 interdiff-39-43.txt1.65 KBAnonymous (not verified)
#43 2870452-43.patch26.65 KBAnonymous (not verified)
#39 interdiff-38-39.txt2.45 KBAnonymous (not verified)
#39 2870452-menu_ui-39.patch26.64 KBAnonymous (not verified)
#38 interdiff-35-38.txt5.96 KBAnonymous (not verified)
#38 2870452-menu_ui-38.patch26.85 KBAnonymous (not verified)
#35 2870452-menu_ui-35.patch29.6 KBandypost
#35 interdiff-2870452-31.txt3.62 KBandypost
#31 2870452-31.interdiff.txt712 bytesclaudiu.cristea
#31 2870452-31.patch29.87 KBclaudiu.cristea
#30 2870452-30.interdiff.txt623 bytesclaudiu.cristea
#30 2870452-30.patch29.56 KBclaudiu.cristea
#29 2870452-29.interdiff.txt34.29 KBclaudiu.cristea
#29 2870452-29.patch29.6 KBclaudiu.cristea
#27 2870452-27.patch18.07 KBjofitz
#27 interdiff-19-27.txt13.36 KBjofitz
#19 2870452-menu_ui-19.patch7.01 KBandypost
#19 interdiff.txt1.43 KBandypost
#17 2870452-menu_ui-17.patch5.86 KBandypost
#17 interdiff.txt1.96 KBandypost
#15 2870452-menu_ui-15.patch4.26 KBandypost
#15 interdiff.txt1.02 KBandypost
#11 2870452-menu_ui-11.patch3.52 KBandypost
#4 browsertest-menu_ui-2870452-2.patch141.74 KBUjin
#2 browsertest-menu_ui-2870452-1.patch27.25 KBUjin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

michielnugter created an issue. See original summary.

Ujin’s picture

Ujin’s picture

Status: Active » Needs review
Ujin’s picture

The last submitted patch, 2: browsertest-menu_ui-2870452-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: browsertest-menu_ui-2870452-2.patch, failed testing.

dawehner’s picture

Hi @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.

1) Drupal\Tests\menu_ui\Functional\MenuNodeTest::testMenuNodeFormWidget
PHPUnit_Framework_Exception: Fatal error: Call to undefined method Drupal\Tests\menu_ui\Functional\MenuNodeTest::assertCacheContext() in /var/www/html/core/modules/menu_ui/tests/src/Functional/MenuNodeTest.php on line 60

This requires #2795085: Add assertNoCacheTag to assertLegacyTrait to be in. Note: you could convert the function calls manually.

michielnugter’s picture

Component: phpunit » menu_ui.module
Issue tags: +phpunit initiative
Ujin’s picture

Hi @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:

Drupal\Tests\menu_ui\Functional\MenuTest::testMenu
Exception: Warning: mkdir(): Permission denied
Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 157)

What could be the issue ?
Thanks!

dawehner’s picture

You probably run the tests with the wrong user, see the documentation on https://www.drupal.org/docs/8/phpunit/running-phpunit-tests

andypost’s picture

Inlined assertCacheContext

Status: Needs review » Needs work

The last submitted patch, 11: 2870452-menu_ui-11.patch, failed testing.

andypost’s picture

andypost’s picture

andypost’s picture

Status: Needs work » Needs review
FileSize
1.02 KB
4.26 KB

Another try

Status: Needs review » Needs work

The last submitted patch, 15: 2870452-menu_ui-15.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
1.96 KB
5.86 KB

And another one

Status: Needs review » Needs work

The last submitted patch, 17: 2870452-menu_ui-17.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
1.43 KB
7.01 KB

Emulate drupalPost()

Status: Needs review » Needs work

The last submitted patch, 19: 2870452-menu_ui-19.patch, failed testing.

michielnugter’s picture

Quick review to see what's going on here.

  1. +++ b/core/modules/menu_ui/tests/src/Functional/MenuTest.php
    @@ -577,9 +578,16 @@ public function testBlockContextualLinks() {
    -    $response = $this->drupalPost('contextual/render', 'application/json', $post, ['query' => ['destination' => 'test-page']]);
    -    $this->assertResponse(200);
    -    $json = Json::decode($response);
    +    $client = \Drupal::httpClient();
    +    $url = $this->buildUrl('contextual/render', ['query' => ['destination' => 'test-page']]);
    +    $response = $client->post($url, [
    +      'form_params' => $post,
    +      'headers' => [
    +        'Accept' => 'application/json',
    +      ],
    +    ]);
    +    $this->assertEquals(200, $response->getStatusCode());
    +    $json = Json::decode((string) $response);
         $this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entitymenuedit-form"><a href="' . base_path() . 'admin/structure/menu/manage/' . $custom_menu->id() . '">Edit menu</a></li></ul>');
    

    As it's actually testing Javascript things, shouldn't we move it to a JavascriptTestBase test?

  2. +++ b/core/modules/menu_ui/tests/src/Functional/MenuTest.php
    @@ -867,13 +875,13 @@ public function testMenuParentsJsAccess() {
    -    $this->drupalGetAjax('admin/structure/menu/parents');
    +    $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']);
    ...
    -    $this->drupalGetAjax('admin/structure/menu/parents');
    +    $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']);
    

    Same for these changes.

andypost’s picture

Yep, both cases means that tests needs split some how (maybe on per method basis)

naveenvalecha’s picture

Title: Convert web tests to browser tests for menu_ui module » [PP-1] Convert web tests to browser tests for menu_ui module
Issue summary: View changes
Status: Needs work » Postponed
dawehner’s picture

Title: [PP-1] Convert web tests to browser tests for menu_ui module » Convert web tests to browser tests for menu_ui module
Status: Postponed » Needs review

This is in, yeah!

dawehner’s picture

Status: Needs review » Needs work

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

Status: Needs work » Needs review
FileSize
13.36 KB
18.07 KB

Applied suggestions from #21 - created FunctionalJavascript/MenuWebTestBase and FunctionalJavascript/MenuTest to contain testBlockContextualLinks() and testMenuParentsJsAccess () from Functional/MenuTest.

Status: Needs review » Needs work

The last submitted patch, 27: 2870452-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
29.6 KB
34.29 KB

Few 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.
  • The ::assertMenuLink() signature parameters should be swapped because in PHPUnit the expectation should come first.
  • The classes prefix Menu* is wrong because the module is "Menu UI". So I renamed all the classes that I'm converting to use the MenuUi* prefix.
  • The new 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.

claudiu.cristea’s picture

Unseles modules are enabled in the JTB test.

claudiu.cristea’s picture

Adding @trigger_error() to the deprecated base class.

dawehner’s picture

I'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.

claudiu.cristea’s picture

I'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

On 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.

Lendude’s picture

Status: Needs review » Needs work

Nice work on this one! But pffff hard to read/review diff here.

  1. +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php
    @@ -2,13 +2,23 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\MenuWebTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use the \Drupal\Tests\BrowserTestBase base class and the \Drupal\Tests\menu_ui\Traits\MenuUiTrait trait instead. See https://www.drupal.org/node/2870452.', E_USER_DEPRECATED);
    

    No need for the 'The ' before the __NAMESPACE__

  2. +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php
    @@ -2,13 +2,23 @@
     /**
      * Base class for menu web tests.
    + *
    + * @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.x. Use
    + *   \Drupal\Tests\menu_ui\Traits\MenuUiTrait methods, instead.
      */
    

    The docblock also needs a @see to the CR

  3. +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php
    @@ -2,13 +2,23 @@
    +  use MenuUiTrait {
    +    assertMenuLink as phpUnitAssertMenuLink;
    +  }
    

    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.

  4. +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
    @@ -856,25 +846,7 @@ public function enableMenuLink(MenuLinkContent $item) {
    -  public function testMenuParentsJsAccess() {
    
    @@ -939,6 +911,22 @@ private function verifyAccess($response = 200) {
    +  public function testMenuParentsJsAccess() {
    

    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.

  5. +++ b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php
    @@ -0,0 +1,159 @@
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    ...
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    

    Try to avoid assertWaitOnAjaxRequest, try to waitForElement()

andypost’s picture

Filed 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

Lendude’s picture

Status: Needs review » Needs work

Thanks for working on this @andypost!

I think better to have it as example showing how to migrate tests instead of code duplication

Well this example actually clearly illustrates why this doesn't work. When you use \Drupal\menu_ui\Tests\MenuWebTestBase after applying this patch and call assertMenuLink, internally it will call assertEquals which doesn't exist on WebTestBase

+++ b/core/modules/menu_ui/tests/src/Traits/MenuUiTrait.php
@@ -48,29 +40,29 @@ public function assertMenuLink($menu_plugin_id, array $expected_item) {
+      $this->assertEquals($expected_item['langcode'], $entity->langcode->value);

Now 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.

Why avoid it, it explicitly tests & throws exception when ajax goes wrong

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
26.85 KB
5.96 KB

#34.3/5 Done!

#34.3: Absolutely agree. The realization as #35 binds us hands forever before 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.

Anonymous’s picture

+++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinkClickTrait.php
@@ -43,4 +43,17 @@ protected function toggleContextualTriggerVisibility($selector) {
+  protected function waitLoadAllContextualLinks() {

+++ b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php
@@ -42,8 +46,7 @@ public function testBlockContextualLinks() {
-    $this->assertSession()->assertWaitOnAjaxRequest();
+    $this->waitLoadAllContextualLinks();

This approach has 3 drawbacks:

  1. New method (additional maintaining)
  2. It remains "implicit rule" that must be observed, simply changed average component
    - drupalGet / assertWaitOnAjaxRequest / clickContextualLink
    + drupalGet / waitLoadAllContextualLinks/ clickContextualLink 
  3. It does not help if the contextual links will appear in the test later (or we must remember the need to wait for them).

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)

andypost’s picture

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Another approach, is always wait cotextual links inside of clickContextualLink() method.

Nice! Yes much better this way.

All feedback has been addressed, looks good to me now.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php
@@ -2,10 +2,17 @@
+@trigger_error(__NAMESPACE__ . '\MenuWebTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use the \Drupal\Tests\BrowserTestBase base class and the \Drupal\Tests\menu_ui\Traits\MenuUiTrait trait instead. See https://www.drupal.org/node/2870452.', E_USER_DEPRECATED);
...
+ * @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.x. Use

s/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)

Anonymous’s picture

Status: Needs work » Needs review
FileSize
26.65 KB
1.65 KB

#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.

claudiu.cristea’s picture

@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.

Anonymous’s picture

@claudiu.cristea, thanks for feedback! Done.

Anonymous’s picture

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

@claudiu.cristea thanks for catching that and @vaplas thanks for fixing it!

Feedback has been addressed, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 51afa6813a to 8.6.x and ee7d05c318 to 8.5.x. Thanks!

  • alexpott committed 51afa68 on 8.6.x
    Issue #2870452 by andypost, vaplas, claudiu.cristea, Ujin, Jo Fitzgerald...

  • alexpott committed ee7d05c on 8.5.x
    Issue #2870452 by andypost, vaplas, claudiu.cristea, Ujin, Jo Fitzgerald...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.