Problem/Motivation

This started out to remove an unused variable and that lead to discovery that the test wasn't working as advertised. See #7.

Original report:
In core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php, $parent_link_path variables are never used.

Proposed resolution

Fix the text so that is properly tests all three situations.
And remove the unused variable.

Remaining tasks

Review

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shetpooja04 created an issue. See original summary.

shetpooja04’s picture

Assigned: shetpooja04 » Unassigned
Status: Active » Needs review
FileSize
618.36 KB
917 bytes

Commit ID: 244ccb28

Link: https://git.drupalcode.org/project/drupal/-/commit/244ccb28632ed87155d8b22a147fb362a058ffaa

File: core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php Line: 91

For Issue: https://www.drupal.org/project/drupal/issues/2845485 the variables were added

$parent_link_path variable were removed

Please review

Status: Needs review » Needs work

The last submitted patch, 2: 3172116-2.patch, failed testing. View results

Spokje’s picture

Status: Needs work » Needs review

Back to NR after #3 turned out to be a random fail.

quietone’s picture

Status: Needs review » Needs work
+++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
@@ -88,7 +88,7 @@ protected function setUp(): void {
   public function testTransformException(array $source_value) {
-    [$parent_id, $menu_name, $parent_link_path] = $source_value;

Part of me likes having the 3rd value in the input array because this is a process plugin that expects three values but yes, it isn't needed. The source data for this is from the dataprovider, providerTransformException. So, if we are only going to use two variables then the data provider should only provide two. Setting to NW to also update the data provider.

naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs work » Needs review
FileSize
1.22 KB
580 bytes

Please review

quietone’s picture

Status: Needs review » Needs work

@naresh_bavaskar, thanks for the patch and interdiff.

+++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
@@ -108,9 +108,6 @@ public function providerTransformException() {
-      'parent link is an internal URI that does not exist' => [
-        'source_value' => [1, NULL, 'admin/structure'],
-      ],

This change removes a test case which we want to keep. Want needs to happen is to modify each test case to provide two parameters instead of three. That will avoid the unused variable.

The PHPUnit docs explain how dataProviders work.

raman.b’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
841 bytes

Removing the third parameter from data provider and reverting the removed test case from #7

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Yes, that looks correct.

I applied that patch and check the changed manually as well looking at the interdiff. There are no coding standard errors reported by testing.

This is good to go.

Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/migrate/tests/src/Unit/process/MenuLinkParentTest.php
@@ -103,13 +103,13 @@ public function providerTransformException() {
       'parent link path/menu name not passed' => [
-        'source_value' => [1, NULL, 'http://drupal.org'],
+        'source_value' => [1, NULL],
       ],
       'parent link is an internal URI that does not exist' => [
-        'source_value' => [1, NULL, 'admin/structure'],
+        'source_value' => [1, NULL],
       ],

This is now really odd the source_value is the same for both tests. I guess this is why the previous patch removed it.

I think we need to check whether these tests are really testing what we think they are.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Title: Remove unused variable $parent_link_path in MenuLinkParentTest.php, migrate module » Fix test in MenuLinkParentTest::testTransformException
Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.31 KB

@alexpott, thanks. Yes, that isn't right.

This now fixes the test to do what it should have been doing all along. It now properly tests all three paths that can cause the exception to be thrown. No interdiff because this is so small.

Change the title to show that a test is being changed.

sulfikar_s’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
11.87 KB

Hi, I've applied the patch in #13 and it applied cleanly.

after-patch.png

Also verified that the values for 'source_value' are now different for the three cases.

So RTBC.

quietone’s picture

@sulfikar_s, thanks for reviewing this patch! Instead of attaching an image that you applied the patch locally it is OK to comment 'I applied the patch and .. then explain what you did in the review. The community know the patch will apply because the test bot ran the tests.

alexpott’s picture

Category: Task » Bug report
Status: Reviewed & tested by the community » Fixed

Committed and pushed b3d61bd368 to 9.2.x and b9d7fac590 to 9.1.x. Thanks!

Backported to 9.1.x as this is a test fix.

@sulfikar_s - thank you for looking into this issue. Posting screenshots of your codebase or CLI does not advance the issue, since the automated testing infrastructure tells us whether the patch applies correctly. So, I've removed the issue credit for that screenshot. In the future, you can get credit for issues by reading the issue to understand its purpose, and posting your review or testing of that purpose. Thank you!

  • alexpott committed b3d61bd on 9.2.x
    Issue #3172116 by shetpooja04, naresh_bavaskar, raman.b, quietone,...

  • alexpott committed b9d7fac on 9.1.x
    Issue #3172116 by shetpooja04, naresh_bavaskar, raman.b, quietone,...

Status: Fixed » Closed (fixed)

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