-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
Admin_Settings::__construct()
. (#229)
- Loading branch information
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
tests/phpunit/tests/AdminSettings/AdminSettings_ConstructTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Class AdminSettings_ConstructTest | ||
* | ||
* @package AspireUpdate | ||
*/ | ||
|
||
/** | ||
* Tests for Admin_Settings::__construct() | ||
* | ||
* @covers \AspireUpdate\Admin_Settings::__construct | ||
*/ | ||
class AdminSettings_ConstructTest extends AdminSettings_UnitTestCase { | ||
/** | ||
* Test that hooks are added. | ||
* | ||
* @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 ) { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
$this->assertIsInt( has_action( $hook, [ $admin_settings, $method ] ) ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public function data_hooks_and_methods() { | ||
return [ | ||
'admin_init -> reset_settings' => [ | ||
'hook' => 'admin_init', | ||
'method' => 'reset_settings', | ||
], | ||
'admin_init -> register_settings' => [ | ||
'hook' => 'admin_init', | ||
'method' => 'register_settings', | ||
], | ||
'admin_init -> update_settings' => [ | ||
'hook' => 'admin_init', | ||
'method' => 'register_settings', | ||
], | ||
'admin_enqueue_scripts -> admin_enqueue_scripts' => [ | ||
'hook' => 'admin_enqueue_scripts', | ||
'method' => 'admin_enqueue_scripts', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Test that single-site hooks are added in single-site. | ||
* | ||
* @dataProvider data_single_site_hooks_and_methods | ||
* | ||
* @group ms-excluded | ||
* | ||
* @string $hook The hook's name. | ||
* @string $method The method to hook. | ||
*/ | ||
public function test_should_add_single_site_hooks_in_single_site( $hook, $method ) { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
$this->assertIsInt( has_action( $hook, [ $admin_settings, $method ] ) ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public function data_single_site_hooks_and_methods() { | ||
return [ | ||
'admin_menu -> register_admin_menu' => [ | ||
'hook' => 'admin_menu', | ||
'method' => 'register_admin_menu', | ||
], | ||
'admin_notices -> admin_notices' => [ | ||
'hook' => 'admin_notices', | ||
'method' => 'admin_notices', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Test that multisite hooks are added in multisite. | ||
* | ||
* @dataProvider data_multisite_hooks_and_methods | ||
* | ||
* @group ms-required | ||
* | ||
* @string $hook The hook's name. | ||
* @string $method The method to hook. | ||
*/ | ||
public function test_should_add_multisite_hooks_in_multisite( $hook, $method ) { | ||
$admin_settings = new AspireUpdate\Admin_Settings(); | ||
$this->assertIsInt( has_action( $hook, [ $admin_settings, $method ] ) ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public function data_multisite_hooks_and_methods() { | ||
return [ | ||
'network_admin_menu -> register_admin_menu' => [ | ||
'hook' => 'network_admin_menu', | ||
'method' => 'register_admin_menu', | ||
], | ||
'network_admin_notices -> admin_notices' => [ | ||
'hook' => 'network_admin_notices', | ||
'method' => 'admin_notices', | ||
], | ||
'network_admin_edit_aspireupdate-settings -> update_settings' => [ | ||
'hook' => 'network_admin_edit_aspireupdate-settings', | ||
'method' => 'update_settings', | ||
], | ||
]; | ||
} | ||
} |