Passed
Push — master ( d406ab...3befbe )
by Benjamin
02:31
created

WPSiteMonitor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A test_settings_unregistered_when_plugin_deactivated() 0 8 1
A test_settings_removed_on_plugin_uninstall() 0 9 1
1
<?php
2
/**
3
 * Class WPSiteMonitorTest
4
 *
5
 * @package WPSiteMonitor
6
 * @since 1.0.0
7
 */
8
9
use WPSiteMonitor\Settings_Menu;
10
use WPSiteMonitor\WP_Site_Monitor;
11
12
/**
13
 * WP Site Monitor test case.
14
 */
15
class WPSiteMonitor extends WP_UnitTestCase {
16
17
	const OPTION_NAME = 'wp_site_monitor_enable';
18
19
	public function setUp() {
20
		parent::setUp();
21
22
		(new Settings_Menu)->init_settings();
23
	}
24
25
	/**
26
	 * Assert that the plugin settings are unregistered on plugin deactivation.
27
	 */
28
	public function test_settings_unregistered_when_plugin_deactivated() {
29
		global $wp_registered_settings;
30
31
		$this->assertArrayHasKey(self::OPTION_NAME, $wp_registered_settings );
32
33
		WP_Site_Monitor::deactivate();
34
35
		$this->assertArrayNotHasKey(self::OPTION_NAME, $wp_registered_settings );
36
	}
37
38
	/**
39
	 * Assert that the plugin settings are removed on plugin uninstall.
40
	 */
41
	public function test_settings_removed_on_plugin_uninstall() {
42
		global $wpdb;
43
		update_option( self::OPTION_NAME, 1 );
44
45
		WP_Site_Monitor::uninstall();
46
47
		$option = self::OPTION_NAME;
48
		$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
49
		$this->assertNull( $row );
50
	}
51
}
52