@@ -12,27 +12,27 @@ |
||
12 | 12 | * |
13 | 13 | * @since 1.2.1 |
14 | 14 | */ |
15 | -require_once( WORDPOINTS_IMPORTER_TESTS_DIR . '/../../src/admin/admin.php' ); |
|
15 | +require_once(WORDPOINTS_IMPORTER_TESTS_DIR.'/../../src/admin/admin.php'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Feedback object used in the tests. |
19 | 19 | * |
20 | 20 | * @since 1.0.0 |
21 | 21 | */ |
22 | -require_once( WORDPOINTS_IMPORTER_TESTS_DIR . '/includes/feedback.php' ); |
|
22 | +require_once(WORDPOINTS_IMPORTER_TESTS_DIR.'/includes/feedback.php'); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Mocks used in the tests. |
26 | 26 | * |
27 | 27 | * @since 1.0.0 |
28 | 28 | */ |
29 | -require_once( WORDPOINTS_IMPORTER_TESTS_DIR . '/includes/mocks.php' ); |
|
29 | +require_once(WORDPOINTS_IMPORTER_TESTS_DIR.'/includes/mocks.php'); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Testcase for testing hooks. |
33 | 33 | * |
34 | 34 | * @since 1.2.0 |
35 | 35 | */ |
36 | -require_once( WORDPOINTS_IMPORTER_TESTS_DIR . '/includes/testcases/hook.php' ); |
|
36 | +require_once(WORDPOINTS_IMPORTER_TESTS_DIR.'/includes/testcases/hook.php'); |
|
37 | 37 | |
38 | 38 | // EOF |
@@ -17,856 +17,856 @@ |
||
17 | 17 | */ |
18 | 18 | class WordPoints_CubePoints_Importer_Test extends WordPoints_Points_UnitTestCase { |
19 | 19 | |
20 | - /** |
|
21 | - * The importer used in the tests. |
|
22 | - * |
|
23 | - * @since 1.0.0 |
|
24 | - * |
|
25 | - * @var WordPoints_CubePoints_Importer |
|
26 | - */ |
|
27 | - protected $importer; |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 1.0.0 |
|
31 | - */ |
|
32 | - public function setUp() { |
|
33 | - |
|
34 | - parent::setUp(); |
|
35 | - |
|
36 | - // These are usually inactive by default. We activate them in the tests |
|
37 | - // bootstrap so that they will be fully loaded, but deactivate them here to |
|
38 | - // restore default behavior. |
|
39 | - cp_module_activation_set( 'post_author_points', false ); |
|
40 | - cp_module_activation_set( 'dailypoints', false ); |
|
41 | - |
|
42 | - $this->importer = new WordPoints_CubePoints_Importer( 'Test CubePoints' ); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @since 1.1.0 |
|
47 | - */ |
|
48 | - public function tearDown() { |
|
49 | - |
|
50 | - WordPoints_Rank_Groups::deregister_group( 'points_type-points' ); |
|
51 | - WordPoints_Rank_Types::deregister_type( 'points-points' ); |
|
52 | - |
|
53 | - parent::tearDown(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Test that it returns true when CubePoints is installed. |
|
58 | - * |
|
59 | - * @since 1.0.0 |
|
60 | - * |
|
61 | - * @covers WordPoints_CubePoints_Importer::is_cubepoints_installed |
|
62 | - */ |
|
63 | - public function test_is_cubepoints_installed() { |
|
64 | - |
|
65 | - $this->assertTrue( $this->importer->is_cubepoints_installed() ); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Test that it returns false when CubePoints is not installed. |
|
70 | - * |
|
71 | - * @since 1.0.0 |
|
72 | - * |
|
73 | - * @covers WordPoints_CubePoints_Importer::is_cubepoints_installed |
|
74 | - */ |
|
75 | - public function test_is_cubepoints_not_installed() { |
|
76 | - |
|
77 | - delete_option( 'cp_db_version' ); |
|
78 | - |
|
79 | - $this->assertFalse( $this->importer->is_cubepoints_installed() ); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Test that it returns true when CubePoints is installed. |
|
84 | - * |
|
85 | - * @since 1.0.0 |
|
86 | - * |
|
87 | - * @covers WordPoints_CubePoints_Importer::is_available |
|
88 | - */ |
|
89 | - public function test_is_cubepoints_is_available() { |
|
90 | - |
|
91 | - $this->assertTrue( $this->importer->is_available() ); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Test that it returns a WP_Error when CubePoints is not installed. |
|
96 | - * |
|
97 | - * @since 1.0.0 |
|
98 | - * |
|
99 | - * @covers WordPoints_CubePoints_Importer::is_available |
|
100 | - */ |
|
101 | - public function test_is_cubepoints_not_available() { |
|
102 | - |
|
103 | - delete_option( 'cp_db_version' ); |
|
104 | - |
|
105 | - $this->assertWPError( $this->importer->is_available() ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Test that it returns true when CubePoints is active. |
|
110 | - * |
|
111 | - * @since 1.0.0 |
|
112 | - * |
|
113 | - * @covers WordPoints_CubePoints_Importer::is_cubepoints_active |
|
114 | - */ |
|
115 | - public function test_is_cubepoints_active() { |
|
116 | - |
|
117 | - $this->assertEquals( |
|
118 | - function_exists( 'cp_ready' ) |
|
119 | - , $this->importer->is_cubepoints_active() |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Test importing the excluded users. |
|
125 | - * |
|
126 | - * @since 1.0.0 |
|
127 | - * |
|
128 | - * @covers WordPoints_CubePoints_Importer::import_excluded_users |
|
129 | - */ |
|
130 | - public function test_import_excluded_users() { |
|
131 | - |
|
132 | - $user_ids = $this->factory->user->create_many( 3 ); |
|
133 | - $user_logins = array(); |
|
134 | - |
|
135 | - foreach ( $user_ids as $user_id ) { |
|
136 | - $user_logins[] = get_userdata( $user_id )->user_login; |
|
137 | - } |
|
138 | - |
|
139 | - update_option( 'cp_topfilter', $user_logins ); |
|
140 | - |
|
141 | - $this->do_points_import( 'excluded_users' ); |
|
142 | - |
|
143 | - $this->assertEquals( |
|
144 | - $user_ids |
|
145 | - , wordpoints_get_excluded_users( 'tests' ) |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Test importing the excluded users gives a warning if there are none. |
|
151 | - * |
|
152 | - * @since 1.0.0 |
|
153 | - * |
|
154 | - * @covers WordPoints_CubePoints_Importer::import_excluded_users |
|
155 | - */ |
|
156 | - public function test_import_excluded_users_none() { |
|
157 | - |
|
158 | - delete_option( 'cp_topfilter' ); |
|
159 | - |
|
160 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
161 | - |
|
162 | - $this->importer->do_import( |
|
163 | - array( |
|
164 | - 'points' => array( |
|
165 | - 'excluded_users' => '1', |
|
166 | - '_data' => array( 'points_type' => 'points' ), |
|
167 | - ), |
|
168 | - ) |
|
169 | - , $feedback |
|
170 | - ); |
|
171 | - |
|
172 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Test importing the points settings to points hooks. |
|
177 | - * |
|
178 | - * @since 1.1.0 |
|
179 | - * |
|
180 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
181 | - * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
182 | - * @covers WordPoints_CubePoints_Importer::format_settings_for_post_type |
|
183 | - */ |
|
184 | - public function test_import_points_settings() { |
|
185 | - |
|
186 | - update_option( 'cp_comment_points', 10 ); |
|
187 | - update_option( 'cp_post_points', 20 ); |
|
188 | - update_option( 'cp_reg_points', 50 ); |
|
189 | - |
|
190 | - $this->do_points_import( 'settings' ); |
|
191 | - |
|
192 | - $this->assertHookImported( |
|
193 | - array( |
|
194 | - 'event' => 'comment_leave\post', |
|
195 | - 'target' => array( 'comment\post', 'author', 'user' ), |
|
196 | - 'reactor' => 'points_legacy', |
|
197 | - 'points' => 10, |
|
198 | - 'points_type' => 'points', |
|
199 | - 'log_text' => 'Comment on a Post.', |
|
200 | - 'description' => 'Commenting on a Post.', |
|
201 | - 'legacy_log_type' => 'cubepoints-comment', |
|
202 | - 'legacy_meta_key' => 'comment', |
|
203 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
204 | - ) |
|
205 | - ); |
|
206 | - |
|
207 | - $this->assertHookImported( |
|
208 | - array( |
|
209 | - 'event' => 'comment_leave\page', |
|
210 | - 'target' => array( 'comment\page', 'author', 'user' ), |
|
211 | - 'reactor' => 'points_legacy', |
|
212 | - 'points' => 10, |
|
213 | - 'points_type' => 'points', |
|
214 | - 'log_text' => 'Comment on a Page.', |
|
215 | - 'description' => 'Commenting on a Page.', |
|
216 | - 'legacy_log_type' => 'cubepoints-comment', |
|
217 | - 'legacy_meta_key' => 'comment', |
|
218 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
219 | - ) |
|
220 | - ); |
|
221 | - |
|
222 | - $this->assertHookImported( |
|
223 | - array( |
|
224 | - 'event' => 'comment_leave\attachment', |
|
225 | - 'target' => array( 'comment\attachment', 'author', 'user' ), |
|
226 | - 'reactor' => 'points_legacy', |
|
227 | - 'points' => 10, |
|
228 | - 'points_type' => 'points', |
|
229 | - 'log_text' => 'Comment on a Media.', |
|
230 | - 'description' => 'Commenting on a Media.', |
|
231 | - 'legacy_log_type' => 'cubepoints-comment', |
|
232 | - 'legacy_meta_key' => 'comment', |
|
233 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - $this->assertHookImported( |
|
238 | - array( |
|
239 | - 'event' => 'post_publish\post', |
|
240 | - 'target' => array( 'post\post', 'author', 'user' ), |
|
241 | - 'reactor' => 'points_legacy', |
|
242 | - 'points' => 20, |
|
243 | - 'points_type' => 'points', |
|
244 | - 'log_text' => 'Published a Post.', |
|
245 | - 'description' => 'Publishing a Post.', |
|
246 | - 'blocker' => array( 'toggle_off' => true ), |
|
247 | - 'legacy_log_type' => 'cubepoints-post', |
|
248 | - 'legacy_meta_key' => 'post', |
|
249 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
250 | - 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
251 | - ) |
|
252 | - ); |
|
253 | - |
|
254 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
255 | - |
|
256 | - $this->assertEmpty( |
|
257 | - $reaction_store->get_reactions_to_event( 'post_publish\page' ) |
|
258 | - ); |
|
259 | - |
|
260 | - $this->assertEmpty( |
|
261 | - $reaction_store->get_reactions_to_event( 'post_publish\attachment' ) |
|
262 | - ); |
|
263 | - |
|
264 | - $this->assertEmpty( |
|
265 | - $reaction_store->get_reactions_to_event( 'media_upload' ) |
|
266 | - ); |
|
267 | - |
|
268 | - $this->assertHookImported( |
|
269 | - array( |
|
270 | - 'event' => 'user_register', |
|
271 | - 'target' => array( 'user' ), |
|
272 | - 'reactor' => 'points_legacy', |
|
273 | - 'points' => 50, |
|
274 | - 'points_type' => 'points', |
|
275 | - 'log_text' => 'Registration.', |
|
276 | - 'description' => 'Registration.', |
|
277 | - 'legacy_log_type' => 'cubepoints-register', |
|
278 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
279 | - ) |
|
280 | - ); |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Test that it imports legacy points hooks on install. |
|
285 | - * |
|
286 | - * @since 1.0.0 |
|
287 | - * |
|
288 | - * @coversNothing |
|
289 | - */ |
|
290 | - public function test_imported_post_points_hook_does_not_refire() { |
|
291 | - |
|
292 | - update_option( 'cp_post_points', 20 ); |
|
293 | - |
|
294 | - $user_id = $this->factory->user->create(); |
|
295 | - $post_id = $this->factory->post->create( |
|
296 | - array( |
|
297 | - 'post_author' => $user_id, |
|
298 | - 'post_type' => 'post', |
|
299 | - ) |
|
300 | - ); |
|
301 | - |
|
302 | - $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
303 | - |
|
304 | - $this->factory->post->update_object( |
|
305 | - $post_id |
|
306 | - , array( 'post_status' => 'draft' ) |
|
307 | - ); |
|
308 | - |
|
309 | - $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
310 | - |
|
311 | - $this->do_points_import( 'settings' ); |
|
312 | - $this->do_points_import( 'user_points' ); |
|
313 | - $this->do_points_import( 'logs' ); |
|
314 | - |
|
315 | - $this->assertEquals( |
|
316 | - 120 |
|
317 | - , wordpoints_get_points( $user_id, 'points' ) |
|
318 | - ); |
|
319 | - |
|
320 | - $this->factory->post->update_object( |
|
321 | - $post_id |
|
322 | - , array( 'post_status' => 'publish' ) |
|
323 | - ); |
|
324 | - |
|
325 | - $this->assertEquals( |
|
326 | - 120 |
|
327 | - , wordpoints_get_points( $user_id, 'points' ) |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Test importing the settings from the post author points module to points hooks. |
|
333 | - * |
|
334 | - * @since 1.1.0 |
|
335 | - * |
|
336 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
337 | - * @covers WordPoints_CubePoints_Importer::format_settings_for_post_type |
|
338 | - */ |
|
339 | - public function test_import_post_author_points() { |
|
340 | - |
|
341 | - cp_module_activation_set( 'post_author_points', 'active' ); |
|
342 | - |
|
343 | - update_option( 'cp_post_author_points', 15 ); |
|
344 | - |
|
345 | - $this->do_points_import( 'settings' ); |
|
346 | - |
|
347 | - $this->assertHookImported( |
|
348 | - array( |
|
349 | - 'event' => 'comment_leave\post', |
|
350 | - 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
351 | - 'reactor' => 'points_legacy', |
|
352 | - 'points' => 15, |
|
353 | - 'points_type' => 'points', |
|
354 | - 'log_text' => 'Received a comment on a Post.', |
|
355 | - 'description' => 'Receiving a comment on a Post.', |
|
356 | - 'legacy_log_type' => 'cubepoints-post_author', |
|
357 | - 'legacy_meta_key' => 'comment', |
|
358 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
359 | - ) |
|
360 | - ); |
|
361 | - |
|
362 | - $this->assertHookImported( |
|
363 | - array( |
|
364 | - 'event' => 'comment_leave\page', |
|
365 | - 'target' => array( 'comment\page', 'post\page', 'post\page', 'author', 'user' ), |
|
366 | - 'reactor' => 'points_legacy', |
|
367 | - 'points' => 15, |
|
368 | - 'points_type' => 'points', |
|
369 | - 'log_text' => 'Received a comment on a Page.', |
|
370 | - 'description' => 'Receiving a comment on a Page.', |
|
371 | - 'legacy_log_type' => 'cubepoints-post_author', |
|
372 | - 'legacy_meta_key' => 'comment', |
|
373 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
374 | - ) |
|
375 | - ); |
|
376 | - |
|
377 | - $this->assertHookImported( |
|
378 | - array( |
|
379 | - 'event' => 'comment_leave\attachment', |
|
380 | - 'target' => array( 'comment\attachment', 'post\attachment', 'post\attachment', 'author', 'user' ), |
|
381 | - 'reactor' => 'points_legacy', |
|
382 | - 'points' => 15, |
|
383 | - 'points_type' => 'points', |
|
384 | - 'log_text' => 'Received a comment on a Media.', |
|
385 | - 'description' => 'Receiving a comment on a Media.', |
|
386 | - 'legacy_log_type' => 'cubepoints-post_author', |
|
387 | - 'legacy_meta_key' => 'comment', |
|
388 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
389 | - ) |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Test importing the settings from the daily points module to points hooks. |
|
395 | - * |
|
396 | - * @since 1.1.0 |
|
397 | - * |
|
398 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
399 | - * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
400 | - */ |
|
401 | - public function test_import_periodic_points() { |
|
402 | - |
|
403 | - cp_module_activation_set( 'dailypoints', 'active' ); |
|
404 | - |
|
405 | - update_option( 'cp_module_dailypoints_points', 30 ); |
|
406 | - update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
407 | - |
|
408 | - $this->do_points_import( 'settings' ); |
|
409 | - |
|
410 | - $this->assertHookImported( |
|
411 | - array( |
|
412 | - 'event' => 'user_visit', |
|
413 | - 'target' => array( 'current:user' ), |
|
414 | - 'reactor' => 'points_legacy', |
|
415 | - 'points' => 30, |
|
416 | - 'points_type' => 'points', |
|
417 | - 'log_text' => 'Visiting the site.', |
|
418 | - 'description' => 'Visiting the site.', |
|
419 | - 'points_legacy_periods' => array( |
|
420 | - 'fire' => array( |
|
421 | - array( |
|
422 | - 'length' => DAY_IN_SECONDS, |
|
423 | - 'args' => array( array( 'current:user' ) ), |
|
424 | - 'relative' => true, |
|
425 | - ), |
|
426 | - ), |
|
427 | - ), |
|
428 | - 'points_legacy_reversals' => array(), |
|
429 | - 'legacy_log_type' => 'cubepoints-dailypoints', |
|
430 | - ) |
|
431 | - ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Test that the imported user visit hook respects CubePoints's started periods. |
|
436 | - * |
|
437 | - * @since 1.2.0 |
|
438 | - * |
|
439 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
440 | - * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
441 | - */ |
|
442 | - public function test_import_periodic_points_respect_old_periods() { |
|
443 | - |
|
444 | - if ( version_compare( $GLOBALS['wp_version'], '4.5', '>=' ) ) { |
|
445 | - $this->setExpectedDeprecated( 'get_currentuserinfo' ); |
|
446 | - } |
|
447 | - |
|
448 | - cp_module_activation_set( 'dailypoints', 'active' ); |
|
449 | - |
|
450 | - update_option( 'cp_module_dailypoints_points', 30 ); |
|
451 | - update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
452 | - |
|
453 | - $user_id = $this->factory->user->create(); |
|
454 | - |
|
455 | - wp_set_current_user( $user_id ); |
|
456 | - |
|
457 | - $this->assertEquals( 100, cp_getPoints( $user_id ) ); |
|
458 | - |
|
459 | - cp_module_dailypoints_checkTimer(); |
|
460 | - |
|
461 | - $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
462 | - |
|
463 | - // Running again shouldn't hit again. |
|
464 | - cp_module_dailypoints_checkTimer(); |
|
465 | - |
|
466 | - $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
467 | - |
|
468 | - $this->do_points_import( 'settings' ); |
|
469 | - $this->do_points_import( 'user_points' ); |
|
470 | - $this->do_points_import( 'logs' ); |
|
471 | - |
|
472 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
473 | - |
|
474 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
475 | - |
|
476 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
477 | - |
|
478 | - // Fast-forward and try again. |
|
479 | - global $wpdb; |
|
480 | - |
|
481 | - $id = $wpdb->get_var( |
|
482 | - " |
|
20 | + /** |
|
21 | + * The importer used in the tests. |
|
22 | + * |
|
23 | + * @since 1.0.0 |
|
24 | + * |
|
25 | + * @var WordPoints_CubePoints_Importer |
|
26 | + */ |
|
27 | + protected $importer; |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 1.0.0 |
|
31 | + */ |
|
32 | + public function setUp() { |
|
33 | + |
|
34 | + parent::setUp(); |
|
35 | + |
|
36 | + // These are usually inactive by default. We activate them in the tests |
|
37 | + // bootstrap so that they will be fully loaded, but deactivate them here to |
|
38 | + // restore default behavior. |
|
39 | + cp_module_activation_set( 'post_author_points', false ); |
|
40 | + cp_module_activation_set( 'dailypoints', false ); |
|
41 | + |
|
42 | + $this->importer = new WordPoints_CubePoints_Importer( 'Test CubePoints' ); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @since 1.1.0 |
|
47 | + */ |
|
48 | + public function tearDown() { |
|
49 | + |
|
50 | + WordPoints_Rank_Groups::deregister_group( 'points_type-points' ); |
|
51 | + WordPoints_Rank_Types::deregister_type( 'points-points' ); |
|
52 | + |
|
53 | + parent::tearDown(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Test that it returns true when CubePoints is installed. |
|
58 | + * |
|
59 | + * @since 1.0.0 |
|
60 | + * |
|
61 | + * @covers WordPoints_CubePoints_Importer::is_cubepoints_installed |
|
62 | + */ |
|
63 | + public function test_is_cubepoints_installed() { |
|
64 | + |
|
65 | + $this->assertTrue( $this->importer->is_cubepoints_installed() ); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Test that it returns false when CubePoints is not installed. |
|
70 | + * |
|
71 | + * @since 1.0.0 |
|
72 | + * |
|
73 | + * @covers WordPoints_CubePoints_Importer::is_cubepoints_installed |
|
74 | + */ |
|
75 | + public function test_is_cubepoints_not_installed() { |
|
76 | + |
|
77 | + delete_option( 'cp_db_version' ); |
|
78 | + |
|
79 | + $this->assertFalse( $this->importer->is_cubepoints_installed() ); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Test that it returns true when CubePoints is installed. |
|
84 | + * |
|
85 | + * @since 1.0.0 |
|
86 | + * |
|
87 | + * @covers WordPoints_CubePoints_Importer::is_available |
|
88 | + */ |
|
89 | + public function test_is_cubepoints_is_available() { |
|
90 | + |
|
91 | + $this->assertTrue( $this->importer->is_available() ); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Test that it returns a WP_Error when CubePoints is not installed. |
|
96 | + * |
|
97 | + * @since 1.0.0 |
|
98 | + * |
|
99 | + * @covers WordPoints_CubePoints_Importer::is_available |
|
100 | + */ |
|
101 | + public function test_is_cubepoints_not_available() { |
|
102 | + |
|
103 | + delete_option( 'cp_db_version' ); |
|
104 | + |
|
105 | + $this->assertWPError( $this->importer->is_available() ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Test that it returns true when CubePoints is active. |
|
110 | + * |
|
111 | + * @since 1.0.0 |
|
112 | + * |
|
113 | + * @covers WordPoints_CubePoints_Importer::is_cubepoints_active |
|
114 | + */ |
|
115 | + public function test_is_cubepoints_active() { |
|
116 | + |
|
117 | + $this->assertEquals( |
|
118 | + function_exists( 'cp_ready' ) |
|
119 | + , $this->importer->is_cubepoints_active() |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Test importing the excluded users. |
|
125 | + * |
|
126 | + * @since 1.0.0 |
|
127 | + * |
|
128 | + * @covers WordPoints_CubePoints_Importer::import_excluded_users |
|
129 | + */ |
|
130 | + public function test_import_excluded_users() { |
|
131 | + |
|
132 | + $user_ids = $this->factory->user->create_many( 3 ); |
|
133 | + $user_logins = array(); |
|
134 | + |
|
135 | + foreach ( $user_ids as $user_id ) { |
|
136 | + $user_logins[] = get_userdata( $user_id )->user_login; |
|
137 | + } |
|
138 | + |
|
139 | + update_option( 'cp_topfilter', $user_logins ); |
|
140 | + |
|
141 | + $this->do_points_import( 'excluded_users' ); |
|
142 | + |
|
143 | + $this->assertEquals( |
|
144 | + $user_ids |
|
145 | + , wordpoints_get_excluded_users( 'tests' ) |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Test importing the excluded users gives a warning if there are none. |
|
151 | + * |
|
152 | + * @since 1.0.0 |
|
153 | + * |
|
154 | + * @covers WordPoints_CubePoints_Importer::import_excluded_users |
|
155 | + */ |
|
156 | + public function test_import_excluded_users_none() { |
|
157 | + |
|
158 | + delete_option( 'cp_topfilter' ); |
|
159 | + |
|
160 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
161 | + |
|
162 | + $this->importer->do_import( |
|
163 | + array( |
|
164 | + 'points' => array( |
|
165 | + 'excluded_users' => '1', |
|
166 | + '_data' => array( 'points_type' => 'points' ), |
|
167 | + ), |
|
168 | + ) |
|
169 | + , $feedback |
|
170 | + ); |
|
171 | + |
|
172 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Test importing the points settings to points hooks. |
|
177 | + * |
|
178 | + * @since 1.1.0 |
|
179 | + * |
|
180 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
181 | + * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
182 | + * @covers WordPoints_CubePoints_Importer::format_settings_for_post_type |
|
183 | + */ |
|
184 | + public function test_import_points_settings() { |
|
185 | + |
|
186 | + update_option( 'cp_comment_points', 10 ); |
|
187 | + update_option( 'cp_post_points', 20 ); |
|
188 | + update_option( 'cp_reg_points', 50 ); |
|
189 | + |
|
190 | + $this->do_points_import( 'settings' ); |
|
191 | + |
|
192 | + $this->assertHookImported( |
|
193 | + array( |
|
194 | + 'event' => 'comment_leave\post', |
|
195 | + 'target' => array( 'comment\post', 'author', 'user' ), |
|
196 | + 'reactor' => 'points_legacy', |
|
197 | + 'points' => 10, |
|
198 | + 'points_type' => 'points', |
|
199 | + 'log_text' => 'Comment on a Post.', |
|
200 | + 'description' => 'Commenting on a Post.', |
|
201 | + 'legacy_log_type' => 'cubepoints-comment', |
|
202 | + 'legacy_meta_key' => 'comment', |
|
203 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
204 | + ) |
|
205 | + ); |
|
206 | + |
|
207 | + $this->assertHookImported( |
|
208 | + array( |
|
209 | + 'event' => 'comment_leave\page', |
|
210 | + 'target' => array( 'comment\page', 'author', 'user' ), |
|
211 | + 'reactor' => 'points_legacy', |
|
212 | + 'points' => 10, |
|
213 | + 'points_type' => 'points', |
|
214 | + 'log_text' => 'Comment on a Page.', |
|
215 | + 'description' => 'Commenting on a Page.', |
|
216 | + 'legacy_log_type' => 'cubepoints-comment', |
|
217 | + 'legacy_meta_key' => 'comment', |
|
218 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
219 | + ) |
|
220 | + ); |
|
221 | + |
|
222 | + $this->assertHookImported( |
|
223 | + array( |
|
224 | + 'event' => 'comment_leave\attachment', |
|
225 | + 'target' => array( 'comment\attachment', 'author', 'user' ), |
|
226 | + 'reactor' => 'points_legacy', |
|
227 | + 'points' => 10, |
|
228 | + 'points_type' => 'points', |
|
229 | + 'log_text' => 'Comment on a Media.', |
|
230 | + 'description' => 'Commenting on a Media.', |
|
231 | + 'legacy_log_type' => 'cubepoints-comment', |
|
232 | + 'legacy_meta_key' => 'comment', |
|
233 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + $this->assertHookImported( |
|
238 | + array( |
|
239 | + 'event' => 'post_publish\post', |
|
240 | + 'target' => array( 'post\post', 'author', 'user' ), |
|
241 | + 'reactor' => 'points_legacy', |
|
242 | + 'points' => 20, |
|
243 | + 'points_type' => 'points', |
|
244 | + 'log_text' => 'Published a Post.', |
|
245 | + 'description' => 'Publishing a Post.', |
|
246 | + 'blocker' => array( 'toggle_off' => true ), |
|
247 | + 'legacy_log_type' => 'cubepoints-post', |
|
248 | + 'legacy_meta_key' => 'post', |
|
249 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
250 | + 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
251 | + ) |
|
252 | + ); |
|
253 | + |
|
254 | + $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
255 | + |
|
256 | + $this->assertEmpty( |
|
257 | + $reaction_store->get_reactions_to_event( 'post_publish\page' ) |
|
258 | + ); |
|
259 | + |
|
260 | + $this->assertEmpty( |
|
261 | + $reaction_store->get_reactions_to_event( 'post_publish\attachment' ) |
|
262 | + ); |
|
263 | + |
|
264 | + $this->assertEmpty( |
|
265 | + $reaction_store->get_reactions_to_event( 'media_upload' ) |
|
266 | + ); |
|
267 | + |
|
268 | + $this->assertHookImported( |
|
269 | + array( |
|
270 | + 'event' => 'user_register', |
|
271 | + 'target' => array( 'user' ), |
|
272 | + 'reactor' => 'points_legacy', |
|
273 | + 'points' => 50, |
|
274 | + 'points_type' => 'points', |
|
275 | + 'log_text' => 'Registration.', |
|
276 | + 'description' => 'Registration.', |
|
277 | + 'legacy_log_type' => 'cubepoints-register', |
|
278 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
279 | + ) |
|
280 | + ); |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Test that it imports legacy points hooks on install. |
|
285 | + * |
|
286 | + * @since 1.0.0 |
|
287 | + * |
|
288 | + * @coversNothing |
|
289 | + */ |
|
290 | + public function test_imported_post_points_hook_does_not_refire() { |
|
291 | + |
|
292 | + update_option( 'cp_post_points', 20 ); |
|
293 | + |
|
294 | + $user_id = $this->factory->user->create(); |
|
295 | + $post_id = $this->factory->post->create( |
|
296 | + array( |
|
297 | + 'post_author' => $user_id, |
|
298 | + 'post_type' => 'post', |
|
299 | + ) |
|
300 | + ); |
|
301 | + |
|
302 | + $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
303 | + |
|
304 | + $this->factory->post->update_object( |
|
305 | + $post_id |
|
306 | + , array( 'post_status' => 'draft' ) |
|
307 | + ); |
|
308 | + |
|
309 | + $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
310 | + |
|
311 | + $this->do_points_import( 'settings' ); |
|
312 | + $this->do_points_import( 'user_points' ); |
|
313 | + $this->do_points_import( 'logs' ); |
|
314 | + |
|
315 | + $this->assertEquals( |
|
316 | + 120 |
|
317 | + , wordpoints_get_points( $user_id, 'points' ) |
|
318 | + ); |
|
319 | + |
|
320 | + $this->factory->post->update_object( |
|
321 | + $post_id |
|
322 | + , array( 'post_status' => 'publish' ) |
|
323 | + ); |
|
324 | + |
|
325 | + $this->assertEquals( |
|
326 | + 120 |
|
327 | + , wordpoints_get_points( $user_id, 'points' ) |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Test importing the settings from the post author points module to points hooks. |
|
333 | + * |
|
334 | + * @since 1.1.0 |
|
335 | + * |
|
336 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
337 | + * @covers WordPoints_CubePoints_Importer::format_settings_for_post_type |
|
338 | + */ |
|
339 | + public function test_import_post_author_points() { |
|
340 | + |
|
341 | + cp_module_activation_set( 'post_author_points', 'active' ); |
|
342 | + |
|
343 | + update_option( 'cp_post_author_points', 15 ); |
|
344 | + |
|
345 | + $this->do_points_import( 'settings' ); |
|
346 | + |
|
347 | + $this->assertHookImported( |
|
348 | + array( |
|
349 | + 'event' => 'comment_leave\post', |
|
350 | + 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
351 | + 'reactor' => 'points_legacy', |
|
352 | + 'points' => 15, |
|
353 | + 'points_type' => 'points', |
|
354 | + 'log_text' => 'Received a comment on a Post.', |
|
355 | + 'description' => 'Receiving a comment on a Post.', |
|
356 | + 'legacy_log_type' => 'cubepoints-post_author', |
|
357 | + 'legacy_meta_key' => 'comment', |
|
358 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
359 | + ) |
|
360 | + ); |
|
361 | + |
|
362 | + $this->assertHookImported( |
|
363 | + array( |
|
364 | + 'event' => 'comment_leave\page', |
|
365 | + 'target' => array( 'comment\page', 'post\page', 'post\page', 'author', 'user' ), |
|
366 | + 'reactor' => 'points_legacy', |
|
367 | + 'points' => 15, |
|
368 | + 'points_type' => 'points', |
|
369 | + 'log_text' => 'Received a comment on a Page.', |
|
370 | + 'description' => 'Receiving a comment on a Page.', |
|
371 | + 'legacy_log_type' => 'cubepoints-post_author', |
|
372 | + 'legacy_meta_key' => 'comment', |
|
373 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
374 | + ) |
|
375 | + ); |
|
376 | + |
|
377 | + $this->assertHookImported( |
|
378 | + array( |
|
379 | + 'event' => 'comment_leave\attachment', |
|
380 | + 'target' => array( 'comment\attachment', 'post\attachment', 'post\attachment', 'author', 'user' ), |
|
381 | + 'reactor' => 'points_legacy', |
|
382 | + 'points' => 15, |
|
383 | + 'points_type' => 'points', |
|
384 | + 'log_text' => 'Received a comment on a Media.', |
|
385 | + 'description' => 'Receiving a comment on a Media.', |
|
386 | + 'legacy_log_type' => 'cubepoints-post_author', |
|
387 | + 'legacy_meta_key' => 'comment', |
|
388 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
389 | + ) |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Test importing the settings from the daily points module to points hooks. |
|
395 | + * |
|
396 | + * @since 1.1.0 |
|
397 | + * |
|
398 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
399 | + * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
400 | + */ |
|
401 | + public function test_import_periodic_points() { |
|
402 | + |
|
403 | + cp_module_activation_set( 'dailypoints', 'active' ); |
|
404 | + |
|
405 | + update_option( 'cp_module_dailypoints_points', 30 ); |
|
406 | + update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
407 | + |
|
408 | + $this->do_points_import( 'settings' ); |
|
409 | + |
|
410 | + $this->assertHookImported( |
|
411 | + array( |
|
412 | + 'event' => 'user_visit', |
|
413 | + 'target' => array( 'current:user' ), |
|
414 | + 'reactor' => 'points_legacy', |
|
415 | + 'points' => 30, |
|
416 | + 'points_type' => 'points', |
|
417 | + 'log_text' => 'Visiting the site.', |
|
418 | + 'description' => 'Visiting the site.', |
|
419 | + 'points_legacy_periods' => array( |
|
420 | + 'fire' => array( |
|
421 | + array( |
|
422 | + 'length' => DAY_IN_SECONDS, |
|
423 | + 'args' => array( array( 'current:user' ) ), |
|
424 | + 'relative' => true, |
|
425 | + ), |
|
426 | + ), |
|
427 | + ), |
|
428 | + 'points_legacy_reversals' => array(), |
|
429 | + 'legacy_log_type' => 'cubepoints-dailypoints', |
|
430 | + ) |
|
431 | + ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Test that the imported user visit hook respects CubePoints's started periods. |
|
436 | + * |
|
437 | + * @since 1.2.0 |
|
438 | + * |
|
439 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
440 | + * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
441 | + */ |
|
442 | + public function test_import_periodic_points_respect_old_periods() { |
|
443 | + |
|
444 | + if ( version_compare( $GLOBALS['wp_version'], '4.5', '>=' ) ) { |
|
445 | + $this->setExpectedDeprecated( 'get_currentuserinfo' ); |
|
446 | + } |
|
447 | + |
|
448 | + cp_module_activation_set( 'dailypoints', 'active' ); |
|
449 | + |
|
450 | + update_option( 'cp_module_dailypoints_points', 30 ); |
|
451 | + update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
452 | + |
|
453 | + $user_id = $this->factory->user->create(); |
|
454 | + |
|
455 | + wp_set_current_user( $user_id ); |
|
456 | + |
|
457 | + $this->assertEquals( 100, cp_getPoints( $user_id ) ); |
|
458 | + |
|
459 | + cp_module_dailypoints_checkTimer(); |
|
460 | + |
|
461 | + $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
462 | + |
|
463 | + // Running again shouldn't hit again. |
|
464 | + cp_module_dailypoints_checkTimer(); |
|
465 | + |
|
466 | + $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
467 | + |
|
468 | + $this->do_points_import( 'settings' ); |
|
469 | + $this->do_points_import( 'user_points' ); |
|
470 | + $this->do_points_import( 'logs' ); |
|
471 | + |
|
472 | + $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
473 | + |
|
474 | + wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
475 | + |
|
476 | + $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
477 | + |
|
478 | + // Fast-forward and try again. |
|
479 | + global $wpdb; |
|
480 | + |
|
481 | + $id = $wpdb->get_var( |
|
482 | + " |
|
483 | 483 | SELECT `id` |
484 | 484 | FROM `{$wpdb->wordpoints_points_logs}` |
485 | 485 | ORDER BY `id` DESC |
486 | 486 | LIMIT 1 |
487 | 487 | " |
488 | - ); |
|
489 | - |
|
490 | - // Don't go all the way yet. |
|
491 | - $updated = $wpdb->update( |
|
492 | - $wpdb->wordpoints_points_logs |
|
493 | - , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS + HOUR_IN_SECONDS ) ) |
|
494 | - , array( 'id' => $id ) |
|
495 | - , array( '%s' ) |
|
496 | - , array( '%d' ) |
|
497 | - ); |
|
498 | - |
|
499 | - $this->assertEquals( 1, $updated ); |
|
500 | - |
|
501 | - // The periods cache will still hold the old date. |
|
502 | - $this->flush_cache(); |
|
503 | - |
|
504 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
505 | - |
|
506 | - // Points should have been awarded again yet. |
|
507 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
508 | - |
|
509 | - // This time go all the way. |
|
510 | - $updated = $wpdb->update( |
|
511 | - $wpdb->wordpoints_points_logs |
|
512 | - , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS - 1 ) ) |
|
513 | - , array( 'id' => $id ) |
|
514 | - , array( '%s' ) |
|
515 | - , array( '%d' ) |
|
516 | - ); |
|
517 | - |
|
518 | - $this->assertEquals( 1, $updated ); |
|
519 | - |
|
520 | - // The periods cache will still hold the old date. |
|
521 | - $this->flush_cache(); |
|
522 | - |
|
523 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
524 | - |
|
525 | - // Points should have been awarded again. |
|
526 | - $this->assertEquals( 160, wordpoints_get_points( $user_id, 'points' ) ); |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Test the imported periods when the site has a positive GMT offset. |
|
531 | - * |
|
532 | - * @since 1.2.0 |
|
533 | - * |
|
534 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
535 | - * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
536 | - */ |
|
537 | - public function test_import_periods_positive_gmt_offset() { |
|
538 | - |
|
539 | - update_option( 'gmt_offset', 5 ); |
|
540 | - |
|
541 | - $this->test_import_periodic_points_respect_old_periods(); |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Test the imported periods when the site has a negative GMT offset. |
|
546 | - * |
|
547 | - * @since 1.2.0 |
|
548 | - * |
|
549 | - * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
550 | - * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
551 | - */ |
|
552 | - public function test_import_periods_negative_gmt_offset() { |
|
553 | - |
|
554 | - update_option( 'gmt_offset', -5 ); |
|
555 | - |
|
556 | - $this->test_import_periodic_points_respect_old_periods(); |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Test importing the user's points. |
|
561 | - * |
|
562 | - * @since 1.0.0 |
|
563 | - * |
|
564 | - * @covers WordPoints_CubePoints_Importer::import_user_points |
|
565 | - * @covers WordPoints_CubePoints_Importer::get_next_user_points_batch |
|
566 | - */ |
|
567 | - public function test_import_user_points() { |
|
568 | - |
|
569 | - $user_points = array(); |
|
570 | - |
|
571 | - foreach ( array( 20, 10, 45 ) as $points ) { |
|
572 | - |
|
573 | - $user_id = $this->factory->user->create(); |
|
574 | - cp_updatePoints( $user_id, $points ); |
|
575 | - $user_points[ $user_id ] = $points; |
|
576 | - } |
|
577 | - |
|
578 | - $this->do_points_import( 'user_points' ); |
|
579 | - |
|
580 | - foreach ( $user_points as $user_id => $points ) { |
|
581 | - $this->assertEquals( $points, wordpoints_get_points( $user_id, 'points' ) ); |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Test importing the points logs. |
|
587 | - * |
|
588 | - * @since 1.0.0 |
|
589 | - * |
|
590 | - * @covers WordPoints_CubePoints_Importer::import_points_logs |
|
591 | - * @covers WordPoints_CubePoints_Importer::import_points_log |
|
592 | - * @covers WordPoints_CubePoints_Importer::get_next_points_logs_batch |
|
593 | - * @covers WordPoints_CubePoints_Importer::render_points_log_text |
|
594 | - */ |
|
595 | - public function test_import_points_logs() { |
|
596 | - |
|
597 | - remove_action( 'publish_post', 'cp_newPost' ); |
|
598 | - |
|
599 | - $user_id = $this->factory->user->create(); |
|
600 | - cp_points( 'misc', $user_id, 10, 'Testing things.' ); |
|
601 | - |
|
602 | - $user_id_2 = $this->factory->user->create(); |
|
603 | - $post_id = $this->factory->post->create(); |
|
604 | - cp_points( 'post', $user_id_2, 25, $post_id ); |
|
605 | - |
|
606 | - $this->do_points_import( 'logs' ); |
|
607 | - |
|
608 | - $query = new WordPoints_Points_Logs_Query( array( 'orderby' => 'id' ) ); |
|
609 | - $logs = $query->get(); |
|
610 | - |
|
611 | - $this->assertCount( 4, $logs ); |
|
612 | - |
|
613 | - $log = $logs[2]; |
|
614 | - |
|
615 | - $this->assertEquals( $user_id, $log->user_id ); |
|
616 | - $this->assertEquals( 10, $log->points ); |
|
617 | - $this->assertEquals( 'Testing things.', $log->text ); |
|
618 | - $this->assertEquals( 'cubepoints-misc', $log->log_type ); |
|
619 | - $this->assertEquals( 'points', $log->points_type ); |
|
620 | - $this->assertEquals( 'misc', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
621 | - $this->assertEquals( 'Testing things.', wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
622 | - |
|
623 | - $log = $logs[0]; |
|
624 | - |
|
625 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
626 | - $this->assertEquals( 25, $log->points ); |
|
627 | - $this->assertStringMatchesFormat( 'Post on "<a href="%s">Post title %s</a>"', $log->text ); |
|
628 | - $this->assertEquals( 'cubepoints-post', $log->log_type ); |
|
629 | - $this->assertEquals( 'points', $log->points_type ); |
|
630 | - $this->assertEquals( 'post', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
631 | - $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
632 | - $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'post', true ) ); |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Test importing points logs that have been reversed. |
|
637 | - * |
|
638 | - * @since 1.2.0 |
|
639 | - * |
|
640 | - * @covers WordPoints_CubePoints_Importer::import_points_logs |
|
641 | - * @covers WordPoints_CubePoints_Importer::import_points_log |
|
642 | - * @covers WordPoints_CubePoints_Importer::get_next_points_logs_batch |
|
643 | - * @covers WordPoints_CubePoints_Importer::render_points_log_text |
|
644 | - */ |
|
645 | - public function test_import_points_logs_reversals() { |
|
646 | - |
|
647 | - remove_action( 'publish_post', 'cp_newPost' ); |
|
648 | - remove_action( 'cp_comment_add', 'cp_module_post_author_points_comment_add' ); |
|
649 | - remove_action( 'cp_comment_remove', 'cp_module_post_author_points_comment_remove' ); |
|
650 | - |
|
651 | - update_option( 'cp_comment_points', 10 ); |
|
652 | - update_option( 'cp_del_comment_points', 10 ); |
|
653 | - |
|
654 | - $user_id = $this->factory->user->create(); |
|
655 | - $post_id = $this->factory->post->create(); |
|
656 | - |
|
657 | - $comment_id = $this->factory->comment->create( |
|
658 | - array( 'user_id' => $user_id, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
659 | - ); |
|
660 | - |
|
661 | - wp_update_comment( |
|
662 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
663 | - ); |
|
664 | - |
|
665 | - $user_id_2 = $this->factory->user->create(); |
|
666 | - $comment_id_2 = $this->factory->comment->create( |
|
667 | - array( 'user_id' => $user_id_2, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
668 | - ); |
|
669 | - |
|
670 | - wp_update_comment( |
|
671 | - array( 'comment_ID' => $comment_id_2, 'comment_approved' => 1 ) |
|
672 | - ); |
|
673 | - |
|
674 | - // Now reverse the two transactions. |
|
675 | - wp_update_comment( |
|
676 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
677 | - ); |
|
678 | - |
|
679 | - wp_update_comment( |
|
680 | - array( 'comment_ID' => $comment_id_2, 'comment_approved' => 0 ) |
|
681 | - ); |
|
682 | - |
|
683 | - $this->do_points_import( 'logs' ); |
|
684 | - |
|
685 | - $query = new WordPoints_Points_Logs_Query( |
|
686 | - array( 'orderby' => 'id', 'order' => 'ASC' ) |
|
687 | - ); |
|
688 | - |
|
689 | - $logs = $query->get(); |
|
690 | - |
|
691 | - $this->assertCount( 6, $logs ); |
|
692 | - |
|
693 | - // The first log will be for when the first user was created, so we skip it. |
|
694 | - $log = $logs[1]; |
|
695 | - |
|
696 | - $this->assertEquals( $user_id, $log->user_id ); |
|
697 | - $this->assertEquals( 10, $log->points ); |
|
698 | - $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
699 | - $this->assertEquals( 'points', $log->points_type ); |
|
700 | - $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
701 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
702 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
703 | - $this->assertEquals( $logs[4]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
704 | - |
|
705 | - // The third log is for when the second user was created, so we skip it, too. |
|
706 | - $log = $logs[3]; |
|
707 | - |
|
708 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
709 | - $this->assertEquals( 10, $log->points ); |
|
710 | - $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
711 | - $this->assertEquals( 'points', $log->points_type ); |
|
712 | - $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
713 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
714 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
715 | - $this->assertEquals( $logs[5]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
716 | - |
|
717 | - $log = $logs[4]; |
|
718 | - |
|
719 | - $this->assertEquals( $user_id, $log->user_id ); |
|
720 | - $this->assertEquals( -10, $log->points ); |
|
721 | - $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
722 | - $this->assertEquals( 'points', $log->points_type ); |
|
723 | - $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
724 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
725 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
726 | - $this->assertEquals( $logs[1]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
727 | - |
|
728 | - $log = $logs[5]; |
|
729 | - |
|
730 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
731 | - $this->assertEquals( -10, $log->points ); |
|
732 | - $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
733 | - $this->assertEquals( 'points', $log->points_type ); |
|
734 | - $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
735 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
736 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
737 | - $this->assertEquals( $logs[3]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Test that ranks are imported. |
|
742 | - * |
|
743 | - * @since 1.1.0 |
|
744 | - * |
|
745 | - * @covers WordPoints_CubePoints_Importer::import_ranks |
|
746 | - */ |
|
747 | - public function test_ranks_import() { |
|
748 | - |
|
749 | - update_option( |
|
750 | - 'cp_module_ranks_data' |
|
751 | - , array( 0 => 'Newbie', 1000 => 'Biggie', 5000 => 'Oldie' ) |
|
752 | - ); |
|
753 | - |
|
754 | - wordpoints_register_points_ranks(); |
|
755 | - |
|
756 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
757 | - |
|
758 | - $this->importer->do_import( |
|
759 | - array( |
|
760 | - 'ranks' => array( |
|
761 | - 'ranks' => '1', |
|
762 | - '_data' => array( 'rank_group' => 'points_type-points' ), |
|
763 | - ), |
|
764 | - ) |
|
765 | - , $feedback |
|
766 | - ); |
|
767 | - |
|
768 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
769 | - $this->assertCount( 1, $feedback->messages['success'] ); |
|
770 | - |
|
771 | - $group = WordPoints_Rank_Groups::get_group( 'points_type-points' ); |
|
772 | - |
|
773 | - $base_rank = wordpoints_get_rank( $group->get_rank( 0 ) ); |
|
774 | - $this->assertEquals( 'base', $base_rank->type ); |
|
775 | - $this->assertEquals( 'Newbie', $base_rank->name ); |
|
776 | - |
|
777 | - $second_rank = wordpoints_get_rank( $group->get_rank( 1 ) ); |
|
778 | - $this->assertEquals( 1000, $second_rank->points ); |
|
779 | - $this->assertEquals( 'Biggie', $second_rank->name ); |
|
780 | - |
|
781 | - $third_rank = wordpoints_get_rank( $group->get_rank( 2 ) ); |
|
782 | - $this->assertEquals( 5000, $third_rank->points ); |
|
783 | - $this->assertEquals( 'Oldie', $third_rank->name ); |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * Test that there is an error if there are no ranks import. |
|
788 | - * |
|
789 | - * @since 1.1.0 |
|
790 | - * |
|
791 | - * @covers WordPoints_CubePoints_Importer::import_ranks |
|
792 | - */ |
|
793 | - public function test_error_if_no_ranks_to_import() { |
|
794 | - |
|
795 | - wordpoints_register_points_ranks(); |
|
796 | - |
|
797 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
798 | - |
|
799 | - $this->importer->do_import( |
|
800 | - array( |
|
801 | - 'ranks' => array( |
|
802 | - 'ranks' => '1', |
|
803 | - '_data' => array( 'rank_group' => 'points_type-points' ), |
|
804 | - ), |
|
805 | - ) |
|
806 | - , $feedback |
|
807 | - ); |
|
808 | - |
|
809 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
810 | - $this->assertCount( 1, $feedback->messages['error'] ); |
|
811 | - |
|
812 | - } |
|
813 | - |
|
814 | - // |
|
815 | - // Helpers. |
|
816 | - // |
|
817 | - |
|
818 | - /** |
|
819 | - * Do the import for the points settings. |
|
820 | - * |
|
821 | - * @since 1.1.0 |
|
822 | - * |
|
823 | - * @param string $type The type of points import. |
|
824 | - */ |
|
825 | - protected function do_points_import( $type ) { |
|
826 | - |
|
827 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
828 | - |
|
829 | - $this->importer->do_import( |
|
830 | - array( |
|
831 | - 'points' => array( |
|
832 | - $type => '1', |
|
833 | - '_data' => array( 'points_type' => 'points' ), |
|
834 | - ), |
|
835 | - ) |
|
836 | - , $feedback |
|
837 | - ); |
|
838 | - |
|
839 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
840 | - $this->assertCount( 1, $feedback->messages['success'] ); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Assert that a hook was imported. |
|
845 | - * |
|
846 | - * Actually just checks that the hook exists. |
|
847 | - * |
|
848 | - * @since 1.1.0 |
|
849 | - * @since 1.2.0 Now just accepts a single parameter, $settings. |
|
850 | - * |
|
851 | - * @param array $settings The expected reaction settings. |
|
852 | - */ |
|
853 | - protected function assertHookImported( $settings ) { |
|
854 | - |
|
855 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
856 | - |
|
857 | - $reactions = $reaction_store->get_reactions_to_event( $settings['event'] ); |
|
858 | - |
|
859 | - $this->assertNotEmpty( $reactions ); |
|
860 | - |
|
861 | - foreach ( $reactions as $reaction ) { |
|
862 | - if ( $settings === $reaction->get_all_meta() ) { |
|
863 | - $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
864 | - return; |
|
865 | - } |
|
866 | - } |
|
867 | - |
|
868 | - $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
869 | - } |
|
488 | + ); |
|
489 | + |
|
490 | + // Don't go all the way yet. |
|
491 | + $updated = $wpdb->update( |
|
492 | + $wpdb->wordpoints_points_logs |
|
493 | + , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS + HOUR_IN_SECONDS ) ) |
|
494 | + , array( 'id' => $id ) |
|
495 | + , array( '%s' ) |
|
496 | + , array( '%d' ) |
|
497 | + ); |
|
498 | + |
|
499 | + $this->assertEquals( 1, $updated ); |
|
500 | + |
|
501 | + // The periods cache will still hold the old date. |
|
502 | + $this->flush_cache(); |
|
503 | + |
|
504 | + wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
505 | + |
|
506 | + // Points should have been awarded again yet. |
|
507 | + $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
508 | + |
|
509 | + // This time go all the way. |
|
510 | + $updated = $wpdb->update( |
|
511 | + $wpdb->wordpoints_points_logs |
|
512 | + , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS - 1 ) ) |
|
513 | + , array( 'id' => $id ) |
|
514 | + , array( '%s' ) |
|
515 | + , array( '%d' ) |
|
516 | + ); |
|
517 | + |
|
518 | + $this->assertEquals( 1, $updated ); |
|
519 | + |
|
520 | + // The periods cache will still hold the old date. |
|
521 | + $this->flush_cache(); |
|
522 | + |
|
523 | + wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
524 | + |
|
525 | + // Points should have been awarded again. |
|
526 | + $this->assertEquals( 160, wordpoints_get_points( $user_id, 'points' ) ); |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Test the imported periods when the site has a positive GMT offset. |
|
531 | + * |
|
532 | + * @since 1.2.0 |
|
533 | + * |
|
534 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
535 | + * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
536 | + */ |
|
537 | + public function test_import_periods_positive_gmt_offset() { |
|
538 | + |
|
539 | + update_option( 'gmt_offset', 5 ); |
|
540 | + |
|
541 | + $this->test_import_periodic_points_respect_old_periods(); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Test the imported periods when the site has a negative GMT offset. |
|
546 | + * |
|
547 | + * @since 1.2.0 |
|
548 | + * |
|
549 | + * @covers WordPoints_CubePoints_Importer::import_points_settings |
|
550 | + * @covers WordPoints_CubePoints_Importer::import_daily_points_hook |
|
551 | + */ |
|
552 | + public function test_import_periods_negative_gmt_offset() { |
|
553 | + |
|
554 | + update_option( 'gmt_offset', -5 ); |
|
555 | + |
|
556 | + $this->test_import_periodic_points_respect_old_periods(); |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Test importing the user's points. |
|
561 | + * |
|
562 | + * @since 1.0.0 |
|
563 | + * |
|
564 | + * @covers WordPoints_CubePoints_Importer::import_user_points |
|
565 | + * @covers WordPoints_CubePoints_Importer::get_next_user_points_batch |
|
566 | + */ |
|
567 | + public function test_import_user_points() { |
|
568 | + |
|
569 | + $user_points = array(); |
|
570 | + |
|
571 | + foreach ( array( 20, 10, 45 ) as $points ) { |
|
572 | + |
|
573 | + $user_id = $this->factory->user->create(); |
|
574 | + cp_updatePoints( $user_id, $points ); |
|
575 | + $user_points[ $user_id ] = $points; |
|
576 | + } |
|
577 | + |
|
578 | + $this->do_points_import( 'user_points' ); |
|
579 | + |
|
580 | + foreach ( $user_points as $user_id => $points ) { |
|
581 | + $this->assertEquals( $points, wordpoints_get_points( $user_id, 'points' ) ); |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Test importing the points logs. |
|
587 | + * |
|
588 | + * @since 1.0.0 |
|
589 | + * |
|
590 | + * @covers WordPoints_CubePoints_Importer::import_points_logs |
|
591 | + * @covers WordPoints_CubePoints_Importer::import_points_log |
|
592 | + * @covers WordPoints_CubePoints_Importer::get_next_points_logs_batch |
|
593 | + * @covers WordPoints_CubePoints_Importer::render_points_log_text |
|
594 | + */ |
|
595 | + public function test_import_points_logs() { |
|
596 | + |
|
597 | + remove_action( 'publish_post', 'cp_newPost' ); |
|
598 | + |
|
599 | + $user_id = $this->factory->user->create(); |
|
600 | + cp_points( 'misc', $user_id, 10, 'Testing things.' ); |
|
601 | + |
|
602 | + $user_id_2 = $this->factory->user->create(); |
|
603 | + $post_id = $this->factory->post->create(); |
|
604 | + cp_points( 'post', $user_id_2, 25, $post_id ); |
|
605 | + |
|
606 | + $this->do_points_import( 'logs' ); |
|
607 | + |
|
608 | + $query = new WordPoints_Points_Logs_Query( array( 'orderby' => 'id' ) ); |
|
609 | + $logs = $query->get(); |
|
610 | + |
|
611 | + $this->assertCount( 4, $logs ); |
|
612 | + |
|
613 | + $log = $logs[2]; |
|
614 | + |
|
615 | + $this->assertEquals( $user_id, $log->user_id ); |
|
616 | + $this->assertEquals( 10, $log->points ); |
|
617 | + $this->assertEquals( 'Testing things.', $log->text ); |
|
618 | + $this->assertEquals( 'cubepoints-misc', $log->log_type ); |
|
619 | + $this->assertEquals( 'points', $log->points_type ); |
|
620 | + $this->assertEquals( 'misc', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
621 | + $this->assertEquals( 'Testing things.', wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
622 | + |
|
623 | + $log = $logs[0]; |
|
624 | + |
|
625 | + $this->assertEquals( $user_id_2, $log->user_id ); |
|
626 | + $this->assertEquals( 25, $log->points ); |
|
627 | + $this->assertStringMatchesFormat( 'Post on "<a href="%s">Post title %s</a>"', $log->text ); |
|
628 | + $this->assertEquals( 'cubepoints-post', $log->log_type ); |
|
629 | + $this->assertEquals( 'points', $log->points_type ); |
|
630 | + $this->assertEquals( 'post', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
631 | + $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
632 | + $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'post', true ) ); |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Test importing points logs that have been reversed. |
|
637 | + * |
|
638 | + * @since 1.2.0 |
|
639 | + * |
|
640 | + * @covers WordPoints_CubePoints_Importer::import_points_logs |
|
641 | + * @covers WordPoints_CubePoints_Importer::import_points_log |
|
642 | + * @covers WordPoints_CubePoints_Importer::get_next_points_logs_batch |
|
643 | + * @covers WordPoints_CubePoints_Importer::render_points_log_text |
|
644 | + */ |
|
645 | + public function test_import_points_logs_reversals() { |
|
646 | + |
|
647 | + remove_action( 'publish_post', 'cp_newPost' ); |
|
648 | + remove_action( 'cp_comment_add', 'cp_module_post_author_points_comment_add' ); |
|
649 | + remove_action( 'cp_comment_remove', 'cp_module_post_author_points_comment_remove' ); |
|
650 | + |
|
651 | + update_option( 'cp_comment_points', 10 ); |
|
652 | + update_option( 'cp_del_comment_points', 10 ); |
|
653 | + |
|
654 | + $user_id = $this->factory->user->create(); |
|
655 | + $post_id = $this->factory->post->create(); |
|
656 | + |
|
657 | + $comment_id = $this->factory->comment->create( |
|
658 | + array( 'user_id' => $user_id, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
659 | + ); |
|
660 | + |
|
661 | + wp_update_comment( |
|
662 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
663 | + ); |
|
664 | + |
|
665 | + $user_id_2 = $this->factory->user->create(); |
|
666 | + $comment_id_2 = $this->factory->comment->create( |
|
667 | + array( 'user_id' => $user_id_2, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
668 | + ); |
|
669 | + |
|
670 | + wp_update_comment( |
|
671 | + array( 'comment_ID' => $comment_id_2, 'comment_approved' => 1 ) |
|
672 | + ); |
|
673 | + |
|
674 | + // Now reverse the two transactions. |
|
675 | + wp_update_comment( |
|
676 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
677 | + ); |
|
678 | + |
|
679 | + wp_update_comment( |
|
680 | + array( 'comment_ID' => $comment_id_2, 'comment_approved' => 0 ) |
|
681 | + ); |
|
682 | + |
|
683 | + $this->do_points_import( 'logs' ); |
|
684 | + |
|
685 | + $query = new WordPoints_Points_Logs_Query( |
|
686 | + array( 'orderby' => 'id', 'order' => 'ASC' ) |
|
687 | + ); |
|
688 | + |
|
689 | + $logs = $query->get(); |
|
690 | + |
|
691 | + $this->assertCount( 6, $logs ); |
|
692 | + |
|
693 | + // The first log will be for when the first user was created, so we skip it. |
|
694 | + $log = $logs[1]; |
|
695 | + |
|
696 | + $this->assertEquals( $user_id, $log->user_id ); |
|
697 | + $this->assertEquals( 10, $log->points ); |
|
698 | + $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
699 | + $this->assertEquals( 'points', $log->points_type ); |
|
700 | + $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
701 | + $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
702 | + $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
703 | + $this->assertEquals( $logs[4]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
704 | + |
|
705 | + // The third log is for when the second user was created, so we skip it, too. |
|
706 | + $log = $logs[3]; |
|
707 | + |
|
708 | + $this->assertEquals( $user_id_2, $log->user_id ); |
|
709 | + $this->assertEquals( 10, $log->points ); |
|
710 | + $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
711 | + $this->assertEquals( 'points', $log->points_type ); |
|
712 | + $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
713 | + $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
714 | + $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
715 | + $this->assertEquals( $logs[5]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
716 | + |
|
717 | + $log = $logs[4]; |
|
718 | + |
|
719 | + $this->assertEquals( $user_id, $log->user_id ); |
|
720 | + $this->assertEquals( -10, $log->points ); |
|
721 | + $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
722 | + $this->assertEquals( 'points', $log->points_type ); |
|
723 | + $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
724 | + $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
725 | + $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
726 | + $this->assertEquals( $logs[1]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
727 | + |
|
728 | + $log = $logs[5]; |
|
729 | + |
|
730 | + $this->assertEquals( $user_id_2, $log->user_id ); |
|
731 | + $this->assertEquals( -10, $log->points ); |
|
732 | + $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
733 | + $this->assertEquals( 'points', $log->points_type ); |
|
734 | + $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
735 | + $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
736 | + $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
737 | + $this->assertEquals( $logs[3]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Test that ranks are imported. |
|
742 | + * |
|
743 | + * @since 1.1.0 |
|
744 | + * |
|
745 | + * @covers WordPoints_CubePoints_Importer::import_ranks |
|
746 | + */ |
|
747 | + public function test_ranks_import() { |
|
748 | + |
|
749 | + update_option( |
|
750 | + 'cp_module_ranks_data' |
|
751 | + , array( 0 => 'Newbie', 1000 => 'Biggie', 5000 => 'Oldie' ) |
|
752 | + ); |
|
753 | + |
|
754 | + wordpoints_register_points_ranks(); |
|
755 | + |
|
756 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
757 | + |
|
758 | + $this->importer->do_import( |
|
759 | + array( |
|
760 | + 'ranks' => array( |
|
761 | + 'ranks' => '1', |
|
762 | + '_data' => array( 'rank_group' => 'points_type-points' ), |
|
763 | + ), |
|
764 | + ) |
|
765 | + , $feedback |
|
766 | + ); |
|
767 | + |
|
768 | + $this->assertCount( 4, $feedback->messages['info'] ); |
|
769 | + $this->assertCount( 1, $feedback->messages['success'] ); |
|
770 | + |
|
771 | + $group = WordPoints_Rank_Groups::get_group( 'points_type-points' ); |
|
772 | + |
|
773 | + $base_rank = wordpoints_get_rank( $group->get_rank( 0 ) ); |
|
774 | + $this->assertEquals( 'base', $base_rank->type ); |
|
775 | + $this->assertEquals( 'Newbie', $base_rank->name ); |
|
776 | + |
|
777 | + $second_rank = wordpoints_get_rank( $group->get_rank( 1 ) ); |
|
778 | + $this->assertEquals( 1000, $second_rank->points ); |
|
779 | + $this->assertEquals( 'Biggie', $second_rank->name ); |
|
780 | + |
|
781 | + $third_rank = wordpoints_get_rank( $group->get_rank( 2 ) ); |
|
782 | + $this->assertEquals( 5000, $third_rank->points ); |
|
783 | + $this->assertEquals( 'Oldie', $third_rank->name ); |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * Test that there is an error if there are no ranks import. |
|
788 | + * |
|
789 | + * @since 1.1.0 |
|
790 | + * |
|
791 | + * @covers WordPoints_CubePoints_Importer::import_ranks |
|
792 | + */ |
|
793 | + public function test_error_if_no_ranks_to_import() { |
|
794 | + |
|
795 | + wordpoints_register_points_ranks(); |
|
796 | + |
|
797 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
798 | + |
|
799 | + $this->importer->do_import( |
|
800 | + array( |
|
801 | + 'ranks' => array( |
|
802 | + 'ranks' => '1', |
|
803 | + '_data' => array( 'rank_group' => 'points_type-points' ), |
|
804 | + ), |
|
805 | + ) |
|
806 | + , $feedback |
|
807 | + ); |
|
808 | + |
|
809 | + $this->assertCount( 4, $feedback->messages['info'] ); |
|
810 | + $this->assertCount( 1, $feedback->messages['error'] ); |
|
811 | + |
|
812 | + } |
|
813 | + |
|
814 | + // |
|
815 | + // Helpers. |
|
816 | + // |
|
817 | + |
|
818 | + /** |
|
819 | + * Do the import for the points settings. |
|
820 | + * |
|
821 | + * @since 1.1.0 |
|
822 | + * |
|
823 | + * @param string $type The type of points import. |
|
824 | + */ |
|
825 | + protected function do_points_import( $type ) { |
|
826 | + |
|
827 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
828 | + |
|
829 | + $this->importer->do_import( |
|
830 | + array( |
|
831 | + 'points' => array( |
|
832 | + $type => '1', |
|
833 | + '_data' => array( 'points_type' => 'points' ), |
|
834 | + ), |
|
835 | + ) |
|
836 | + , $feedback |
|
837 | + ); |
|
838 | + |
|
839 | + $this->assertCount( 4, $feedback->messages['info'] ); |
|
840 | + $this->assertCount( 1, $feedback->messages['success'] ); |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Assert that a hook was imported. |
|
845 | + * |
|
846 | + * Actually just checks that the hook exists. |
|
847 | + * |
|
848 | + * @since 1.1.0 |
|
849 | + * @since 1.2.0 Now just accepts a single parameter, $settings. |
|
850 | + * |
|
851 | + * @param array $settings The expected reaction settings. |
|
852 | + */ |
|
853 | + protected function assertHookImported( $settings ) { |
|
854 | + |
|
855 | + $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
856 | + |
|
857 | + $reactions = $reaction_store->get_reactions_to_event( $settings['event'] ); |
|
858 | + |
|
859 | + $this->assertNotEmpty( $reactions ); |
|
860 | + |
|
861 | + foreach ( $reactions as $reaction ) { |
|
862 | + if ( $settings === $reaction->get_all_meta() ) { |
|
863 | + $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
864 | + return; |
|
865 | + } |
|
866 | + } |
|
867 | + |
|
868 | + $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
869 | + } |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | // EOF |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | // These are usually inactive by default. We activate them in the tests |
37 | 37 | // bootstrap so that they will be fully loaded, but deactivate them here to |
38 | 38 | // restore default behavior. |
39 | - cp_module_activation_set( 'post_author_points', false ); |
|
40 | - cp_module_activation_set( 'dailypoints', false ); |
|
39 | + cp_module_activation_set('post_author_points', false); |
|
40 | + cp_module_activation_set('dailypoints', false); |
|
41 | 41 | |
42 | - $this->importer = new WordPoints_CubePoints_Importer( 'Test CubePoints' ); |
|
42 | + $this->importer = new WordPoints_CubePoints_Importer('Test CubePoints'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function tearDown() { |
49 | 49 | |
50 | - WordPoints_Rank_Groups::deregister_group( 'points_type-points' ); |
|
51 | - WordPoints_Rank_Types::deregister_type( 'points-points' ); |
|
50 | + WordPoints_Rank_Groups::deregister_group('points_type-points'); |
|
51 | + WordPoints_Rank_Types::deregister_type('points-points'); |
|
52 | 52 | |
53 | 53 | parent::tearDown(); |
54 | 54 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function test_is_cubepoints_installed() { |
64 | 64 | |
65 | - $this->assertTrue( $this->importer->is_cubepoints_installed() ); |
|
65 | + $this->assertTrue($this->importer->is_cubepoints_installed()); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function test_is_cubepoints_not_installed() { |
76 | 76 | |
77 | - delete_option( 'cp_db_version' ); |
|
77 | + delete_option('cp_db_version'); |
|
78 | 78 | |
79 | - $this->assertFalse( $this->importer->is_cubepoints_installed() ); |
|
79 | + $this->assertFalse($this->importer->is_cubepoints_installed()); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function test_is_cubepoints_is_available() { |
90 | 90 | |
91 | - $this->assertTrue( $this->importer->is_available() ); |
|
91 | + $this->assertTrue($this->importer->is_available()); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function test_is_cubepoints_not_available() { |
102 | 102 | |
103 | - delete_option( 'cp_db_version' ); |
|
103 | + delete_option('cp_db_version'); |
|
104 | 104 | |
105 | - $this->assertWPError( $this->importer->is_available() ); |
|
105 | + $this->assertWPError($this->importer->is_available()); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | public function test_is_cubepoints_active() { |
116 | 116 | |
117 | 117 | $this->assertEquals( |
118 | - function_exists( 'cp_ready' ) |
|
118 | + function_exists('cp_ready') |
|
119 | 119 | , $this->importer->is_cubepoints_active() |
120 | 120 | ); |
121 | 121 | } |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function test_import_excluded_users() { |
131 | 131 | |
132 | - $user_ids = $this->factory->user->create_many( 3 ); |
|
132 | + $user_ids = $this->factory->user->create_many(3); |
|
133 | 133 | $user_logins = array(); |
134 | 134 | |
135 | - foreach ( $user_ids as $user_id ) { |
|
136 | - $user_logins[] = get_userdata( $user_id )->user_login; |
|
135 | + foreach ($user_ids as $user_id) { |
|
136 | + $user_logins[] = get_userdata($user_id)->user_login; |
|
137 | 137 | } |
138 | 138 | |
139 | - update_option( 'cp_topfilter', $user_logins ); |
|
139 | + update_option('cp_topfilter', $user_logins); |
|
140 | 140 | |
141 | - $this->do_points_import( 'excluded_users' ); |
|
141 | + $this->do_points_import('excluded_users'); |
|
142 | 142 | |
143 | 143 | $this->assertEquals( |
144 | 144 | $user_ids |
145 | - , wordpoints_get_excluded_users( 'tests' ) |
|
145 | + , wordpoints_get_excluded_users('tests') |
|
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function test_import_excluded_users_none() { |
157 | 157 | |
158 | - delete_option( 'cp_topfilter' ); |
|
158 | + delete_option('cp_topfilter'); |
|
159 | 159 | |
160 | 160 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
161 | 161 | |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | array( |
164 | 164 | 'points' => array( |
165 | 165 | 'excluded_users' => '1', |
166 | - '_data' => array( 'points_type' => 'points' ), |
|
166 | + '_data' => array('points_type' => 'points'), |
|
167 | 167 | ), |
168 | 168 | ) |
169 | 169 | , $feedback |
170 | 170 | ); |
171 | 171 | |
172 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
172 | + $this->assertCount(1, $feedback->messages['warning']); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function test_import_points_settings() { |
185 | 185 | |
186 | - update_option( 'cp_comment_points', 10 ); |
|
187 | - update_option( 'cp_post_points', 20 ); |
|
188 | - update_option( 'cp_reg_points', 50 ); |
|
186 | + update_option('cp_comment_points', 10); |
|
187 | + update_option('cp_post_points', 20); |
|
188 | + update_option('cp_reg_points', 50); |
|
189 | 189 | |
190 | - $this->do_points_import( 'settings' ); |
|
190 | + $this->do_points_import('settings'); |
|
191 | 191 | |
192 | 192 | $this->assertHookImported( |
193 | 193 | array( |
194 | 194 | 'event' => 'comment_leave\post', |
195 | - 'target' => array( 'comment\post', 'author', 'user' ), |
|
195 | + 'target' => array('comment\post', 'author', 'user'), |
|
196 | 196 | 'reactor' => 'points_legacy', |
197 | 197 | 'points' => 10, |
198 | 198 | 'points_type' => 'points', |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | 'description' => 'Commenting on a Post.', |
201 | 201 | 'legacy_log_type' => 'cubepoints-comment', |
202 | 202 | 'legacy_meta_key' => 'comment', |
203 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
203 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
204 | 204 | ) |
205 | 205 | ); |
206 | 206 | |
207 | 207 | $this->assertHookImported( |
208 | 208 | array( |
209 | 209 | 'event' => 'comment_leave\page', |
210 | - 'target' => array( 'comment\page', 'author', 'user' ), |
|
210 | + 'target' => array('comment\page', 'author', 'user'), |
|
211 | 211 | 'reactor' => 'points_legacy', |
212 | 212 | 'points' => 10, |
213 | 213 | 'points_type' => 'points', |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | 'description' => 'Commenting on a Page.', |
216 | 216 | 'legacy_log_type' => 'cubepoints-comment', |
217 | 217 | 'legacy_meta_key' => 'comment', |
218 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
218 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
219 | 219 | ) |
220 | 220 | ); |
221 | 221 | |
222 | 222 | $this->assertHookImported( |
223 | 223 | array( |
224 | 224 | 'event' => 'comment_leave\attachment', |
225 | - 'target' => array( 'comment\attachment', 'author', 'user' ), |
|
225 | + 'target' => array('comment\attachment', 'author', 'user'), |
|
226 | 226 | 'reactor' => 'points_legacy', |
227 | 227 | 'points' => 10, |
228 | 228 | 'points_type' => 'points', |
@@ -230,52 +230,52 @@ discard block |
||
230 | 230 | 'description' => 'Commenting on a Media.', |
231 | 231 | 'legacy_log_type' => 'cubepoints-comment', |
232 | 232 | 'legacy_meta_key' => 'comment', |
233 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
233 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
234 | 234 | ) |
235 | 235 | ); |
236 | 236 | |
237 | 237 | $this->assertHookImported( |
238 | 238 | array( |
239 | 239 | 'event' => 'post_publish\post', |
240 | - 'target' => array( 'post\post', 'author', 'user' ), |
|
240 | + 'target' => array('post\post', 'author', 'user'), |
|
241 | 241 | 'reactor' => 'points_legacy', |
242 | 242 | 'points' => 20, |
243 | 243 | 'points_type' => 'points', |
244 | 244 | 'log_text' => 'Published a Post.', |
245 | 245 | 'description' => 'Publishing a Post.', |
246 | - 'blocker' => array( 'toggle_off' => true ), |
|
246 | + 'blocker' => array('toggle_off' => true), |
|
247 | 247 | 'legacy_log_type' => 'cubepoints-post', |
248 | 248 | 'legacy_meta_key' => 'post', |
249 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
250 | - 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
249 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
250 | + 'points_legacy_repeat_blocker' => array('toggle_on' => true), |
|
251 | 251 | ) |
252 | 252 | ); |
253 | 253 | |
254 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
254 | + $reaction_store = wordpoints_hooks()->get_reaction_store('points'); |
|
255 | 255 | |
256 | 256 | $this->assertEmpty( |
257 | - $reaction_store->get_reactions_to_event( 'post_publish\page' ) |
|
257 | + $reaction_store->get_reactions_to_event('post_publish\page') |
|
258 | 258 | ); |
259 | 259 | |
260 | 260 | $this->assertEmpty( |
261 | - $reaction_store->get_reactions_to_event( 'post_publish\attachment' ) |
|
261 | + $reaction_store->get_reactions_to_event('post_publish\attachment') |
|
262 | 262 | ); |
263 | 263 | |
264 | 264 | $this->assertEmpty( |
265 | - $reaction_store->get_reactions_to_event( 'media_upload' ) |
|
265 | + $reaction_store->get_reactions_to_event('media_upload') |
|
266 | 266 | ); |
267 | 267 | |
268 | 268 | $this->assertHookImported( |
269 | 269 | array( |
270 | 270 | 'event' => 'user_register', |
271 | - 'target' => array( 'user' ), |
|
271 | + 'target' => array('user'), |
|
272 | 272 | 'reactor' => 'points_legacy', |
273 | 273 | 'points' => 50, |
274 | 274 | 'points_type' => 'points', |
275 | 275 | 'log_text' => 'Registration.', |
276 | 276 | 'description' => 'Registration.', |
277 | 277 | 'legacy_log_type' => 'cubepoints-register', |
278 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
278 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
279 | 279 | ) |
280 | 280 | ); |
281 | 281 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function test_imported_post_points_hook_does_not_refire() { |
291 | 291 | |
292 | - update_option( 'cp_post_points', 20 ); |
|
292 | + update_option('cp_post_points', 20); |
|
293 | 293 | |
294 | 294 | $user_id = $this->factory->user->create(); |
295 | 295 | $post_id = $this->factory->post->create( |
@@ -299,32 +299,32 @@ discard block |
||
299 | 299 | ) |
300 | 300 | ); |
301 | 301 | |
302 | - $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
302 | + $this->assertEquals(120, cp_getPoints($user_id)); |
|
303 | 303 | |
304 | 304 | $this->factory->post->update_object( |
305 | 305 | $post_id |
306 | - , array( 'post_status' => 'draft' ) |
|
306 | + , array('post_status' => 'draft') |
|
307 | 307 | ); |
308 | 308 | |
309 | - $this->assertEquals( 120, cp_getPoints( $user_id ) ); |
|
309 | + $this->assertEquals(120, cp_getPoints($user_id)); |
|
310 | 310 | |
311 | - $this->do_points_import( 'settings' ); |
|
312 | - $this->do_points_import( 'user_points' ); |
|
313 | - $this->do_points_import( 'logs' ); |
|
311 | + $this->do_points_import('settings'); |
|
312 | + $this->do_points_import('user_points'); |
|
313 | + $this->do_points_import('logs'); |
|
314 | 314 | |
315 | 315 | $this->assertEquals( |
316 | 316 | 120 |
317 | - , wordpoints_get_points( $user_id, 'points' ) |
|
317 | + , wordpoints_get_points($user_id, 'points') |
|
318 | 318 | ); |
319 | 319 | |
320 | 320 | $this->factory->post->update_object( |
321 | 321 | $post_id |
322 | - , array( 'post_status' => 'publish' ) |
|
322 | + , array('post_status' => 'publish') |
|
323 | 323 | ); |
324 | 324 | |
325 | 325 | $this->assertEquals( |
326 | 326 | 120 |
327 | - , wordpoints_get_points( $user_id, 'points' ) |
|
327 | + , wordpoints_get_points($user_id, 'points') |
|
328 | 328 | ); |
329 | 329 | } |
330 | 330 | |
@@ -338,16 +338,16 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public function test_import_post_author_points() { |
340 | 340 | |
341 | - cp_module_activation_set( 'post_author_points', 'active' ); |
|
341 | + cp_module_activation_set('post_author_points', 'active'); |
|
342 | 342 | |
343 | - update_option( 'cp_post_author_points', 15 ); |
|
343 | + update_option('cp_post_author_points', 15); |
|
344 | 344 | |
345 | - $this->do_points_import( 'settings' ); |
|
345 | + $this->do_points_import('settings'); |
|
346 | 346 | |
347 | 347 | $this->assertHookImported( |
348 | 348 | array( |
349 | 349 | 'event' => 'comment_leave\post', |
350 | - 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
350 | + 'target' => array('comment\post', 'post\post', 'post\post', 'author', 'user'), |
|
351 | 351 | 'reactor' => 'points_legacy', |
352 | 352 | 'points' => 15, |
353 | 353 | 'points_type' => 'points', |
@@ -355,14 +355,14 @@ discard block |
||
355 | 355 | 'description' => 'Receiving a comment on a Post.', |
356 | 356 | 'legacy_log_type' => 'cubepoints-post_author', |
357 | 357 | 'legacy_meta_key' => 'comment', |
358 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
358 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
359 | 359 | ) |
360 | 360 | ); |
361 | 361 | |
362 | 362 | $this->assertHookImported( |
363 | 363 | array( |
364 | 364 | 'event' => 'comment_leave\page', |
365 | - 'target' => array( 'comment\page', 'post\page', 'post\page', 'author', 'user' ), |
|
365 | + 'target' => array('comment\page', 'post\page', 'post\page', 'author', 'user'), |
|
366 | 366 | 'reactor' => 'points_legacy', |
367 | 367 | 'points' => 15, |
368 | 368 | 'points_type' => 'points', |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | 'description' => 'Receiving a comment on a Page.', |
371 | 371 | 'legacy_log_type' => 'cubepoints-post_author', |
372 | 372 | 'legacy_meta_key' => 'comment', |
373 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
373 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
374 | 374 | ) |
375 | 375 | ); |
376 | 376 | |
377 | 377 | $this->assertHookImported( |
378 | 378 | array( |
379 | 379 | 'event' => 'comment_leave\attachment', |
380 | - 'target' => array( 'comment\attachment', 'post\attachment', 'post\attachment', 'author', 'user' ), |
|
380 | + 'target' => array('comment\attachment', 'post\attachment', 'post\attachment', 'author', 'user'), |
|
381 | 381 | 'reactor' => 'points_legacy', |
382 | 382 | 'points' => 15, |
383 | 383 | 'points_type' => 'points', |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | 'description' => 'Receiving a comment on a Media.', |
386 | 386 | 'legacy_log_type' => 'cubepoints-post_author', |
387 | 387 | 'legacy_meta_key' => 'comment', |
388 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
388 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
389 | 389 | ) |
390 | 390 | ); |
391 | 391 | } |
@@ -400,17 +400,17 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function test_import_periodic_points() { |
402 | 402 | |
403 | - cp_module_activation_set( 'dailypoints', 'active' ); |
|
403 | + cp_module_activation_set('dailypoints', 'active'); |
|
404 | 404 | |
405 | - update_option( 'cp_module_dailypoints_points', 30 ); |
|
406 | - update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
405 | + update_option('cp_module_dailypoints_points', 30); |
|
406 | + update_option('cp_module_dailypoints_time', DAY_IN_SECONDS); |
|
407 | 407 | |
408 | - $this->do_points_import( 'settings' ); |
|
408 | + $this->do_points_import('settings'); |
|
409 | 409 | |
410 | 410 | $this->assertHookImported( |
411 | 411 | array( |
412 | 412 | 'event' => 'user_visit', |
413 | - 'target' => array( 'current:user' ), |
|
413 | + 'target' => array('current:user'), |
|
414 | 414 | 'reactor' => 'points_legacy', |
415 | 415 | 'points' => 30, |
416 | 416 | 'points_type' => 'points', |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | 'fire' => array( |
421 | 421 | array( |
422 | 422 | 'length' => DAY_IN_SECONDS, |
423 | - 'args' => array( array( 'current:user' ) ), |
|
423 | + 'args' => array(array('current:user')), |
|
424 | 424 | 'relative' => true, |
425 | 425 | ), |
426 | 426 | ), |
@@ -441,39 +441,39 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function test_import_periodic_points_respect_old_periods() { |
443 | 443 | |
444 | - if ( version_compare( $GLOBALS['wp_version'], '4.5', '>=' ) ) { |
|
445 | - $this->setExpectedDeprecated( 'get_currentuserinfo' ); |
|
444 | + if (version_compare($GLOBALS['wp_version'], '4.5', '>=')) { |
|
445 | + $this->setExpectedDeprecated('get_currentuserinfo'); |
|
446 | 446 | } |
447 | 447 | |
448 | - cp_module_activation_set( 'dailypoints', 'active' ); |
|
448 | + cp_module_activation_set('dailypoints', 'active'); |
|
449 | 449 | |
450 | - update_option( 'cp_module_dailypoints_points', 30 ); |
|
451 | - update_option( 'cp_module_dailypoints_time', DAY_IN_SECONDS ); |
|
450 | + update_option('cp_module_dailypoints_points', 30); |
|
451 | + update_option('cp_module_dailypoints_time', DAY_IN_SECONDS); |
|
452 | 452 | |
453 | 453 | $user_id = $this->factory->user->create(); |
454 | 454 | |
455 | - wp_set_current_user( $user_id ); |
|
455 | + wp_set_current_user($user_id); |
|
456 | 456 | |
457 | - $this->assertEquals( 100, cp_getPoints( $user_id ) ); |
|
457 | + $this->assertEquals(100, cp_getPoints($user_id)); |
|
458 | 458 | |
459 | 459 | cp_module_dailypoints_checkTimer(); |
460 | 460 | |
461 | - $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
461 | + $this->assertEquals(130, cp_getPoints($user_id)); |
|
462 | 462 | |
463 | 463 | // Running again shouldn't hit again. |
464 | 464 | cp_module_dailypoints_checkTimer(); |
465 | 465 | |
466 | - $this->assertEquals( 130, cp_getPoints( $user_id ) ); |
|
466 | + $this->assertEquals(130, cp_getPoints($user_id)); |
|
467 | 467 | |
468 | - $this->do_points_import( 'settings' ); |
|
469 | - $this->do_points_import( 'user_points' ); |
|
470 | - $this->do_points_import( 'logs' ); |
|
468 | + $this->do_points_import('settings'); |
|
469 | + $this->do_points_import('user_points'); |
|
470 | + $this->do_points_import('logs'); |
|
471 | 471 | |
472 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
472 | + $this->assertEquals(130, wordpoints_get_points($user_id, 'points')); |
|
473 | 473 | |
474 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
474 | + wordpoints_hooks()->get_sub_app('router')->{'wp,10'}(); |
|
475 | 475 | |
476 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
476 | + $this->assertEquals(130, wordpoints_get_points($user_id, 'points')); |
|
477 | 477 | |
478 | 478 | // Fast-forward and try again. |
479 | 479 | global $wpdb; |
@@ -490,40 +490,40 @@ discard block |
||
490 | 490 | // Don't go all the way yet. |
491 | 491 | $updated = $wpdb->update( |
492 | 492 | $wpdb->wordpoints_points_logs |
493 | - , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS + HOUR_IN_SECONDS ) ) |
|
494 | - , array( 'id' => $id ) |
|
495 | - , array( '%s' ) |
|
496 | - , array( '%d' ) |
|
493 | + , array('date' => date('Y-m-d H:i:s', current_time('timestamp', true) - DAY_IN_SECONDS + HOUR_IN_SECONDS)) |
|
494 | + , array('id' => $id) |
|
495 | + , array('%s') |
|
496 | + , array('%d') |
|
497 | 497 | ); |
498 | 498 | |
499 | - $this->assertEquals( 1, $updated ); |
|
499 | + $this->assertEquals(1, $updated); |
|
500 | 500 | |
501 | 501 | // The periods cache will still hold the old date. |
502 | 502 | $this->flush_cache(); |
503 | 503 | |
504 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
504 | + wordpoints_hooks()->get_sub_app('router')->{'wp,10'}(); |
|
505 | 505 | |
506 | 506 | // Points should have been awarded again yet. |
507 | - $this->assertEquals( 130, wordpoints_get_points( $user_id, 'points' ) ); |
|
507 | + $this->assertEquals(130, wordpoints_get_points($user_id, 'points')); |
|
508 | 508 | |
509 | 509 | // This time go all the way. |
510 | 510 | $updated = $wpdb->update( |
511 | 511 | $wpdb->wordpoints_points_logs |
512 | - , array( 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) - DAY_IN_SECONDS - 1 ) ) |
|
513 | - , array( 'id' => $id ) |
|
514 | - , array( '%s' ) |
|
515 | - , array( '%d' ) |
|
512 | + , array('date' => date('Y-m-d H:i:s', current_time('timestamp', true) - DAY_IN_SECONDS - 1)) |
|
513 | + , array('id' => $id) |
|
514 | + , array('%s') |
|
515 | + , array('%d') |
|
516 | 516 | ); |
517 | 517 | |
518 | - $this->assertEquals( 1, $updated ); |
|
518 | + $this->assertEquals(1, $updated); |
|
519 | 519 | |
520 | 520 | // The periods cache will still hold the old date. |
521 | 521 | $this->flush_cache(); |
522 | 522 | |
523 | - wordpoints_hooks()->get_sub_app( 'router' )->{'wp,10'}(); |
|
523 | + wordpoints_hooks()->get_sub_app('router')->{'wp,10'}(); |
|
524 | 524 | |
525 | 525 | // Points should have been awarded again. |
526 | - $this->assertEquals( 160, wordpoints_get_points( $user_id, 'points' ) ); |
|
526 | + $this->assertEquals(160, wordpoints_get_points($user_id, 'points')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | */ |
537 | 537 | public function test_import_periods_positive_gmt_offset() { |
538 | 538 | |
539 | - update_option( 'gmt_offset', 5 ); |
|
539 | + update_option('gmt_offset', 5); |
|
540 | 540 | |
541 | 541 | $this->test_import_periodic_points_respect_old_periods(); |
542 | 542 | } |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function test_import_periods_negative_gmt_offset() { |
553 | 553 | |
554 | - update_option( 'gmt_offset', -5 ); |
|
554 | + update_option('gmt_offset', -5); |
|
555 | 555 | |
556 | 556 | $this->test_import_periodic_points_respect_old_periods(); |
557 | 557 | } |
@@ -568,17 +568,17 @@ discard block |
||
568 | 568 | |
569 | 569 | $user_points = array(); |
570 | 570 | |
571 | - foreach ( array( 20, 10, 45 ) as $points ) { |
|
571 | + foreach (array(20, 10, 45) as $points) { |
|
572 | 572 | |
573 | 573 | $user_id = $this->factory->user->create(); |
574 | - cp_updatePoints( $user_id, $points ); |
|
575 | - $user_points[ $user_id ] = $points; |
|
574 | + cp_updatePoints($user_id, $points); |
|
575 | + $user_points[$user_id] = $points; |
|
576 | 576 | } |
577 | 577 | |
578 | - $this->do_points_import( 'user_points' ); |
|
578 | + $this->do_points_import('user_points'); |
|
579 | 579 | |
580 | - foreach ( $user_points as $user_id => $points ) { |
|
581 | - $this->assertEquals( $points, wordpoints_get_points( $user_id, 'points' ) ); |
|
580 | + foreach ($user_points as $user_id => $points) { |
|
581 | + $this->assertEquals($points, wordpoints_get_points($user_id, 'points')); |
|
582 | 582 | } |
583 | 583 | } |
584 | 584 | |
@@ -594,42 +594,42 @@ discard block |
||
594 | 594 | */ |
595 | 595 | public function test_import_points_logs() { |
596 | 596 | |
597 | - remove_action( 'publish_post', 'cp_newPost' ); |
|
597 | + remove_action('publish_post', 'cp_newPost'); |
|
598 | 598 | |
599 | 599 | $user_id = $this->factory->user->create(); |
600 | - cp_points( 'misc', $user_id, 10, 'Testing things.' ); |
|
600 | + cp_points('misc', $user_id, 10, 'Testing things.'); |
|
601 | 601 | |
602 | 602 | $user_id_2 = $this->factory->user->create(); |
603 | 603 | $post_id = $this->factory->post->create(); |
604 | - cp_points( 'post', $user_id_2, 25, $post_id ); |
|
604 | + cp_points('post', $user_id_2, 25, $post_id); |
|
605 | 605 | |
606 | - $this->do_points_import( 'logs' ); |
|
606 | + $this->do_points_import('logs'); |
|
607 | 607 | |
608 | - $query = new WordPoints_Points_Logs_Query( array( 'orderby' => 'id' ) ); |
|
608 | + $query = new WordPoints_Points_Logs_Query(array('orderby' => 'id')); |
|
609 | 609 | $logs = $query->get(); |
610 | 610 | |
611 | - $this->assertCount( 4, $logs ); |
|
611 | + $this->assertCount(4, $logs); |
|
612 | 612 | |
613 | 613 | $log = $logs[2]; |
614 | 614 | |
615 | - $this->assertEquals( $user_id, $log->user_id ); |
|
616 | - $this->assertEquals( 10, $log->points ); |
|
617 | - $this->assertEquals( 'Testing things.', $log->text ); |
|
618 | - $this->assertEquals( 'cubepoints-misc', $log->log_type ); |
|
619 | - $this->assertEquals( 'points', $log->points_type ); |
|
620 | - $this->assertEquals( 'misc', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
621 | - $this->assertEquals( 'Testing things.', wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
615 | + $this->assertEquals($user_id, $log->user_id); |
|
616 | + $this->assertEquals(10, $log->points); |
|
617 | + $this->assertEquals('Testing things.', $log->text); |
|
618 | + $this->assertEquals('cubepoints-misc', $log->log_type); |
|
619 | + $this->assertEquals('points', $log->points_type); |
|
620 | + $this->assertEquals('misc', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
621 | + $this->assertEquals('Testing things.', wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
622 | 622 | |
623 | 623 | $log = $logs[0]; |
624 | 624 | |
625 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
626 | - $this->assertEquals( 25, $log->points ); |
|
627 | - $this->assertStringMatchesFormat( 'Post on "<a href="%s">Post title %s</a>"', $log->text ); |
|
628 | - $this->assertEquals( 'cubepoints-post', $log->log_type ); |
|
629 | - $this->assertEquals( 'points', $log->points_type ); |
|
630 | - $this->assertEquals( 'post', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
631 | - $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
632 | - $this->assertEquals( $post_id, wordpoints_get_points_log_meta( $log->id, 'post', true ) ); |
|
625 | + $this->assertEquals($user_id_2, $log->user_id); |
|
626 | + $this->assertEquals(25, $log->points); |
|
627 | + $this->assertStringMatchesFormat('Post on "<a href="%s">Post title %s</a>"', $log->text); |
|
628 | + $this->assertEquals('cubepoints-post', $log->log_type); |
|
629 | + $this->assertEquals('points', $log->points_type); |
|
630 | + $this->assertEquals('post', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
631 | + $this->assertEquals($post_id, wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
632 | + $this->assertEquals($post_id, wordpoints_get_points_log_meta($log->id, 'post', true)); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | /** |
@@ -644,97 +644,97 @@ discard block |
||
644 | 644 | */ |
645 | 645 | public function test_import_points_logs_reversals() { |
646 | 646 | |
647 | - remove_action( 'publish_post', 'cp_newPost' ); |
|
648 | - remove_action( 'cp_comment_add', 'cp_module_post_author_points_comment_add' ); |
|
649 | - remove_action( 'cp_comment_remove', 'cp_module_post_author_points_comment_remove' ); |
|
647 | + remove_action('publish_post', 'cp_newPost'); |
|
648 | + remove_action('cp_comment_add', 'cp_module_post_author_points_comment_add'); |
|
649 | + remove_action('cp_comment_remove', 'cp_module_post_author_points_comment_remove'); |
|
650 | 650 | |
651 | - update_option( 'cp_comment_points', 10 ); |
|
652 | - update_option( 'cp_del_comment_points', 10 ); |
|
651 | + update_option('cp_comment_points', 10); |
|
652 | + update_option('cp_del_comment_points', 10); |
|
653 | 653 | |
654 | 654 | $user_id = $this->factory->user->create(); |
655 | 655 | $post_id = $this->factory->post->create(); |
656 | 656 | |
657 | 657 | $comment_id = $this->factory->comment->create( |
658 | - array( 'user_id' => $user_id, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
658 | + array('user_id' => $user_id, 'comment_post_ID' => $post_id, 'comment_approved' => 0) |
|
659 | 659 | ); |
660 | 660 | |
661 | 661 | wp_update_comment( |
662 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
662 | + array('comment_ID' => $comment_id, 'comment_approved' => 1) |
|
663 | 663 | ); |
664 | 664 | |
665 | 665 | $user_id_2 = $this->factory->user->create(); |
666 | 666 | $comment_id_2 = $this->factory->comment->create( |
667 | - array( 'user_id' => $user_id_2, 'comment_post_ID' => $post_id, 'comment_approved' => 0 ) |
|
667 | + array('user_id' => $user_id_2, 'comment_post_ID' => $post_id, 'comment_approved' => 0) |
|
668 | 668 | ); |
669 | 669 | |
670 | 670 | wp_update_comment( |
671 | - array( 'comment_ID' => $comment_id_2, 'comment_approved' => 1 ) |
|
671 | + array('comment_ID' => $comment_id_2, 'comment_approved' => 1) |
|
672 | 672 | ); |
673 | 673 | |
674 | 674 | // Now reverse the two transactions. |
675 | 675 | wp_update_comment( |
676 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
676 | + array('comment_ID' => $comment_id, 'comment_approved' => 0) |
|
677 | 677 | ); |
678 | 678 | |
679 | 679 | wp_update_comment( |
680 | - array( 'comment_ID' => $comment_id_2, 'comment_approved' => 0 ) |
|
680 | + array('comment_ID' => $comment_id_2, 'comment_approved' => 0) |
|
681 | 681 | ); |
682 | 682 | |
683 | - $this->do_points_import( 'logs' ); |
|
683 | + $this->do_points_import('logs'); |
|
684 | 684 | |
685 | 685 | $query = new WordPoints_Points_Logs_Query( |
686 | - array( 'orderby' => 'id', 'order' => 'ASC' ) |
|
686 | + array('orderby' => 'id', 'order' => 'ASC') |
|
687 | 687 | ); |
688 | 688 | |
689 | 689 | $logs = $query->get(); |
690 | 690 | |
691 | - $this->assertCount( 6, $logs ); |
|
691 | + $this->assertCount(6, $logs); |
|
692 | 692 | |
693 | 693 | // The first log will be for when the first user was created, so we skip it. |
694 | 694 | $log = $logs[1]; |
695 | 695 | |
696 | - $this->assertEquals( $user_id, $log->user_id ); |
|
697 | - $this->assertEquals( 10, $log->points ); |
|
698 | - $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
699 | - $this->assertEquals( 'points', $log->points_type ); |
|
700 | - $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
701 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
702 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
703 | - $this->assertEquals( $logs[4]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
696 | + $this->assertEquals($user_id, $log->user_id); |
|
697 | + $this->assertEquals(10, $log->points); |
|
698 | + $this->assertEquals('cubepoints-comment', $log->log_type); |
|
699 | + $this->assertEquals('points', $log->points_type); |
|
700 | + $this->assertEquals('comment', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
701 | + $this->assertEquals($comment_id, wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
702 | + $this->assertEquals($comment_id, wordpoints_get_points_log_meta($log->id, 'comment', true)); |
|
703 | + $this->assertEquals($logs[4]->id, wordpoints_get_points_log_meta($log->id, 'auto_reversed', true)); |
|
704 | 704 | |
705 | 705 | // The third log is for when the second user was created, so we skip it, too. |
706 | 706 | $log = $logs[3]; |
707 | 707 | |
708 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
709 | - $this->assertEquals( 10, $log->points ); |
|
710 | - $this->assertEquals( 'cubepoints-comment', $log->log_type ); |
|
711 | - $this->assertEquals( 'points', $log->points_type ); |
|
712 | - $this->assertEquals( 'comment', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
713 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
714 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
715 | - $this->assertEquals( $logs[5]->id, wordpoints_get_points_log_meta( $log->id, 'auto_reversed', true ) ); |
|
708 | + $this->assertEquals($user_id_2, $log->user_id); |
|
709 | + $this->assertEquals(10, $log->points); |
|
710 | + $this->assertEquals('cubepoints-comment', $log->log_type); |
|
711 | + $this->assertEquals('points', $log->points_type); |
|
712 | + $this->assertEquals('comment', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
713 | + $this->assertEquals($comment_id_2, wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
714 | + $this->assertEquals($comment_id_2, wordpoints_get_points_log_meta($log->id, 'comment', true)); |
|
715 | + $this->assertEquals($logs[5]->id, wordpoints_get_points_log_meta($log->id, 'auto_reversed', true)); |
|
716 | 716 | |
717 | 717 | $log = $logs[4]; |
718 | 718 | |
719 | - $this->assertEquals( $user_id, $log->user_id ); |
|
719 | + $this->assertEquals($user_id, $log->user_id); |
|
720 | 720 | $this->assertEquals( -10, $log->points ); |
721 | - $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
722 | - $this->assertEquals( 'points', $log->points_type ); |
|
723 | - $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
724 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
725 | - $this->assertEquals( $comment_id, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
726 | - $this->assertEquals( $logs[1]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
721 | + $this->assertEquals('cubepoints-comment_remove', $log->log_type); |
|
722 | + $this->assertEquals('points', $log->points_type); |
|
723 | + $this->assertEquals('comment_remove', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
724 | + $this->assertEquals($comment_id, wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
725 | + $this->assertEquals($comment_id, wordpoints_get_points_log_meta($log->id, 'comment', true)); |
|
726 | + $this->assertEquals($logs[1]->id, wordpoints_get_points_log_meta($log->id, 'original_log_id', true)); |
|
727 | 727 | |
728 | 728 | $log = $logs[5]; |
729 | 729 | |
730 | - $this->assertEquals( $user_id_2, $log->user_id ); |
|
730 | + $this->assertEquals($user_id_2, $log->user_id); |
|
731 | 731 | $this->assertEquals( -10, $log->points ); |
732 | - $this->assertEquals( 'cubepoints-comment_remove', $log->log_type ); |
|
733 | - $this->assertEquals( 'points', $log->points_type ); |
|
734 | - $this->assertEquals( 'comment_remove', wordpoints_get_points_log_meta( $log->id, 'cubepoints_type', true ) ); |
|
735 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'cubepoints_data', true ) ); |
|
736 | - $this->assertEquals( $comment_id_2, wordpoints_get_points_log_meta( $log->id, 'comment', true ) ); |
|
737 | - $this->assertEquals( $logs[3]->id, wordpoints_get_points_log_meta( $log->id, 'original_log_id', true ) ); |
|
732 | + $this->assertEquals('cubepoints-comment_remove', $log->log_type); |
|
733 | + $this->assertEquals('points', $log->points_type); |
|
734 | + $this->assertEquals('comment_remove', wordpoints_get_points_log_meta($log->id, 'cubepoints_type', true)); |
|
735 | + $this->assertEquals($comment_id_2, wordpoints_get_points_log_meta($log->id, 'cubepoints_data', true)); |
|
736 | + $this->assertEquals($comment_id_2, wordpoints_get_points_log_meta($log->id, 'comment', true)); |
|
737 | + $this->assertEquals($logs[3]->id, wordpoints_get_points_log_meta($log->id, 'original_log_id', true)); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | |
749 | 749 | update_option( |
750 | 750 | 'cp_module_ranks_data' |
751 | - , array( 0 => 'Newbie', 1000 => 'Biggie', 5000 => 'Oldie' ) |
|
751 | + , array(0 => 'Newbie', 1000 => 'Biggie', 5000 => 'Oldie') |
|
752 | 752 | ); |
753 | 753 | |
754 | 754 | wordpoints_register_points_ranks(); |
@@ -759,28 +759,28 @@ discard block |
||
759 | 759 | array( |
760 | 760 | 'ranks' => array( |
761 | 761 | 'ranks' => '1', |
762 | - '_data' => array( 'rank_group' => 'points_type-points' ), |
|
762 | + '_data' => array('rank_group' => 'points_type-points'), |
|
763 | 763 | ), |
764 | 764 | ) |
765 | 765 | , $feedback |
766 | 766 | ); |
767 | 767 | |
768 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
769 | - $this->assertCount( 1, $feedback->messages['success'] ); |
|
768 | + $this->assertCount(4, $feedback->messages['info']); |
|
769 | + $this->assertCount(1, $feedback->messages['success']); |
|
770 | 770 | |
771 | - $group = WordPoints_Rank_Groups::get_group( 'points_type-points' ); |
|
771 | + $group = WordPoints_Rank_Groups::get_group('points_type-points'); |
|
772 | 772 | |
773 | - $base_rank = wordpoints_get_rank( $group->get_rank( 0 ) ); |
|
774 | - $this->assertEquals( 'base', $base_rank->type ); |
|
775 | - $this->assertEquals( 'Newbie', $base_rank->name ); |
|
773 | + $base_rank = wordpoints_get_rank($group->get_rank(0)); |
|
774 | + $this->assertEquals('base', $base_rank->type); |
|
775 | + $this->assertEquals('Newbie', $base_rank->name); |
|
776 | 776 | |
777 | - $second_rank = wordpoints_get_rank( $group->get_rank( 1 ) ); |
|
778 | - $this->assertEquals( 1000, $second_rank->points ); |
|
779 | - $this->assertEquals( 'Biggie', $second_rank->name ); |
|
777 | + $second_rank = wordpoints_get_rank($group->get_rank(1)); |
|
778 | + $this->assertEquals(1000, $second_rank->points); |
|
779 | + $this->assertEquals('Biggie', $second_rank->name); |
|
780 | 780 | |
781 | - $third_rank = wordpoints_get_rank( $group->get_rank( 2 ) ); |
|
782 | - $this->assertEquals( 5000, $third_rank->points ); |
|
783 | - $this->assertEquals( 'Oldie', $third_rank->name ); |
|
781 | + $third_rank = wordpoints_get_rank($group->get_rank(2)); |
|
782 | + $this->assertEquals(5000, $third_rank->points); |
|
783 | + $this->assertEquals('Oldie', $third_rank->name); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
@@ -800,14 +800,14 @@ discard block |
||
800 | 800 | array( |
801 | 801 | 'ranks' => array( |
802 | 802 | 'ranks' => '1', |
803 | - '_data' => array( 'rank_group' => 'points_type-points' ), |
|
803 | + '_data' => array('rank_group' => 'points_type-points'), |
|
804 | 804 | ), |
805 | 805 | ) |
806 | 806 | , $feedback |
807 | 807 | ); |
808 | 808 | |
809 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
810 | - $this->assertCount( 1, $feedback->messages['error'] ); |
|
809 | + $this->assertCount(4, $feedback->messages['info']); |
|
810 | + $this->assertCount(1, $feedback->messages['error']); |
|
811 | 811 | |
812 | 812 | } |
813 | 813 | |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | * |
823 | 823 | * @param string $type The type of points import. |
824 | 824 | */ |
825 | - protected function do_points_import( $type ) { |
|
825 | + protected function do_points_import($type) { |
|
826 | 826 | |
827 | 827 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
828 | 828 | |
@@ -830,14 +830,14 @@ discard block |
||
830 | 830 | array( |
831 | 831 | 'points' => array( |
832 | 832 | $type => '1', |
833 | - '_data' => array( 'points_type' => 'points' ), |
|
833 | + '_data' => array('points_type' => 'points'), |
|
834 | 834 | ), |
835 | 835 | ) |
836 | 836 | , $feedback |
837 | 837 | ); |
838 | 838 | |
839 | - $this->assertCount( 4, $feedback->messages['info'] ); |
|
840 | - $this->assertCount( 1, $feedback->messages['success'] ); |
|
839 | + $this->assertCount(4, $feedback->messages['info']); |
|
840 | + $this->assertCount(1, $feedback->messages['success']); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -850,22 +850,22 @@ discard block |
||
850 | 850 | * |
851 | 851 | * @param array $settings The expected reaction settings. |
852 | 852 | */ |
853 | - protected function assertHookImported( $settings ) { |
|
853 | + protected function assertHookImported($settings) { |
|
854 | 854 | |
855 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
855 | + $reaction_store = wordpoints_hooks()->get_reaction_store('points'); |
|
856 | 856 | |
857 | - $reactions = $reaction_store->get_reactions_to_event( $settings['event'] ); |
|
857 | + $reactions = $reaction_store->get_reactions_to_event($settings['event']); |
|
858 | 858 | |
859 | - $this->assertNotEmpty( $reactions ); |
|
859 | + $this->assertNotEmpty($reactions); |
|
860 | 860 | |
861 | - foreach ( $reactions as $reaction ) { |
|
862 | - if ( $settings === $reaction->get_all_meta() ) { |
|
863 | - $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
861 | + foreach ($reactions as $reaction) { |
|
862 | + if ($settings === $reaction->get_all_meta()) { |
|
863 | + $this->assertEquals($settings, $reaction->get_all_meta()); |
|
864 | 864 | return; |
865 | 865 | } |
866 | 866 | } |
867 | 867 | |
868 | - $this->assertEquals( $settings, $reaction->get_all_meta() ); |
|
868 | + $this->assertEquals($settings, $reaction->get_all_meta()); |
|
869 | 869 | } |
870 | 870 | } |
871 | 871 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | * @since 1.0.0 |
14 | 14 | */ |
15 | 15 | class AcceptanceTester extends \WordPoints\Tests\Codeception\AcceptanceTester { |
16 | - // Add any methods here that you want. |
|
16 | + // Add any methods here that you want. |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | // EOF |