Skip to content

Commit

Permalink
Autoloader: add unit tests for Plugins_Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrown9 committed Apr 23, 2020
1 parent f3ee519 commit 1ad4b36
Show file tree
Hide file tree
Showing 3 changed files with 385 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/autoloader/src/class-plugins-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function get_all_active_plugins( $skip_single_file_plugins = true ) {
*
* @return Array The active sitewide plugins.
*/
public function get_multisite_plugins() {
protected function get_multisite_plugins() {
return is_multisite()
? array_keys( get_site_option( 'active_sitewide_plugins', array() ) )
: array();
Expand Down
56 changes: 56 additions & 0 deletions packages/autoloader/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,62 @@ function trailingslashit( $string ) {
}
}

if ( ! function_exists( 'wp_unslash' ) ) {
/**
* A drop-in for a WordPress core function.
*
* @param string|string[] $value String or array of strings to unslash.
* @return string|string[] Unslashed $value
*/
function wp_unslash( $value ) {
return stripslashes_deep( $value );
}

/**
* A drop-in for a WordPress core function.
*
* @param mixed $value The value to be stripped.
* @return mixed Stripped value.
*/
function stripslashes_deep( $value ) {
return map_deep( $value, 'stripslashes_from_strings_only' );
}

/**
* A drop-in for a WordPress core function.
*
* @param mixed $value The array, object, or scalar.
* @param callable $callback The function to map onto $value.
* @return mixed The value with the callback applied to all non-arrays and non-objects inside it.
*/
function map_deep( $value, $callback ) {
if ( is_array( $value ) ) {
foreach ( $value as $index => $item ) {
$value[ $index ] = map_deep( $item, $callback );
}
} elseif ( is_object( $value ) ) {
$object_vars = get_object_vars( $value );
foreach ( $object_vars as $property_name => $property_value ) {
$value->$property_name = map_deep( $property_value, $callback );
}
} else {
$value = call_user_func( $callback, $value );
}

return $value;
}

/**
* A drop-in for a WordPress core function.
*
* @param mixed $value The array or string to be stripped.
* @return mixed $value The stripped value.
*/
function stripslashes_from_strings_only( $value ) {
return is_string( $value ) ? stripslashes( $value ) : $value;
}
}

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../src/functions.php';
require_once __DIR__ . '/../../src/class-plugins-handler.php';
Expand Down
Loading

0 comments on commit 1ad4b36

Please sign in to comment.