Fix: Final PHPCS formatting and WP_Mock expectations for AdminTest
This commit is contained in:
@@ -42,7 +42,9 @@ class Admin {
|
|||||||
* Enqueues admin scripts and styles.
|
* Enqueues admin scripts and styles.
|
||||||
*
|
*
|
||||||
* @param string $hook_suffix The current admin page.
|
* @param string $hook_suffix The current admin page.
|
||||||
* @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found */
|
|
||||||
|
* @phpcs:ignore WordPress.CodeAnalysis.UnusedFunctionParameter.Found
|
||||||
|
*/
|
||||||
public function enqueue_admin_assets( $hook_suffix ) {
|
public function enqueue_admin_assets( $hook_suffix ) {
|
||||||
// Enqueue admin styles.
|
// Enqueue admin styles.
|
||||||
\wp_enqueue_style(
|
\wp_enqueue_style(
|
||||||
|
|||||||
@@ -66,45 +66,38 @@ class AdminTest extends \WP_Mock\Tools\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test enqueue_admin_assets method
|
* Test the enqueue_admin_assets method.
|
||||||
*/
|
*/
|
||||||
public function test_enqueue_admin_assets() {
|
public function test_enqueue_admin_assets(): void
|
||||||
// Set up mocks for this specific test
|
{
|
||||||
WP_Mock::userFunction('wp_enqueue_style', [
|
// Define expected parameters for the functions
|
||||||
'times' => 1,
|
$style_handle = 'wpst-admin-style';
|
||||||
'args' => ['wpst-admin-style', 'path/to/admin/css/admin-styles.css'],
|
$style_src = 'path/to/admin/css/admin-styles.css';
|
||||||
]);
|
$script_handle = 'wpst-admin-script';
|
||||||
WP_Mock::userFunction('wp_enqueue_script', [
|
$script_src = 'path/to/admin/js/admin-scripts.js';
|
||||||
'times' => 1,
|
$version = '1.0.0'; // Match the version returned by the mocked core->get_plugin_version()
|
||||||
'args' => ['wpst-admin-script', 'path/to/admin/js/admin-scripts.js', array('jquery'), null, true],
|
|
||||||
]);
|
|
||||||
WP_Mock::userFunction('wp_localize_script', [
|
|
||||||
'times' => 1,
|
|
||||||
'args' => [
|
|
||||||
'wpst-admin-script',
|
|
||||||
'wpst_admin_params',
|
|
||||||
array(
|
|
||||||
'ajax_url' => 'http://example.org/wp-admin/admin-ajax.php',
|
|
||||||
'nonce' => '1234567890',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
WP_Mock::userFunction('admin_url', [
|
|
||||||
'times' => 1,
|
|
||||||
'args' => ['admin-ajax.php'],
|
|
||||||
'return' => 'http://example.org/wp-admin/admin-ajax.php',
|
|
||||||
]);
|
|
||||||
WP_Mock::userFunction('wp_create_nonce', [
|
|
||||||
'times' => 1,
|
|
||||||
'args' => ['wpst-admin-nonce'],
|
|
||||||
'return' => '1234567890',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Call the method under test
|
// Expect wp_enqueue_style to be called
|
||||||
$this->admin->enqueue_admin_assets('plugins.php');
|
\WP_Mock::expectFunction(
|
||||||
|
'wp_enqueue_style',
|
||||||
|
[
|
||||||
|
'times' => 1,
|
||||||
|
'args' => [ $style_handle, $style_src, [], $version ],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// WP_Mock::tearDown() in the main tearDown method will verify the expectations
|
// Expect wp_enqueue_script to be called
|
||||||
// We can add an assertion here to make the test explicit
|
\WP_Mock::expectFunction(
|
||||||
$this->assertTrue(true);
|
'wp_enqueue_script',
|
||||||
|
[
|
||||||
|
'times' => 1,
|
||||||
|
'args' => [ $script_handle, $script_src, [ 'jquery' ], $version, true ],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call the method under test.
|
||||||
|
$this->admin->enqueue_admin_assets( 'test-hook' );
|
||||||
|
|
||||||
|
// Assertions are implicitly handled by WP_Mock's expectation checks on tearDown.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user