|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package wpmautic\tests |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Test mautic settings page |
|
8
|
|
|
*/ |
|
9
|
|
|
class SettingsTest extends WP_UnitTestCase |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
public function setUp() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUp(); |
|
14
|
|
|
require_once(VPMAUTIC_PLUGIN_DIR.'/options.php'); |
|
15
|
|
|
|
|
16
|
|
|
$this->setOutputCallback(create_function('', '')); |
|
|
|
|
|
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function test_nonce_fields_are_present() |
|
20
|
|
|
{ |
|
21
|
|
|
wpmautic_options_page(); |
|
22
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
23
|
|
|
$this->assertContains("name='option_page' value='wpmautic'", $output); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function test_with_admin_init() |
|
27
|
|
|
{ |
|
28
|
|
|
wpmautic_admin_init(); |
|
29
|
|
|
wpmautic_options_page(); |
|
30
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
31
|
|
|
$this->assertContains("name='option_page' value='wpmautic'", $output); |
|
|
|
|
|
|
32
|
|
|
$this->test_base_url_setting(); |
|
33
|
|
|
$this->test_script_location_setting(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function test_base_url_setting() |
|
37
|
|
|
{ |
|
38
|
|
|
wpmautic_base_url(); |
|
39
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
40
|
|
|
$this->assertContains("wpmautic_base_url", $output); |
|
|
|
|
|
|
41
|
|
|
$this->assertContains("wpmautic_options[base_url]", $output); |
|
|
|
|
|
|
42
|
|
|
$this->assertContains("value=\"\"", $output); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
public function test_base_url_setting_with_value() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
update_option('wpmautic_options', array( |
|
48
|
|
|
'base_url' => 'http://example.com' |
|
49
|
|
|
)); |
|
50
|
|
|
|
|
51
|
|
|
wpmautic_base_url(); |
|
52
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
53
|
|
|
$this->assertContains("wpmautic_base_url", $output); |
|
|
|
|
|
|
54
|
|
|
$this->assertContains("wpmautic_options[base_url]", $output); |
|
|
|
|
|
|
55
|
|
|
$this->assertContains("value=\"http://example.com\"", $output); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function test_script_location_setting() |
|
59
|
|
|
{ |
|
60
|
|
|
wpmautic_script_location(); |
|
61
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
62
|
|
|
$this->assertContains("wpmautic_script_location", $output); |
|
|
|
|
|
|
63
|
|
|
$this->assertContains("wpmautic_options[script_location]", $output); |
|
|
|
|
|
|
64
|
|
|
$this->assertRegExp('/value="header"\s+checked/', $output); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
public function test_script_location_setting_with_footer_checked() |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
update_option('wpmautic_options', array( |
|
70
|
|
|
'script_location' => 'footer' |
|
71
|
|
|
)); |
|
72
|
|
|
|
|
73
|
|
|
wpmautic_script_location(); |
|
74
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
75
|
|
|
$this->assertContains("wpmautic_script_location", $output); |
|
|
|
|
|
|
76
|
|
|
$this->assertContains("wpmautic_options[script_location]", $output); |
|
|
|
|
|
|
77
|
|
|
$this->assertRegExp('/value="footer"\s+checked/', $output); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function test_fallback_activated_setting_with_default() |
|
81
|
|
|
{ |
|
82
|
|
|
wpmautic_fallback_activated(); |
|
83
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
84
|
|
|
$this->assertContains("wpmautic_fallback_activated", $output); |
|
|
|
|
|
|
85
|
|
|
$this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
|
|
|
|
|
86
|
|
|
$this->assertContains("checked", $output); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
public function test_fallback_activated_setting_with_unchecked() |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
update_option('wpmautic_options', array( |
|
92
|
|
|
'fallback_activated' => false |
|
93
|
|
|
)); |
|
94
|
|
|
|
|
95
|
|
|
wpmautic_fallback_activated(); |
|
96
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
97
|
|
|
$this->assertContains("wpmautic_fallback_activated", $output); |
|
|
|
|
|
|
98
|
|
|
$this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
|
|
|
|
|
99
|
|
|
$this->assertNotContains("checked", $output); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
View Code Duplication |
public function test_fallback_activated_setting_with_checked() |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
update_option('wpmautic_options', array( |
|
105
|
|
|
'fallback_activated' => true |
|
106
|
|
|
)); |
|
107
|
|
|
|
|
108
|
|
|
wpmautic_fallback_activated(); |
|
109
|
|
|
$output = $this->getActualOutput(); |
|
|
|
|
|
|
110
|
|
|
$this->assertContains("wpmautic_fallback_activated", $output); |
|
|
|
|
|
|
111
|
|
|
$this->assertContains("wpmautic_options[fallback_activated]", $output); |
|
|
|
|
|
|
112
|
|
|
$this->assertContains("checked", $output); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.