Make WordPress Core

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#56629 closed defect (bug) (fixed)

Delete Link Manager plugin after running REST API plugins controller tests

Reported by: ironprogrammer's profile ironprogrammer Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version: 5.5
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

After running the multisite PHPUnit test suite, the following files remain, contributing toward a dirty working copy:

tests/phpunit/data/plugins/link-manager/link-manager.php
tests/phpunit/data/plugins/link-manager/readme.txt

These files should be deleted after running the tests.

Background

The following three tests in /tests/rest-api/rest-plugins-controller.php are the last ones related to the Link Manager plugin. In each test, it first deletes the plugin if it exists (via delete_plugins( array( 'link-manager/link-manager.php' ) )), and then attempts to install the plugin.

  1. test_create_item_and_activate_errors_if_no_permission_to_activate_plugin()
  2. test_create_item_and_network_activate_rejected_if_not_multisite() (skipped in multisite testing)
  3. test_create_item_and_network_activate() (skipped in non-multisite testing)

During non-multisite testing, phpunit executes both #1 and #2. Test #2 deletes the plugin, and then fails to install the plugin because it is not multisite. The plugin cleanup from #1 is coincidental.

But in multisite testing, tests #1 and #3 are run. Because the plugin deletion occurs at the start of each test, and test #3 succeeds, the plugin is installed and its files remain at the end of the test.


Testing Instructions

Steps to Reproduce

  1. Run the multisite PHPUnit tests (also see optional filter in Additional Information below):
    phpunit --verbose -c tests/phpunit/multisite.xml
    
  2. 🐞 Observe that files in tests/phpunit/data/plugins/link-manager/ remain after tests complete.

Expected Results

  • ❌ link-manager plugin files should be deleted after running the tests.

Additional Information

To shorten the time needed to reproduce the issue, optionally apply a phpunit filter to run the final Link Manager test in /tests/rest-api/rest-plugins-controller.php:

phpunit --verbose -c tests/phpunit/multisite.xml --filter test_create_item_and_network_activate

Test Report Icons:
🐞 <= Indicates where issue ("bug") occurs.
✅ <= Behavior is expected.
❌ <= Behavior is NOT expected.

Related: #52579.

Change History (7)

This ticket was mentioned in PR #3314 on WordPress/wordpress-develop by ironprogrammer.


15 months ago
#1

  • Keywords has-patch has-unit-tests added

In tests/phpunit/tests/rest-api/rest-plugins-controller.php:

  • Delete link-manager plugin during test tear down.

Trac ticket: https://core.trac.wordpress.org/ticket/56629

#2 @ironprogrammer
15 months ago

I've opened PR 3314 to address this issue.

#3 @SergeyBiryukov
15 months ago

  • Milestone changed from Awaiting Review to 6.1

#4 @SergeyBiryukov
15 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 54301:

Tests: Delete Link Manager plugin after running REST API plugins controller tests.

After running the multisite PHPUnit test suite, the following files remained, contributing towards a dirty working copy:

tests/phpunit/data/plugins/link-manager/link-manager.php
tests/phpunit/data/plugins/link-manager/readme.txt

These files should be deleted after running the tests.

This commit ensures the link-manager plugin is deleted during test tear down, which was previously done at the beginning of some test methods, but not afterwards.

Follow-up to [48242], [54300].

Props ironprogrammer.
Fixes #56629.

SergeyBiryukov commented on PR #3314:


15 months ago
#5

Thanks for the PR! Merged in r54301.

#6 @SergeyBiryukov
15 months ago

In 54302:

Coding Standards: Remove extra space in REST API plugins controller test class.

This fixes a WPCS error:

  • Tabs must be used to indent lines; spaces are not allowed

Follow-up to [54301].

See #56629.

#7 @SergeyBiryukov
15 months ago

In 54304:

Tests: Revert removing empty directory in WP_UnitTestCase_Base::rmdir() for now.

This appears to need more investigation. Instead, delete the test-plugin and link-manager directories in REST API plugins controller tests, for which this change was initially intended.

Follow-up to [54300], [54301], [54303].

See #55652, #56629.

Note: See TracTickets for help on using tickets.