From 2daa951685390bf5fe640e1b483b276969225e74 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Tue, 21 Jul 2020 01:36:16 +0000 Subject: [PATCH] REST API: Make plugin installation tests more robust on alternate test environments. The REST API plugin installation tests use the `upgrader_pre_download` filter to avoid downloading the test plugin from WordPress.org. Previously, this would apply to any upgrader, which caused issues if the testing environment required a language update. Now, the filter only overwrites the file if the `Plugin_Upgrader` is being used which should hopefully prevent the issue. Props pfefferle, TimothyBlynJacobs. Fixes #50671. git-svn-id: https://develop.svn.wordpress.org/trunk@48524 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/rest-api/rest-plugins-controller.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-plugins-controller.php b/tests/phpunit/tests/rest-api/rest-plugins-controller.php index 26ed4cc4c0..77203a73d3 100644 --- a/tests/phpunit/tests/rest-api/rest-plugins-controller.php +++ b/tests/phpunit/tests/rest-api/rest-plugins-controller.php @@ -1013,9 +1013,15 @@ class WP_REST_Plugins_Controller_Test extends WP_Test_REST_Controller_Testcase { copy( DIR_TESTDATA . '/plugins/link-manager.zip', DIR_TESTDATA . '/link-manager.zip' ); add_filter( 'upgrader_pre_download', - function () { - return DIR_TESTDATA . '/link-manager.zip'; - } + static function ( $reply, $package, $upgrader ) { + if ( $upgrader instanceof Plugin_Upgrader ) { + $reply = DIR_TESTDATA . '/link-manager.zip'; + } + + return $reply; + }, + 10, + 3 ); }