Passed
Branch master (4d016b)
by Benjamin
02:36
created

SettingsMenuTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * Class SettingsMenuTest
4
 *
5
 * @package WPSiteMonitor
6
 * @since 1.0.0
7
 */
8
9
use WPSiteMonitor\Settings_Menu;
10
11
/**
12
 * Settings Page test case.
13
 */
14
class SettingsMenuTest extends WP_UnitTestCase {
15
16
	protected $settings_menu;
17
	protected $menu_slug;
18
19
	public function setUp() {
20
		parent::setUp();
21
22
		$this->settings_menu = new Settings_Menu();
23
		$this->menu_slug = 'wp_site_monitor';
24
		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
25
	}
26
27
	/**
28
	 * Assert that the settings page is added to the settings menu successfully.
29
	 */
30
	public function test_settings_page_is_added_to_settings_menu() {
31
		global $submenu;
32
		$this->settings_menu->display_settings_page();
33
34
		$this->assertEquals( admin_url() . 'options-general.php?page=' . $this->menu_slug, menu_page_url( $this->menu_slug, false ) );
0 ignored issues
show
Bug introduced by
Are you sure the usage of admin_url() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
35
		$this->assertEquals( 'WP Site Monitor Settings', $submenu['options-general.php'][0][3] );
36
		$this->assertEquals( 'WP Site Monitor', $submenu['options-general.php'][0][0] );
37
	}
38
39
	/**
40
	 * Assert that the enable/disable toggle is registered with the settings API.
41
	 */
42
	public function test_enable_option_is_created() {
43
		global $new_whitelist_options, $wp_settings_sections, $wp_settings_fields;
44
		$this->settings_menu->init_settings();
45
46
		$section_id = 'wp_site_monitor_enable_section';
47
		$this->assertContains('wp_site_monitor_enable', $new_whitelist_options[$this->menu_slug] );
48
		$this->assertEquals( $section_id, $wp_settings_sections[$this->menu_slug][$section_id]['id'] );
49
		$this->assertEquals( 'Enable/Disable WP Site Monitor', $wp_settings_sections[$this->menu_slug][$section_id]['title'] );
50
		$this->assertEquals( 'wp_site_monitor_enable', $wp_settings_fields[$this->menu_slug][$section_id]['wp_site_monitor_enable']['id'] );
51
		$this->assertEquals( 'Enable WP Site Monitor', $wp_settings_fields[$this->menu_slug][$section_id]['wp_site_monitor_enable']['title'] );
52
	}
53
}
54