|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class SettingsMenuTest |
|
4
|
|
|
* |
|
5
|
|
|
* @package WPSiteMonitor |
|
6
|
|
|
* @since 1.0.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Tests\Test_Case; |
|
10
|
|
|
use WPSiteMonitor\Settings_Menu; |
|
11
|
|
|
use WPSiteMonitor\WP_Site_Monitor; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Settings Page test case. |
|
15
|
|
|
*/ |
|
16
|
|
|
class SettingsMenuTest extends Test_Case { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var Settings_Menu |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $settings_menu; |
|
22
|
|
|
|
|
23
|
|
|
public function setUp() { |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$this->settings_menu = new Settings_Menu(); |
|
27
|
|
|
$this->log_in(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Assert that the init_settings method is registered to the admin_init hook. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function test_init_settings_is_registered_to_admin_init_hook() { |
|
34
|
|
|
// Make sure is_admin() returns true. |
|
35
|
|
|
set_current_screen('index.php'); |
|
36
|
|
|
|
|
37
|
|
|
$plugin = new WP_Site_Monitor(); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertNotFalse( has_action( 'admin_init', array( $plugin->settings_menu, 'init_settings' ) ) ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Assert that the display_settings_page method is registered to the admin_menu hook. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function test_display_settings_page_is_registered_to_admin_menu_hook() { |
|
46
|
|
|
// Make sure is_admin() returns true. |
|
47
|
|
|
set_current_screen('index.php'); |
|
48
|
|
|
|
|
49
|
|
|
$plugin = new WP_Site_Monitor(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertNotFalse( has_action( 'admin_menu', array( $plugin->settings_menu, 'display_settings_page' ) ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Assert that the settings page is added to the settings menu successfully. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function test_settings_page_is_added_to_settings_menu() { |
|
58
|
|
|
global $submenu; |
|
59
|
|
|
$this->settings_menu->display_settings_page(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals( admin_url() . 'options-general.php?page=' . self::OPTION_GROUP, menu_page_url( self::OPTION_GROUP, false ) ); |
|
62
|
|
|
$this->assertEquals( 'WP Site Monitor Settings', $submenu['options-general.php'][0][3] ); |
|
63
|
|
|
$this->assertEquals( 'WP Site Monitor', $submenu['options-general.php'][0][0] ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Assert that the enable/disable toggle is registered with the settings API. |
|
68
|
|
|
*/ |
|
69
|
|
|
public function test_enable_option_is_created() { |
|
70
|
|
|
global $new_whitelist_options, $wp_settings_sections, $wp_settings_fields; |
|
71
|
|
|
$this->settings_menu->init_settings(); |
|
72
|
|
|
|
|
73
|
|
|
$section_id = self::OPTION_NAME . '_section'; |
|
74
|
|
|
$this->assertContains(self::OPTION_NAME, $new_whitelist_options[self::OPTION_GROUP] ); |
|
75
|
|
|
$this->assertEquals( $section_id, $wp_settings_sections[self::OPTION_GROUP][$section_id]['id'] ); |
|
76
|
|
|
$this->assertEquals( 'Enable/Disable WP Site Monitor', $wp_settings_sections[self::OPTION_GROUP][$section_id]['title'] ); |
|
77
|
|
|
$this->assertEquals( self::OPTION_NAME, $wp_settings_fields[self::OPTION_GROUP][$section_id][self::OPTION_NAME]['id'] ); |
|
78
|
|
|
$this->assertEquals( 'Enable WP Site Monitor', $wp_settings_fields[self::OPTION_GROUP][$section_id][self::OPTION_NAME]['title'] ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Assert that the settings menu HTML template is included. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function test_settings_menu_template_is_included() { |
|
85
|
|
|
// Hide template output |
|
86
|
|
|
$this->setOutputCallback(function() {}); |
|
87
|
|
|
|
|
88
|
|
|
$this->settings_menu->settings_page_html(); |
|
89
|
|
|
|
|
90
|
|
|
$included_files = get_included_files(); |
|
91
|
|
|
$this->assertContains( WPSM_PATH . 'templates/settings-page.php', $included_files ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Assert that the setting section HTML template is included. |
|
96
|
|
|
*/ |
|
97
|
|
|
public function test_setting_section_template_is_included() { |
|
98
|
|
|
// Hide template output |
|
99
|
|
|
$this->setOutputCallback(function() {}); |
|
100
|
|
|
|
|
101
|
|
|
$this->settings_menu->setting_section_html( array() ); |
|
102
|
|
|
|
|
103
|
|
|
$included_files = get_included_files(); |
|
104
|
|
|
$this->assertContains( WPSM_PATH . 'templates/setting-section.php', $included_files ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Assert that the setting input HTML template is included. |
|
109
|
|
|
*/ |
|
110
|
|
|
public function test_setting_input_template_is_included() { |
|
111
|
|
|
// Hide template output |
|
112
|
|
|
$this->setOutputCallback(function() {}); |
|
113
|
|
|
|
|
114
|
|
|
$this->settings_menu->setting_input_html(); |
|
115
|
|
|
|
|
116
|
|
|
$included_files = get_included_files(); |
|
117
|
|
|
$this->assertContains( WPSM_PATH . 'templates/setting-input.php', $included_files ); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|