From 02a8c4e744e9281182f399c6ca948fbe16a48e4c Mon Sep 17 00:00:00 2001 From: Bogdan Preda Date: Sat, 30 Mar 2024 19:11:44 +0200 Subject: [PATCH] chore: test also element from plugins list as object --- tests/featured-plugins-test.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/featured-plugins-test.php b/tests/featured-plugins-test.php index 70d09fdf..cf61fd93 100644 --- a/tests/featured-plugins-test.php +++ b/tests/featured-plugins-test.php @@ -193,13 +193,34 @@ function( $results, $action, $args ) { return $results; }, 9, - 3 + 3 ); // This should also pass if the result type properties are mutated. $filtered_api_result = apply_filters( 'plugins_api_result', $api_result, 'query_plugins', $args ); $this->assertEquals( 1, count( $filtered_api_result->plugins ) ); + + // Mutate a plugin from list to be an object. + add_filter( + 'plugins_api_result', + function( $results, $action, $args ) { + $plugin = $results->plugins[0]; + $plugin['name'] = 'Optimole'; + $plugin['slug'] = 'optimole-wp'; + $plugins = $results->plugins; + $plugins[] = (object) $plugin; + $results->plugins = $plugins; + + return $results; + }, + 11, + 3 + ); + + // This should also pass if the plugin array contains a object within the list. + $filtered_api_result = apply_filters( 'plugins_api_result', $api_result, 'query_plugins', $args ); + $this->assertEquals( 2, count( $filtered_api_result->plugins ) ); } }