Skip to content

Commit

Permalink
Add tests for Plugins_Screens::__construct(). (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev authored Dec 1, 2024
1 parent db3322e commit 2a5e84e
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Class PluginsScreens_ConstructTest
*
* @package AspireUpdate
*/

/**
* Tests for Plugins_Screens::__construct()
*
* These tests cause constants to be defined.
* They must run in separate processes and must not preserve global state.
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*
* @covers \AspireUpdate\Plugins_Screens::__construct
*/
class PluginsScreens_ConstructTest extends WP_UnitTestCase {
/**
* Test that hooks are added when API rewriting is enabled.
*
* @dataProvider data_single_site_hooks_and_methods
*
* @string $hook The hook's name.
* @string $method The method to hook.
*/
public function test_should_add_hooks( $hook, $method ) {
define( 'AP_ENABLE', true );

$plugins_screens = new AspireUpdate\Plugins_Screens();
$this->assertIsInt( has_action( $hook, [ $plugins_screens, $method ] ) );
}

/**
* Test that hooks are not added when API rewriting is disabled.
*
* @dataProvider data_single_site_hooks_and_methods
*
* @string $hook The hook's name.
* @string $method The method to hook.
*/
public function test_should_not_add_hooks( $hook, $method ) {
define( 'AP_ENABLE', false );

$plugins_screens = new AspireUpdate\Plugins_Screens();
$this->assertFalse( has_action( $hook, [ $plugins_screens, $method ] ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_single_site_hooks_and_methods() {
return [
'install_plugins_tabs -> remove_unused_filter_tabs' => [
'hook' => 'install_plugins_tabs',
'method' => 'remove_unused_filter_tabs',
],
];
}
}

0 comments on commit 2a5e84e

Please sign in to comment.