Skip to content

Commit

Permalink
Add tests for Themes_Screens::__construct(). (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev authored Dec 1, 2024
1 parent 5d4dfcd commit 43b86fc
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/phpunit/tests/ThemesScreens/ThemesScreens_ConstructTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Class ThemesScreens_ConstructTest
*
* @package AspireUpdate
*/

/**
* Tests for Themes_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\Themes_Screens::__construct
*
*/
class ThemesScreens_ConstructTest extends WP_UnitTestCase {
/**
* Test that hooks are added when API rewriting is enabled.
*
* @dataProvider data_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 );

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

/**
* Test that hooks are not added when API rewriting is disabled.
*
* @dataProvider data_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 );

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

/**
* Data provider.
*
* @return array[]
*/
public function data_hooks_and_methods() {
return [
'admin_enqueue_scripts -> admin_enqueue_scripts' => [
'hook' => 'admin_enqueue_scripts',
'method' => 'admin_enqueue_scripts',
],
'load-theme-install.php -> redirect_to_theme_install' => [
'hook' => 'load-theme-install.php',
'method' => 'redirect_to_theme_install',
],
];
}
}

0 comments on commit 43b86fc

Please sign in to comment.