-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-class-base.php
More file actions
235 lines (194 loc) · 5.8 KB
/
Copy pathtest-class-base.php
File metadata and controls
235 lines (194 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php // phpcs:disable Generic.Commenting.Todo
/**
* Class Base_Test
*
* @package Progress_Planner\Tests
*/
namespace Progress_Planner\Tests;
use Progress_Planner\Base;
/**
* Base plugin class test case.
*/
class Base_Test extends \WP_UnitTestCase {
/**
* Test instance.
*
* @var Base
*/
private $base_instance;
/**
* Set up test.
*
* @return void
*/
public function setUp(): void {
parent::setUp();
$this->base_instance = new Base();
}
/**
* Test get_settings returns Settings instance.
*
* @return void
*/
public function test_get_settings() {
$settings = $this->base_instance->get_settings();
$this->assertInstanceOf( \Progress_Planner\Settings::class, $settings );
}
/**
* Test get_settings returns same instance (singleton pattern).
*
* @return void
*/
public function test_get_settings_singleton() {
$settings_1 = $this->base_instance->get_settings();
$settings_2 = $this->base_instance->get_settings();
$this->assertSame( $settings_1, $settings_2 );
}
/**
* Test get_suggested_tasks_db returns Suggested_Tasks_DB instance.
*
* @return void
*/
public function test_get_suggested_tasks_db() {
$db = $this->base_instance->get_suggested_tasks_db();
$this->assertInstanceOf( \Progress_Planner\Suggested_Tasks_DB::class, $db );
}
/**
* Test get_suggested_tasks_db returns same instance (singleton pattern).
*
* @return void
*/
public function test_get_suggested_tasks_db_singleton() {
$db_1 = $this->base_instance->get_suggested_tasks_db();
$db_2 = $this->base_instance->get_suggested_tasks_db();
$this->assertSame( $db_1, $db_2 );
}
/**
* Test get_admin__page returns Admin\Page instance.
*
* @return void
*/
public function test_get_admin_page() {
$page = $this->base_instance->get_admin__page();
$this->assertInstanceOf( \Progress_Planner\Admin\Page::class, $page );
}
/**
* Test get_rest__tasks returns Rest\Tasks instance.
*
* @return void
*/
public function test_get_rest_tasks() {
$tasks = $this->base_instance->get_rest__tasks();
$this->assertInstanceOf( \Progress_Planner\Rest\Tasks::class, $tasks );
}
/**
* Test get_rest__stats returns Rest\Stats instance.
*
* @return void
*/
public function test_get_rest_stats() {
$stats = $this->base_instance->get_rest__stats();
$this->assertInstanceOf( \Progress_Planner\Rest\Stats::class, $stats );
}
/**
* Test get_utils__cache returns Utils\Cache instance.
*
* @return void
*/
public function test_get_utils_cache() {
$cache = $this->base_instance->get_utils__cache();
$this->assertInstanceOf( \Progress_Planner\Utils\Cache::class, $cache );
}
/**
* Test get_todo returns Todo instance.
*
* @return void
*/
public function test_get_todo() {
$todo = $this->base_instance->get_todo();
$this->assertInstanceOf( \Progress_Planner\Todo::class, $todo );
}
/**
* Test get_badges returns Badges instance.
*
* @return void
*/
public function test_get_badges() {
$badges = $this->base_instance->get_badges();
$this->assertInstanceOf( \Progress_Planner\Badges::class, $badges );
}
/**
* Test SCORE_TARGET constant.
*
* @return void
*/
public function test_score_target_constant() {
$this->assertEquals( 200, Base::SCORE_TARGET );
}
/**
* Test init method registers hooks.
*
* @return void
*/
public function test_init_registers_hooks() {
$this->base_instance->init();
// Verify REST API endpoints are registered.
$this->assertNotFalse( \has_action( 'rest_api_init', [ $this->base_instance->get_rest__tasks(), 'register_rest_endpoint' ] ) );
$this->assertNotFalse( \has_action( 'rest_api_init', [ $this->base_instance->get_rest__stats(), 'register_rest_endpoint' ] ) );
// Verify plugin action links filter is registered.
$this->assertNotFalse( \has_filter( 'plugin_action_links_' . \plugin_basename( PROGRESS_PLANNER_FILE ), [ $this->base_instance, 'add_action_links' ] ) );
}
/**
* Test add_action_links adds correct links.
*
* @return void
*/
public function test_add_action_links() {
$links = $this->base_instance->add_action_links( [] );
$this->assertIsArray( $links );
$this->assertNotEmpty( $links );
// Verify links contain expected URLs.
$link_strings = \implode( ' ', $links );
$this->assertStringContainsString( 'progress-planner', $link_strings );
}
/**
* Test is_privacy_policy_accepted checks license key option.
*
* @return void
*/
public function test_is_privacy_policy_accepted() {
// Set license key (privacy policy accepted).
\update_option( 'progress_planner_license_key', 'test-license-key' );
$result = $this->base_instance->is_privacy_policy_accepted();
$this->assertTrue( $result );
// Remove license key (privacy policy not accepted).
\delete_option( 'progress_planner_license_key' );
$result = $this->base_instance->is_privacy_policy_accepted();
$this->assertFalse( $result );
}
/**
* Test is_debug_mode_enabled checks PRPL_DEBUG constant and option.
*
* @return void
*/
public function test_is_debug_mode_enabled() {
// Test with option set.
\update_option( 'prpl_debug', true );
// Option is set, but the user does not have the manage_options capability.
$result = $this->base_instance->is_debug_mode_enabled();
$this->assertFalse( $result );
// Set the current user to a user with the manage_options capability.
\wp_set_current_user( 1 );
// Option is set, and the user has the manage_options capability.
$result = $this->base_instance->is_debug_mode_enabled();
$this->assertTrue( $result );
// Test with option not set.
\delete_option( 'prpl_debug' );
$result = $this->base_instance->is_debug_mode_enabled();
// Should be false unless PRPL_DEBUG constant is defined and true.
$this->assertIsBool( $result );
// Unset the current user.
\wp_set_current_user( 0 );
}
}
// phpcs:enable Generic.Commenting.Todo