Changeset 57674
- Timestamp:
- 02/21/2024 01:05:53 AM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/admin/plugin-dependencies/getDependencyNames.php
r57545 r57674 20 20 21 21 /** 22 * Mocks an API response. 23 * 24 * @param string $type The type of response. Accepts 'success' or 'failure'. 25 */ 26 private function mock_api_response( $type ) { 27 add_filter( 28 'plugins_api', 29 function ( $bypass, $action, $args ) use ( $type ) { 30 if ( 'plugin_information' === $action && isset( $args->slug ) && str_starts_with( $args->slug, 'dependency' ) ) { 31 if ( 'success' === $type ) { 32 return (object) array( 33 'slug' => $args->slug, 34 'name' => 'Dependency ' . str_replace( 'dependency', '', $args->slug ), 35 ); 36 } elseif ( 'failure' === $type ) { 37 return new WP_Error( 'plugin_not_found', 'Plugin not found.' ); 38 } 39 } 40 41 return $bypass; 42 }, 43 10, 44 3 45 ); 46 } 47 48 /** 22 49 * Tests that dependency names are retrieved. 23 50 * … … 41 68 ); 42 69 70 $this->mock_api_response( 'success' ); 43 71 self::$instance::initialize(); 44 72 … … 109 137 ); 110 138 139 $this->mock_api_response( 'failure' ); 111 140 self::$instance::initialize(); 112 141 … … 158 187 ); 159 188 189 $this->mock_api_response( 'failure' ); 160 190 self::$instance::initialize(); 161 191 … … 212 242 set_site_transient( 'wp_plugin_dependencies_plugin_data', array( 'dependency' => false ) ); 213 243 set_site_transient( 'wp_plugin_dependencies_plugin_timeout_dependency', true, 12 * HOUR_IN_SECONDS ); 244 245 $this->mock_api_response( 'success' ); 214 246 self::$instance::get_dependency_names( 'dependent' ); 215 247
Note: See TracChangeset
for help on using the changeset viewer.