@@ -65,6 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @since 1.0.0 |
68 | + * @param string $name |
|
68 | 69 | */ |
69 | 70 | public function __construct( $name ) { |
70 | 71 | |
@@ -611,6 +612,11 @@ discard block |
||
611 | 612 | * Generate the log text when importing a points log. |
612 | 613 | * |
613 | 614 | * @since 1.0.0 |
615 | + * @param string $text |
|
616 | + * @param integer $user_id |
|
617 | + * @param integer $points |
|
618 | + * @param string $points_type |
|
619 | + * @param string $log_type |
|
614 | 620 | */ |
615 | 621 | public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) { |
616 | 622 |
@@ -14,700 +14,700 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPoints_CubePoints_Importer extends WordPoints_Importer { |
16 | 16 | |
17 | - /** |
|
18 | - * Reversible log types indexed by the reversing log type. |
|
19 | - * |
|
20 | - * This information is used to set the `auto_reversed` and `original_log_id` |
|
21 | - * points log metadata for the imported logs. |
|
22 | - * |
|
23 | - * @since 1.2.0 |
|
24 | - * |
|
25 | - * @see WordPoints_CubePoints_Importer::import_points_log() |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $reversible_log_types = array( |
|
30 | - 'comment_remove' => 'comment', |
|
31 | - 'post_comment_remove' => 'post_comment', |
|
32 | - ); |
|
33 | - |
|
34 | - /** |
|
35 | - * Primary entity slugs for each imported log type. |
|
36 | - * |
|
37 | - * These are points log meta keys under which to save the entity ID in the |
|
38 | - * CubePoints `data` log field. |
|
39 | - * |
|
40 | - * @since 1.2.0 |
|
41 | - * |
|
42 | - * @see WordPoints_CubePoints_Importer::import_points_log() |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $log_type_entities = array( |
|
47 | - 'comment' => 'comment', |
|
48 | - 'comment_remove' => 'comment', |
|
49 | - 'post' => 'post', |
|
50 | - 'post_comment' => 'comment', |
|
51 | - 'post_comment_remove' => 'comment', |
|
52 | - 'register' => 'user', |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * IDs of reversible logs, indexed by CubePoints log type and object ID. |
|
57 | - * |
|
58 | - * @since 1.2.0 |
|
59 | - * |
|
60 | - * @see WordPoints_CubePoints_Importer::import_points_log() |
|
61 | - * |
|
62 | - * @var int[][] |
|
63 | - */ |
|
64 | - protected $reversible_log_ids; |
|
65 | - |
|
66 | - /** |
|
67 | - * @since 1.0.0 |
|
68 | - */ |
|
69 | - public function __construct( $name ) { |
|
70 | - |
|
71 | - parent::__construct( $name ); |
|
72 | - |
|
73 | - $this->components = array( |
|
74 | - 'points' => array( |
|
75 | - 'excluded_users' => array( |
|
76 | - 'label' => __( 'Excluded users', 'wordpoints-importer' ), |
|
77 | - 'function' => array( $this, 'import_excluded_users' ), |
|
78 | - ), |
|
79 | - 'settings' => array( |
|
80 | - 'label' => __( 'Points Hooks', 'wordpoints-importer' ), |
|
81 | - 'description' => __( 'If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer' ), |
|
82 | - 'function' => array( $this, 'import_points_settings' ), |
|
83 | - ), |
|
84 | - 'user_points' => array( |
|
85 | - 'label' => __( 'User points', 'wordpoints-importer' ), |
|
86 | - 'function' => array( $this, 'import_user_points' ), |
|
87 | - ), |
|
88 | - 'logs' => array( |
|
89 | - 'label' => __( 'Points logs', 'wordpoints-importer' ), |
|
90 | - 'function' => array( $this, 'import_points_logs' ), |
|
91 | - 'can_import' => array( $this, 'can_import_points_logs' ), |
|
92 | - ), |
|
93 | - ), |
|
94 | - 'ranks' => array( |
|
95 | - 'ranks' => array( |
|
96 | - 'label' => __( 'Rank settings', 'wordpoints-importer' ), |
|
97 | - 'description' => __( 'If checked, the list of ranks is imported, and users will have the correct ranks assigned to them.', 'wordpoints-importer' ), |
|
98 | - 'function' => array( $this, 'import_ranks' ), |
|
99 | - ), |
|
100 | - ), |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @since 1.0.0 |
|
106 | - */ |
|
107 | - public function is_available() { |
|
108 | - |
|
109 | - if ( ! $this->is_cubepoints_installed() ) { |
|
110 | - return new WP_Error( |
|
111 | - 'cubepoints_not_installed' |
|
112 | - , __( 'CubePoints is not installed', 'wordpoints-importer' ) |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - return true; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Check if CubePoints is installed. |
|
121 | - * |
|
122 | - * @since 1.0.0 |
|
123 | - */ |
|
124 | - public function is_cubepoints_installed() { |
|
125 | - |
|
126 | - return (bool) get_option( 'cp_db_version' ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Check if CubePoints is active. |
|
131 | - * |
|
132 | - * @since 1.0.0 |
|
133 | - */ |
|
134 | - public function is_cubepoints_active() { |
|
135 | - |
|
136 | - return function_exists( 'cp_ready' ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Import the excluded users. |
|
141 | - * |
|
142 | - * @since 1.0.0 |
|
143 | - */ |
|
144 | - protected function import_excluded_users() { |
|
145 | - |
|
146 | - $this->feedback->info( __( 'Importing excluded users…', 'wordpoints-importer' ) ); |
|
147 | - |
|
148 | - $excluded_users = get_option( 'cp_topfilter' ); |
|
149 | - |
|
150 | - if ( ! is_array( $excluded_users ) ) { |
|
151 | - $this->feedback->warning( __( 'No excluded users found.', 'wordpoints-importer' ) ); |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $user_ids = array(); |
|
156 | - |
|
157 | - foreach ( $excluded_users as $user_login ) { |
|
158 | - |
|
159 | - $user = get_user_by( 'login', $user_login ); |
|
160 | - |
|
161 | - if ( $user instanceof WP_User ) { |
|
162 | - $user_ids[] = $user->ID; |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - $excluded_user_ids = wordpoints_get_maybe_network_array_option( |
|
167 | - 'wordpoints_excluded_users' |
|
168 | - ); |
|
169 | - |
|
170 | - $excluded_user_ids = array_unique( |
|
171 | - array_merge( $excluded_user_ids, $user_ids ) |
|
172 | - ); |
|
173 | - |
|
174 | - wordpoints_update_maybe_network_option( |
|
175 | - 'wordpoints_excluded_users' |
|
176 | - , $excluded_user_ids |
|
177 | - ); |
|
178 | - |
|
179 | - $this->feedback->success( |
|
180 | - sprintf( |
|
181 | - __( 'Imported %s excluded users.', 'wordpoints-importer' ) |
|
182 | - , count( $user_ids ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Import the points settings to the points hooks. |
|
189 | - * |
|
190 | - * @since 1.1.0 |
|
191 | - * |
|
192 | - * @param array $settings The settings for the points component import. |
|
193 | - */ |
|
194 | - protected function import_points_settings( $settings ) { |
|
195 | - |
|
196 | - $this->feedback->info( __( 'Importing points hooks…', 'wordpoints-importer' ) ); |
|
197 | - |
|
198 | - $options = array( |
|
199 | - 'cp_comment_points' => array( |
|
200 | - 'event' => 'comment_leave\post', |
|
201 | - 'target' => array( 'comment\post', 'author', 'user' ), |
|
202 | - /* translators: The post type name */ |
|
203 | - 'log_text' => __( 'Comment on a %s.', 'wordpoints-importer' ), |
|
204 | - /* translators: The post type name */ |
|
205 | - 'description' => __( 'Commenting on a %s.', 'wordpoints-importer' ), |
|
206 | - 'legacy_log_type' => 'cubepoints-comment', |
|
207 | - 'legacy_meta_key' => 'comment', |
|
208 | - ), |
|
209 | - 'cp_post_points' => array( |
|
210 | - 'event' => 'post_publish\post', |
|
211 | - 'target' => array( 'post\post', 'author', 'user' ), |
|
212 | - /* translators: The post type name */ |
|
213 | - 'log_text' => __( 'Published a Post.', 'wordpoints-importer' ), |
|
214 | - /* translators: The post type name */ |
|
215 | - 'description' => __( 'Publishing a Post.', 'wordpoints-importer' ), |
|
216 | - 'legacy_log_type' => 'cubepoints-post', |
|
217 | - 'legacy_meta_key' => 'post', |
|
218 | - // CubePoints doesn't remove points when a post is deleted. |
|
219 | - 'blocker' => array( 'toggle_off' => true ), |
|
220 | - 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
221 | - ), |
|
222 | - 'cp_reg_points' => array( |
|
223 | - 'event' => 'user_register', |
|
224 | - 'log_text' => __( 'Registration.', 'wordpoints-importer' ), |
|
225 | - 'description' => __( 'Registration.', 'wordpoints-importer' ), |
|
226 | - 'legacy_log_type' => 'cubepoints-register', |
|
227 | - ), |
|
228 | - 'cp_post_author_points' => array( |
|
229 | - 'event' => 'comment_leave\post', |
|
230 | - 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
231 | - /* translators: The post type name */ |
|
232 | - 'log_text' => __( 'Received a comment on a %s.', 'wordpoints-importer' ), |
|
233 | - /* translators: The post type name */ |
|
234 | - 'description' => __( 'Receiving a comment on a %s.', 'wordpoints-importer' ), |
|
235 | - 'legacy_log_type' => 'cubepoints-post_author', |
|
236 | - 'legacy_meta_key' => 'comment', |
|
237 | - ), |
|
238 | - ); |
|
239 | - |
|
240 | - // Don't import this module setting if the module isn't active. |
|
241 | - if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'post_author_points' ) ) { |
|
242 | - unset( $options['cp_post_author_points'] ); |
|
243 | - } |
|
244 | - |
|
245 | - $imported = 0; |
|
246 | - |
|
247 | - foreach ( $options as $option => $hook_settings ) { |
|
248 | - |
|
249 | - $points = get_option( $option ); |
|
250 | - |
|
251 | - if ( wordpoints_posint( $points ) ) { |
|
252 | - |
|
253 | - $hook_settings['points'] = $points; |
|
254 | - $hook_settings['points_type'] = $settings['points_type']; |
|
255 | - |
|
256 | - if ( |
|
257 | - // The CubePoints post points were only awarded for Posts. |
|
258 | - 'post_publish\post' !== $hook_settings['event'] |
|
259 | - && strpos( $hook_settings['event'], '\post' ) |
|
260 | - ) { |
|
261 | - |
|
262 | - $post_type_slugs = get_post_types( array( 'public' => true ) ); |
|
263 | - |
|
264 | - foreach ( $post_type_slugs as $post_type_slug ) { |
|
265 | - |
|
266 | - $added = $this->add_points_hook( |
|
267 | - $this->format_settings_for_post_type( |
|
268 | - $post_type_slug |
|
269 | - , $hook_settings |
|
270 | - ) |
|
271 | - ); |
|
272 | - |
|
273 | - if ( $added ) { |
|
274 | - $imported++; |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - } else { |
|
279 | - if ( $this->add_points_hook( $hook_settings ) ) { |
|
280 | - $imported++; |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - if ( $this->import_daily_points_hook( $settings ) ) { |
|
287 | - $imported++; |
|
288 | - } |
|
289 | - |
|
290 | - $this->feedback->success( |
|
291 | - sprintf( __( 'Imported %s points hooks.', 'wordpoints-importer' ), $imported ) |
|
292 | - ); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Import the settings for the Daily Points module to a points hook. |
|
297 | - * |
|
298 | - * @since 1.1.0 |
|
299 | - * |
|
300 | - * @param array $settings The settings for the points component import. |
|
301 | - * |
|
302 | - * @return bool True if the settings were imported, false otherwise. |
|
303 | - */ |
|
304 | - protected function import_daily_points_hook( $settings ) { |
|
305 | - |
|
306 | - // Don't import this module setting if the module isn't active. |
|
307 | - if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) { |
|
308 | - return false; |
|
309 | - } |
|
310 | - |
|
311 | - $points = get_option( 'cp_module_dailypoints_points' ); |
|
312 | - $period = get_option( 'cp_module_dailypoints_time' ); |
|
313 | - |
|
314 | - if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) { |
|
315 | - return false; |
|
316 | - } |
|
317 | - |
|
318 | - return $this->add_points_hook( |
|
319 | - array( |
|
320 | - 'event' => 'user_visit', |
|
321 | - 'target' => array( 'current:user' ), |
|
322 | - 'reactor' => 'points_legacy', |
|
323 | - 'points' => $points, |
|
324 | - 'points_type' => $settings['points_type'], |
|
325 | - 'points_legacy_periods' => array( |
|
326 | - 'fire' => array( |
|
327 | - array( |
|
328 | - 'length' => $period, |
|
329 | - 'args' => array( array( 'current:user' ) ), |
|
330 | - 'relative' => true, |
|
331 | - ), |
|
332 | - ), |
|
333 | - ), |
|
334 | - 'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
335 | - 'description' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
336 | - 'points_legacy_reversals' => array(), |
|
337 | - 'legacy_log_type' => 'cubepoints-dailypoints', |
|
338 | - ) |
|
339 | - ); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Programmatically create a new instance of a points hook. |
|
344 | - * |
|
345 | - * @since 1.0.0 |
|
346 | - * @since 1.2.0 Now just accepts a single argument, $settings. |
|
347 | - * |
|
348 | - * @param array $settings The settings for this hook. |
|
349 | - * |
|
350 | - * @return bool True if added successfully, or false on failure. |
|
351 | - */ |
|
352 | - private function add_points_hook( $settings = array() ) { |
|
353 | - |
|
354 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
355 | - |
|
356 | - $settings = array_merge( |
|
357 | - array( |
|
358 | - 'target' => array( 'user' ), |
|
359 | - 'reactor' => 'points_legacy', |
|
360 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
361 | - ) |
|
362 | - , $settings |
|
363 | - ); |
|
364 | - |
|
365 | - $reaction = $reaction_store->create_reaction( $settings ); |
|
366 | - |
|
367 | - if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) { |
|
368 | - return false; |
|
369 | - } |
|
370 | - |
|
371 | - return true; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Format the settings for a reaction for a particular post type. |
|
376 | - * |
|
377 | - * @since 1.2.0 |
|
378 | - * |
|
379 | - * @param string $post_type The slug of the post type to format the settings for. |
|
380 | - * @param array $settings The reaction settings. |
|
381 | - * |
|
382 | - * @return array The settings modified for this particular post type. |
|
383 | - */ |
|
384 | - protected function format_settings_for_post_type( $post_type, $settings ) { |
|
385 | - |
|
386 | - $settings['event'] = str_replace( |
|
387 | - '\post' |
|
388 | - , '\\' . $post_type |
|
389 | - , $settings['event'] |
|
390 | - ); |
|
391 | - |
|
392 | - $settings['target'] = str_replace( |
|
393 | - '\post' |
|
394 | - , '\\' . $post_type |
|
395 | - , $settings['target'] |
|
396 | - ); |
|
397 | - |
|
398 | - $labels = get_post_type_labels( get_post_type_object( $post_type ) ); |
|
399 | - |
|
400 | - $settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name ); |
|
401 | - $settings['description'] = sprintf( $settings['description'], $labels->singular_name ); |
|
402 | - |
|
403 | - return $settings; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Import the user points. |
|
408 | - * |
|
409 | - * @since 1.0.0 |
|
410 | - * |
|
411 | - * @param array $settings The settings for the points component import. |
|
412 | - */ |
|
413 | - protected function import_user_points( $settings ) { |
|
414 | - |
|
415 | - $this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) ); |
|
416 | - |
|
417 | - // We don't log the import transactions. |
|
418 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
419 | - |
|
420 | - $start = 0; |
|
421 | - |
|
422 | - // We do the import in batches. |
|
423 | - while ( $rows = $this->get_next_user_points_batch( $start ) ) { |
|
424 | - |
|
425 | - $start += count( $rows ); |
|
426 | - |
|
427 | - foreach ( $rows as $row ) { |
|
428 | - |
|
429 | - wordpoints_alter_points( |
|
430 | - $row->user_id |
|
431 | - , $row->points |
|
432 | - , $settings['points_type'] |
|
433 | - , 'cubepoints_import' // This is only for the hooks, it isn't being logged. |
|
434 | - ); |
|
435 | - } |
|
436 | - |
|
437 | - unset( $rows ); |
|
438 | - } |
|
439 | - |
|
440 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
441 | - |
|
442 | - $this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) ); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get a batch of user points to import. |
|
447 | - * |
|
448 | - * @since 1.0.0 |
|
449 | - * |
|
450 | - * @param int $start The offset number to begin counting at. |
|
451 | - * |
|
452 | - * @return object[]|false The rows, or false. |
|
453 | - */ |
|
454 | - protected function get_next_user_points_batch( $start ) { |
|
455 | - |
|
456 | - global $wpdb; |
|
457 | - |
|
458 | - $rows = $wpdb->get_results( |
|
459 | - $wpdb->prepare( |
|
460 | - " |
|
17 | + /** |
|
18 | + * Reversible log types indexed by the reversing log type. |
|
19 | + * |
|
20 | + * This information is used to set the `auto_reversed` and `original_log_id` |
|
21 | + * points log metadata for the imported logs. |
|
22 | + * |
|
23 | + * @since 1.2.0 |
|
24 | + * |
|
25 | + * @see WordPoints_CubePoints_Importer::import_points_log() |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $reversible_log_types = array( |
|
30 | + 'comment_remove' => 'comment', |
|
31 | + 'post_comment_remove' => 'post_comment', |
|
32 | + ); |
|
33 | + |
|
34 | + /** |
|
35 | + * Primary entity slugs for each imported log type. |
|
36 | + * |
|
37 | + * These are points log meta keys under which to save the entity ID in the |
|
38 | + * CubePoints `data` log field. |
|
39 | + * |
|
40 | + * @since 1.2.0 |
|
41 | + * |
|
42 | + * @see WordPoints_CubePoints_Importer::import_points_log() |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $log_type_entities = array( |
|
47 | + 'comment' => 'comment', |
|
48 | + 'comment_remove' => 'comment', |
|
49 | + 'post' => 'post', |
|
50 | + 'post_comment' => 'comment', |
|
51 | + 'post_comment_remove' => 'comment', |
|
52 | + 'register' => 'user', |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * IDs of reversible logs, indexed by CubePoints log type and object ID. |
|
57 | + * |
|
58 | + * @since 1.2.0 |
|
59 | + * |
|
60 | + * @see WordPoints_CubePoints_Importer::import_points_log() |
|
61 | + * |
|
62 | + * @var int[][] |
|
63 | + */ |
|
64 | + protected $reversible_log_ids; |
|
65 | + |
|
66 | + /** |
|
67 | + * @since 1.0.0 |
|
68 | + */ |
|
69 | + public function __construct( $name ) { |
|
70 | + |
|
71 | + parent::__construct( $name ); |
|
72 | + |
|
73 | + $this->components = array( |
|
74 | + 'points' => array( |
|
75 | + 'excluded_users' => array( |
|
76 | + 'label' => __( 'Excluded users', 'wordpoints-importer' ), |
|
77 | + 'function' => array( $this, 'import_excluded_users' ), |
|
78 | + ), |
|
79 | + 'settings' => array( |
|
80 | + 'label' => __( 'Points Hooks', 'wordpoints-importer' ), |
|
81 | + 'description' => __( 'If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer' ), |
|
82 | + 'function' => array( $this, 'import_points_settings' ), |
|
83 | + ), |
|
84 | + 'user_points' => array( |
|
85 | + 'label' => __( 'User points', 'wordpoints-importer' ), |
|
86 | + 'function' => array( $this, 'import_user_points' ), |
|
87 | + ), |
|
88 | + 'logs' => array( |
|
89 | + 'label' => __( 'Points logs', 'wordpoints-importer' ), |
|
90 | + 'function' => array( $this, 'import_points_logs' ), |
|
91 | + 'can_import' => array( $this, 'can_import_points_logs' ), |
|
92 | + ), |
|
93 | + ), |
|
94 | + 'ranks' => array( |
|
95 | + 'ranks' => array( |
|
96 | + 'label' => __( 'Rank settings', 'wordpoints-importer' ), |
|
97 | + 'description' => __( 'If checked, the list of ranks is imported, and users will have the correct ranks assigned to them.', 'wordpoints-importer' ), |
|
98 | + 'function' => array( $this, 'import_ranks' ), |
|
99 | + ), |
|
100 | + ), |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @since 1.0.0 |
|
106 | + */ |
|
107 | + public function is_available() { |
|
108 | + |
|
109 | + if ( ! $this->is_cubepoints_installed() ) { |
|
110 | + return new WP_Error( |
|
111 | + 'cubepoints_not_installed' |
|
112 | + , __( 'CubePoints is not installed', 'wordpoints-importer' ) |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + return true; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Check if CubePoints is installed. |
|
121 | + * |
|
122 | + * @since 1.0.0 |
|
123 | + */ |
|
124 | + public function is_cubepoints_installed() { |
|
125 | + |
|
126 | + return (bool) get_option( 'cp_db_version' ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Check if CubePoints is active. |
|
131 | + * |
|
132 | + * @since 1.0.0 |
|
133 | + */ |
|
134 | + public function is_cubepoints_active() { |
|
135 | + |
|
136 | + return function_exists( 'cp_ready' ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Import the excluded users. |
|
141 | + * |
|
142 | + * @since 1.0.0 |
|
143 | + */ |
|
144 | + protected function import_excluded_users() { |
|
145 | + |
|
146 | + $this->feedback->info( __( 'Importing excluded users…', 'wordpoints-importer' ) ); |
|
147 | + |
|
148 | + $excluded_users = get_option( 'cp_topfilter' ); |
|
149 | + |
|
150 | + if ( ! is_array( $excluded_users ) ) { |
|
151 | + $this->feedback->warning( __( 'No excluded users found.', 'wordpoints-importer' ) ); |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $user_ids = array(); |
|
156 | + |
|
157 | + foreach ( $excluded_users as $user_login ) { |
|
158 | + |
|
159 | + $user = get_user_by( 'login', $user_login ); |
|
160 | + |
|
161 | + if ( $user instanceof WP_User ) { |
|
162 | + $user_ids[] = $user->ID; |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + $excluded_user_ids = wordpoints_get_maybe_network_array_option( |
|
167 | + 'wordpoints_excluded_users' |
|
168 | + ); |
|
169 | + |
|
170 | + $excluded_user_ids = array_unique( |
|
171 | + array_merge( $excluded_user_ids, $user_ids ) |
|
172 | + ); |
|
173 | + |
|
174 | + wordpoints_update_maybe_network_option( |
|
175 | + 'wordpoints_excluded_users' |
|
176 | + , $excluded_user_ids |
|
177 | + ); |
|
178 | + |
|
179 | + $this->feedback->success( |
|
180 | + sprintf( |
|
181 | + __( 'Imported %s excluded users.', 'wordpoints-importer' ) |
|
182 | + , count( $user_ids ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Import the points settings to the points hooks. |
|
189 | + * |
|
190 | + * @since 1.1.0 |
|
191 | + * |
|
192 | + * @param array $settings The settings for the points component import. |
|
193 | + */ |
|
194 | + protected function import_points_settings( $settings ) { |
|
195 | + |
|
196 | + $this->feedback->info( __( 'Importing points hooks…', 'wordpoints-importer' ) ); |
|
197 | + |
|
198 | + $options = array( |
|
199 | + 'cp_comment_points' => array( |
|
200 | + 'event' => 'comment_leave\post', |
|
201 | + 'target' => array( 'comment\post', 'author', 'user' ), |
|
202 | + /* translators: The post type name */ |
|
203 | + 'log_text' => __( 'Comment on a %s.', 'wordpoints-importer' ), |
|
204 | + /* translators: The post type name */ |
|
205 | + 'description' => __( 'Commenting on a %s.', 'wordpoints-importer' ), |
|
206 | + 'legacy_log_type' => 'cubepoints-comment', |
|
207 | + 'legacy_meta_key' => 'comment', |
|
208 | + ), |
|
209 | + 'cp_post_points' => array( |
|
210 | + 'event' => 'post_publish\post', |
|
211 | + 'target' => array( 'post\post', 'author', 'user' ), |
|
212 | + /* translators: The post type name */ |
|
213 | + 'log_text' => __( 'Published a Post.', 'wordpoints-importer' ), |
|
214 | + /* translators: The post type name */ |
|
215 | + 'description' => __( 'Publishing a Post.', 'wordpoints-importer' ), |
|
216 | + 'legacy_log_type' => 'cubepoints-post', |
|
217 | + 'legacy_meta_key' => 'post', |
|
218 | + // CubePoints doesn't remove points when a post is deleted. |
|
219 | + 'blocker' => array( 'toggle_off' => true ), |
|
220 | + 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
221 | + ), |
|
222 | + 'cp_reg_points' => array( |
|
223 | + 'event' => 'user_register', |
|
224 | + 'log_text' => __( 'Registration.', 'wordpoints-importer' ), |
|
225 | + 'description' => __( 'Registration.', 'wordpoints-importer' ), |
|
226 | + 'legacy_log_type' => 'cubepoints-register', |
|
227 | + ), |
|
228 | + 'cp_post_author_points' => array( |
|
229 | + 'event' => 'comment_leave\post', |
|
230 | + 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
231 | + /* translators: The post type name */ |
|
232 | + 'log_text' => __( 'Received a comment on a %s.', 'wordpoints-importer' ), |
|
233 | + /* translators: The post type name */ |
|
234 | + 'description' => __( 'Receiving a comment on a %s.', 'wordpoints-importer' ), |
|
235 | + 'legacy_log_type' => 'cubepoints-post_author', |
|
236 | + 'legacy_meta_key' => 'comment', |
|
237 | + ), |
|
238 | + ); |
|
239 | + |
|
240 | + // Don't import this module setting if the module isn't active. |
|
241 | + if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'post_author_points' ) ) { |
|
242 | + unset( $options['cp_post_author_points'] ); |
|
243 | + } |
|
244 | + |
|
245 | + $imported = 0; |
|
246 | + |
|
247 | + foreach ( $options as $option => $hook_settings ) { |
|
248 | + |
|
249 | + $points = get_option( $option ); |
|
250 | + |
|
251 | + if ( wordpoints_posint( $points ) ) { |
|
252 | + |
|
253 | + $hook_settings['points'] = $points; |
|
254 | + $hook_settings['points_type'] = $settings['points_type']; |
|
255 | + |
|
256 | + if ( |
|
257 | + // The CubePoints post points were only awarded for Posts. |
|
258 | + 'post_publish\post' !== $hook_settings['event'] |
|
259 | + && strpos( $hook_settings['event'], '\post' ) |
|
260 | + ) { |
|
261 | + |
|
262 | + $post_type_slugs = get_post_types( array( 'public' => true ) ); |
|
263 | + |
|
264 | + foreach ( $post_type_slugs as $post_type_slug ) { |
|
265 | + |
|
266 | + $added = $this->add_points_hook( |
|
267 | + $this->format_settings_for_post_type( |
|
268 | + $post_type_slug |
|
269 | + , $hook_settings |
|
270 | + ) |
|
271 | + ); |
|
272 | + |
|
273 | + if ( $added ) { |
|
274 | + $imported++; |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + } else { |
|
279 | + if ( $this->add_points_hook( $hook_settings ) ) { |
|
280 | + $imported++; |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + if ( $this->import_daily_points_hook( $settings ) ) { |
|
287 | + $imported++; |
|
288 | + } |
|
289 | + |
|
290 | + $this->feedback->success( |
|
291 | + sprintf( __( 'Imported %s points hooks.', 'wordpoints-importer' ), $imported ) |
|
292 | + ); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Import the settings for the Daily Points module to a points hook. |
|
297 | + * |
|
298 | + * @since 1.1.0 |
|
299 | + * |
|
300 | + * @param array $settings The settings for the points component import. |
|
301 | + * |
|
302 | + * @return bool True if the settings were imported, false otherwise. |
|
303 | + */ |
|
304 | + protected function import_daily_points_hook( $settings ) { |
|
305 | + |
|
306 | + // Don't import this module setting if the module isn't active. |
|
307 | + if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) { |
|
308 | + return false; |
|
309 | + } |
|
310 | + |
|
311 | + $points = get_option( 'cp_module_dailypoints_points' ); |
|
312 | + $period = get_option( 'cp_module_dailypoints_time' ); |
|
313 | + |
|
314 | + if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) { |
|
315 | + return false; |
|
316 | + } |
|
317 | + |
|
318 | + return $this->add_points_hook( |
|
319 | + array( |
|
320 | + 'event' => 'user_visit', |
|
321 | + 'target' => array( 'current:user' ), |
|
322 | + 'reactor' => 'points_legacy', |
|
323 | + 'points' => $points, |
|
324 | + 'points_type' => $settings['points_type'], |
|
325 | + 'points_legacy_periods' => array( |
|
326 | + 'fire' => array( |
|
327 | + array( |
|
328 | + 'length' => $period, |
|
329 | + 'args' => array( array( 'current:user' ) ), |
|
330 | + 'relative' => true, |
|
331 | + ), |
|
332 | + ), |
|
333 | + ), |
|
334 | + 'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
335 | + 'description' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
336 | + 'points_legacy_reversals' => array(), |
|
337 | + 'legacy_log_type' => 'cubepoints-dailypoints', |
|
338 | + ) |
|
339 | + ); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Programmatically create a new instance of a points hook. |
|
344 | + * |
|
345 | + * @since 1.0.0 |
|
346 | + * @since 1.2.0 Now just accepts a single argument, $settings. |
|
347 | + * |
|
348 | + * @param array $settings The settings for this hook. |
|
349 | + * |
|
350 | + * @return bool True if added successfully, or false on failure. |
|
351 | + */ |
|
352 | + private function add_points_hook( $settings = array() ) { |
|
353 | + |
|
354 | + $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
355 | + |
|
356 | + $settings = array_merge( |
|
357 | + array( |
|
358 | + 'target' => array( 'user' ), |
|
359 | + 'reactor' => 'points_legacy', |
|
360 | + 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
361 | + ) |
|
362 | + , $settings |
|
363 | + ); |
|
364 | + |
|
365 | + $reaction = $reaction_store->create_reaction( $settings ); |
|
366 | + |
|
367 | + if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) { |
|
368 | + return false; |
|
369 | + } |
|
370 | + |
|
371 | + return true; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Format the settings for a reaction for a particular post type. |
|
376 | + * |
|
377 | + * @since 1.2.0 |
|
378 | + * |
|
379 | + * @param string $post_type The slug of the post type to format the settings for. |
|
380 | + * @param array $settings The reaction settings. |
|
381 | + * |
|
382 | + * @return array The settings modified for this particular post type. |
|
383 | + */ |
|
384 | + protected function format_settings_for_post_type( $post_type, $settings ) { |
|
385 | + |
|
386 | + $settings['event'] = str_replace( |
|
387 | + '\post' |
|
388 | + , '\\' . $post_type |
|
389 | + , $settings['event'] |
|
390 | + ); |
|
391 | + |
|
392 | + $settings['target'] = str_replace( |
|
393 | + '\post' |
|
394 | + , '\\' . $post_type |
|
395 | + , $settings['target'] |
|
396 | + ); |
|
397 | + |
|
398 | + $labels = get_post_type_labels( get_post_type_object( $post_type ) ); |
|
399 | + |
|
400 | + $settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name ); |
|
401 | + $settings['description'] = sprintf( $settings['description'], $labels->singular_name ); |
|
402 | + |
|
403 | + return $settings; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Import the user points. |
|
408 | + * |
|
409 | + * @since 1.0.0 |
|
410 | + * |
|
411 | + * @param array $settings The settings for the points component import. |
|
412 | + */ |
|
413 | + protected function import_user_points( $settings ) { |
|
414 | + |
|
415 | + $this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) ); |
|
416 | + |
|
417 | + // We don't log the import transactions. |
|
418 | + add_filter( 'wordpoints_points_log', '__return_false' ); |
|
419 | + |
|
420 | + $start = 0; |
|
421 | + |
|
422 | + // We do the import in batches. |
|
423 | + while ( $rows = $this->get_next_user_points_batch( $start ) ) { |
|
424 | + |
|
425 | + $start += count( $rows ); |
|
426 | + |
|
427 | + foreach ( $rows as $row ) { |
|
428 | + |
|
429 | + wordpoints_alter_points( |
|
430 | + $row->user_id |
|
431 | + , $row->points |
|
432 | + , $settings['points_type'] |
|
433 | + , 'cubepoints_import' // This is only for the hooks, it isn't being logged. |
|
434 | + ); |
|
435 | + } |
|
436 | + |
|
437 | + unset( $rows ); |
|
438 | + } |
|
439 | + |
|
440 | + remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
441 | + |
|
442 | + $this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) ); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get a batch of user points to import. |
|
447 | + * |
|
448 | + * @since 1.0.0 |
|
449 | + * |
|
450 | + * @param int $start The offset number to begin counting at. |
|
451 | + * |
|
452 | + * @return object[]|false The rows, or false. |
|
453 | + */ |
|
454 | + protected function get_next_user_points_batch( $start ) { |
|
455 | + |
|
456 | + global $wpdb; |
|
457 | + |
|
458 | + $rows = $wpdb->get_results( |
|
459 | + $wpdb->prepare( |
|
460 | + " |
|
461 | 461 | SELECT `user_id`, `meta_value` as points |
462 | 462 | FROM {$wpdb->usermeta} |
463 | 463 | WHERE `meta_key` = 'cpoints' |
464 | 464 | ORDER BY `umeta_id` |
465 | 465 | LIMIT %d,500 |
466 | 466 | " |
467 | - , $start |
|
468 | - ) |
|
469 | - ); // WPCS: cache OK. |
|
470 | - |
|
471 | - if ( ! is_array( $rows ) ) { |
|
472 | - return false; |
|
473 | - } |
|
474 | - |
|
475 | - return $rows; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Check if the points logs can be imported. |
|
480 | - * |
|
481 | - * @since 1.0.0 |
|
482 | - * |
|
483 | - * @return true|WP_Error True on success or a WP_Error on failure. |
|
484 | - */ |
|
485 | - public function can_import_points_logs() { |
|
486 | - |
|
487 | - if ( ! $this->is_cubepoints_active() ) { |
|
488 | - |
|
489 | - return new WP_Error( |
|
490 | - 'wordpoints_import_points_logs_cubepoints_inactive' |
|
491 | - , __( 'CubePoints must be active.', 'wordpoints-importer' ) |
|
492 | - ); |
|
493 | - } |
|
494 | - |
|
495 | - return true; |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * Import the points logs. |
|
500 | - * |
|
501 | - * @since 1.0.0 |
|
502 | - * |
|
503 | - * @param array $settings The import settings for the points component. |
|
504 | - */ |
|
505 | - protected function import_points_logs( $settings ) { |
|
506 | - |
|
507 | - $this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) ); |
|
508 | - |
|
509 | - $start = 0; |
|
510 | - |
|
511 | - while ( $logs = $this->get_next_points_logs_batch( $start ) ) { |
|
512 | - |
|
513 | - $start += count( $logs ); |
|
514 | - |
|
515 | - foreach ( $logs as $log ) { |
|
516 | - |
|
517 | - $this->import_points_log( |
|
518 | - $log->uid |
|
519 | - , $log->points |
|
520 | - , $settings['points_type'] |
|
521 | - , "cubepoints-{$log->type}" |
|
522 | - , array( |
|
523 | - 'cubepoints_type' => $log->type, |
|
524 | - 'cubepoints_data' => $log->data, |
|
525 | - ) |
|
526 | - , date( 'Y-m-d H:i:s', $log->timestamp ) |
|
527 | - ); |
|
528 | - } |
|
529 | - |
|
530 | - unset( $logs ); |
|
531 | - } |
|
532 | - |
|
533 | - $this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) ); |
|
534 | - } |
|
535 | - |
|
536 | - /** |
|
537 | - * Import a points log. |
|
538 | - * |
|
539 | - * @since 1.0.0 |
|
540 | - * |
|
541 | - * @param int $user_id The ID of the user the log is for. |
|
542 | - * @param int $points The number of points awarded. |
|
543 | - * @param string $points_type The points type. |
|
544 | - * @param string $log_type The log type. |
|
545 | - * @param array $meta The metadata for this log. |
|
546 | - * @param int $date The date the transaction took place. |
|
547 | - */ |
|
548 | - protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) { |
|
549 | - |
|
550 | - global $wpdb; |
|
551 | - |
|
552 | - $result = $wpdb->insert( |
|
553 | - $wpdb->wordpoints_points_logs, |
|
554 | - array( |
|
555 | - 'user_id' => $user_id, |
|
556 | - 'points' => $points, |
|
557 | - 'points_type' => $points_type, |
|
558 | - 'log_type' => $log_type, |
|
559 | - 'text' => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ), |
|
560 | - 'date' => $date, |
|
561 | - 'site_id' => $wpdb->siteid, |
|
562 | - 'blog_id' => $wpdb->blogid, |
|
563 | - ), |
|
564 | - array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' ) |
|
565 | - ); |
|
566 | - |
|
567 | - if ( false !== $result ) { |
|
568 | - |
|
569 | - $log_id = (int) $wpdb->insert_id; |
|
570 | - |
|
571 | - // Set auto_reversed and original_log_id metadata for reversed logs. |
|
572 | - foreach ( $this->reversible_log_types as $reverse_type => $type ) { |
|
573 | - |
|
574 | - if ( $meta['cubepoints_type'] === $type ) { |
|
575 | - |
|
576 | - // Save this log ID for later, in case this log was reversed. |
|
577 | - // cubepoints_data will contain the entity ID. |
|
578 | - $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id; |
|
579 | - |
|
580 | - } elseif ( |
|
581 | - $meta['cubepoints_type'] === $reverse_type |
|
582 | - && isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ) |
|
583 | - ) { |
|
584 | - |
|
585 | - // This log was reverses another one. Set the original log ID. |
|
586 | - $meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ]; |
|
587 | - |
|
588 | - // And mark the original as auto_reversed. |
|
589 | - wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id ); |
|
590 | - |
|
591 | - // No need to keep this info anymore. |
|
592 | - unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ); |
|
593 | - } |
|
594 | - } |
|
595 | - |
|
596 | - // Set the entity IDs to their own meta keys, for the sake of reversals. |
|
597 | - if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) { |
|
598 | - $meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data']; |
|
599 | - } |
|
600 | - |
|
601 | - foreach ( $meta as $meta_key => $meta_value ) { |
|
602 | - |
|
603 | - wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value ); |
|
604 | - } |
|
605 | - |
|
606 | - do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id ); |
|
607 | - } |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Generate the log text when importing a points log. |
|
612 | - * |
|
613 | - * @since 1.0.0 |
|
614 | - */ |
|
615 | - public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) { |
|
616 | - |
|
617 | - ob_start(); |
|
618 | - do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] ); |
|
619 | - return ob_get_clean(); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Get the next 500 points logs from CubePoints. |
|
624 | - * |
|
625 | - * @since 1.0.0 |
|
626 | - * |
|
627 | - * @param int $start The offset number to begin counting the 500 at. |
|
628 | - * |
|
629 | - * @return object[]|false The rows from the database. |
|
630 | - */ |
|
631 | - protected function get_next_points_logs_batch( $start ) { |
|
632 | - |
|
633 | - global $wpdb; |
|
634 | - |
|
635 | - $logs = $wpdb->get_results( |
|
636 | - $wpdb->prepare( |
|
637 | - ' |
|
467 | + , $start |
|
468 | + ) |
|
469 | + ); // WPCS: cache OK. |
|
470 | + |
|
471 | + if ( ! is_array( $rows ) ) { |
|
472 | + return false; |
|
473 | + } |
|
474 | + |
|
475 | + return $rows; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Check if the points logs can be imported. |
|
480 | + * |
|
481 | + * @since 1.0.0 |
|
482 | + * |
|
483 | + * @return true|WP_Error True on success or a WP_Error on failure. |
|
484 | + */ |
|
485 | + public function can_import_points_logs() { |
|
486 | + |
|
487 | + if ( ! $this->is_cubepoints_active() ) { |
|
488 | + |
|
489 | + return new WP_Error( |
|
490 | + 'wordpoints_import_points_logs_cubepoints_inactive' |
|
491 | + , __( 'CubePoints must be active.', 'wordpoints-importer' ) |
|
492 | + ); |
|
493 | + } |
|
494 | + |
|
495 | + return true; |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * Import the points logs. |
|
500 | + * |
|
501 | + * @since 1.0.0 |
|
502 | + * |
|
503 | + * @param array $settings The import settings for the points component. |
|
504 | + */ |
|
505 | + protected function import_points_logs( $settings ) { |
|
506 | + |
|
507 | + $this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) ); |
|
508 | + |
|
509 | + $start = 0; |
|
510 | + |
|
511 | + while ( $logs = $this->get_next_points_logs_batch( $start ) ) { |
|
512 | + |
|
513 | + $start += count( $logs ); |
|
514 | + |
|
515 | + foreach ( $logs as $log ) { |
|
516 | + |
|
517 | + $this->import_points_log( |
|
518 | + $log->uid |
|
519 | + , $log->points |
|
520 | + , $settings['points_type'] |
|
521 | + , "cubepoints-{$log->type}" |
|
522 | + , array( |
|
523 | + 'cubepoints_type' => $log->type, |
|
524 | + 'cubepoints_data' => $log->data, |
|
525 | + ) |
|
526 | + , date( 'Y-m-d H:i:s', $log->timestamp ) |
|
527 | + ); |
|
528 | + } |
|
529 | + |
|
530 | + unset( $logs ); |
|
531 | + } |
|
532 | + |
|
533 | + $this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) ); |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Import a points log. |
|
538 | + * |
|
539 | + * @since 1.0.0 |
|
540 | + * |
|
541 | + * @param int $user_id The ID of the user the log is for. |
|
542 | + * @param int $points The number of points awarded. |
|
543 | + * @param string $points_type The points type. |
|
544 | + * @param string $log_type The log type. |
|
545 | + * @param array $meta The metadata for this log. |
|
546 | + * @param int $date The date the transaction took place. |
|
547 | + */ |
|
548 | + protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) { |
|
549 | + |
|
550 | + global $wpdb; |
|
551 | + |
|
552 | + $result = $wpdb->insert( |
|
553 | + $wpdb->wordpoints_points_logs, |
|
554 | + array( |
|
555 | + 'user_id' => $user_id, |
|
556 | + 'points' => $points, |
|
557 | + 'points_type' => $points_type, |
|
558 | + 'log_type' => $log_type, |
|
559 | + 'text' => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ), |
|
560 | + 'date' => $date, |
|
561 | + 'site_id' => $wpdb->siteid, |
|
562 | + 'blog_id' => $wpdb->blogid, |
|
563 | + ), |
|
564 | + array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' ) |
|
565 | + ); |
|
566 | + |
|
567 | + if ( false !== $result ) { |
|
568 | + |
|
569 | + $log_id = (int) $wpdb->insert_id; |
|
570 | + |
|
571 | + // Set auto_reversed and original_log_id metadata for reversed logs. |
|
572 | + foreach ( $this->reversible_log_types as $reverse_type => $type ) { |
|
573 | + |
|
574 | + if ( $meta['cubepoints_type'] === $type ) { |
|
575 | + |
|
576 | + // Save this log ID for later, in case this log was reversed. |
|
577 | + // cubepoints_data will contain the entity ID. |
|
578 | + $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id; |
|
579 | + |
|
580 | + } elseif ( |
|
581 | + $meta['cubepoints_type'] === $reverse_type |
|
582 | + && isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ) |
|
583 | + ) { |
|
584 | + |
|
585 | + // This log was reverses another one. Set the original log ID. |
|
586 | + $meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ]; |
|
587 | + |
|
588 | + // And mark the original as auto_reversed. |
|
589 | + wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id ); |
|
590 | + |
|
591 | + // No need to keep this info anymore. |
|
592 | + unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ); |
|
593 | + } |
|
594 | + } |
|
595 | + |
|
596 | + // Set the entity IDs to their own meta keys, for the sake of reversals. |
|
597 | + if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) { |
|
598 | + $meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data']; |
|
599 | + } |
|
600 | + |
|
601 | + foreach ( $meta as $meta_key => $meta_value ) { |
|
602 | + |
|
603 | + wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value ); |
|
604 | + } |
|
605 | + |
|
606 | + do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id ); |
|
607 | + } |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * Generate the log text when importing a points log. |
|
612 | + * |
|
613 | + * @since 1.0.0 |
|
614 | + */ |
|
615 | + public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) { |
|
616 | + |
|
617 | + ob_start(); |
|
618 | + do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] ); |
|
619 | + return ob_get_clean(); |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Get the next 500 points logs from CubePoints. |
|
624 | + * |
|
625 | + * @since 1.0.0 |
|
626 | + * |
|
627 | + * @param int $start The offset number to begin counting the 500 at. |
|
628 | + * |
|
629 | + * @return object[]|false The rows from the database. |
|
630 | + */ |
|
631 | + protected function get_next_points_logs_batch( $start ) { |
|
632 | + |
|
633 | + global $wpdb; |
|
634 | + |
|
635 | + $logs = $wpdb->get_results( |
|
636 | + $wpdb->prepare( |
|
637 | + ' |
|
638 | 638 | SELECT * |
639 | 639 | FROM `' . CP_DB . '` |
640 | 640 | ORDER BY `id` |
641 | 641 | LIMIT %d,500 |
642 | 642 | ' |
643 | - , $start |
|
644 | - ) |
|
645 | - ); // WPCS: cache OK. |
|
643 | + , $start |
|
644 | + ) |
|
645 | + ); // WPCS: cache OK. |
|
646 | 646 | |
647 | - if ( ! is_array( $logs ) ) { |
|
648 | - $this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) ); |
|
649 | - return false; |
|
650 | - } |
|
647 | + if ( ! is_array( $logs ) ) { |
|
648 | + $this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) ); |
|
649 | + return false; |
|
650 | + } |
|
651 | 651 | |
652 | - return $logs; |
|
653 | - } |
|
652 | + return $logs; |
|
653 | + } |
|
654 | 654 | |
655 | - /** |
|
656 | - * Import ranks. |
|
657 | - * |
|
658 | - * @since 1.1.0 |
|
659 | - * |
|
660 | - * @param array $settings The import settings for the ranks component. |
|
661 | - */ |
|
662 | - public function import_ranks( $settings ) { |
|
655 | + /** |
|
656 | + * Import ranks. |
|
657 | + * |
|
658 | + * @since 1.1.0 |
|
659 | + * |
|
660 | + * @param array $settings The import settings for the ranks component. |
|
661 | + */ |
|
662 | + public function import_ranks( $settings ) { |
|
663 | 663 | |
664 | - $this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) ); |
|
664 | + $this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) ); |
|
665 | 665 | |
666 | - $ranks_data = get_option( 'cp_module_ranks_data' ); |
|
666 | + $ranks_data = get_option( 'cp_module_ranks_data' ); |
|
667 | 667 | |
668 | - if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) { |
|
669 | - $this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) ); |
|
670 | - return; |
|
671 | - } |
|
668 | + if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) { |
|
669 | + $this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) ); |
|
670 | + return; |
|
671 | + } |
|
672 | 672 | |
673 | - $i = 0; |
|
673 | + $i = 0; |
|
674 | 674 | |
675 | - // The base rank already exists, so we just update it. |
|
676 | - if ( isset( $ranks_data[0] ) ) { |
|
675 | + // The base rank already exists, so we just update it. |
|
676 | + if ( isset( $ranks_data[0] ) ) { |
|
677 | 677 | |
678 | - wordpoints_update_rank( |
|
679 | - WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 ) |
|
680 | - , $ranks_data[0] |
|
681 | - , 'base' |
|
682 | - , $settings['rank_group'] |
|
683 | - , 0 |
|
684 | - ); |
|
678 | + wordpoints_update_rank( |
|
679 | + WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 ) |
|
680 | + , $ranks_data[0] |
|
681 | + , 'base' |
|
682 | + , $settings['rank_group'] |
|
683 | + , 0 |
|
684 | + ); |
|
685 | 685 | |
686 | - $i++; |
|
686 | + $i++; |
|
687 | 687 | |
688 | - unset( $ranks_data[0] ); |
|
689 | - } |
|
688 | + unset( $ranks_data[0] ); |
|
689 | + } |
|
690 | 690 | |
691 | - $points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) ); |
|
692 | - $rank_type = 'points-' . $points_type; |
|
691 | + $points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) ); |
|
692 | + $rank_type = 'points-' . $points_type; |
|
693 | 693 | |
694 | - ksort( $ranks_data ); |
|
694 | + ksort( $ranks_data ); |
|
695 | 695 | |
696 | - foreach ( $ranks_data as $points => $rank_name ) { |
|
696 | + foreach ( $ranks_data as $points => $rank_name ) { |
|
697 | 697 | |
698 | - wordpoints_add_rank( |
|
699 | - $rank_name |
|
700 | - , $rank_type |
|
701 | - , $settings['rank_group'] |
|
702 | - , $i |
|
703 | - , array( 'points' => $points, 'points_type' => $points_type ) |
|
704 | - ); |
|
698 | + wordpoints_add_rank( |
|
699 | + $rank_name |
|
700 | + , $rank_type |
|
701 | + , $settings['rank_group'] |
|
702 | + , $i |
|
703 | + , array( 'points' => $points, 'points_type' => $points_type ) |
|
704 | + ); |
|
705 | 705 | |
706 | - $i++; |
|
707 | - } |
|
706 | + $i++; |
|
707 | + } |
|
708 | 708 | |
709 | - $this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) ); |
|
710 | - } |
|
709 | + $this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) ); |
|
710 | + } |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | // EOF |
@@ -66,36 +66,36 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * @since 1.0.0 |
68 | 68 | */ |
69 | - public function __construct( $name ) { |
|
69 | + public function __construct($name) { |
|
70 | 70 | |
71 | - parent::__construct( $name ); |
|
71 | + parent::__construct($name); |
|
72 | 72 | |
73 | 73 | $this->components = array( |
74 | 74 | 'points' => array( |
75 | 75 | 'excluded_users' => array( |
76 | - 'label' => __( 'Excluded users', 'wordpoints-importer' ), |
|
77 | - 'function' => array( $this, 'import_excluded_users' ), |
|
76 | + 'label' => __('Excluded users', 'wordpoints-importer'), |
|
77 | + 'function' => array($this, 'import_excluded_users'), |
|
78 | 78 | ), |
79 | 79 | 'settings' => array( |
80 | - 'label' => __( 'Points Hooks', 'wordpoints-importer' ), |
|
81 | - 'description' => __( 'If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer' ), |
|
82 | - 'function' => array( $this, 'import_points_settings' ), |
|
80 | + 'label' => __('Points Hooks', 'wordpoints-importer'), |
|
81 | + 'description' => __('If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer'), |
|
82 | + 'function' => array($this, 'import_points_settings'), |
|
83 | 83 | ), |
84 | 84 | 'user_points' => array( |
85 | - 'label' => __( 'User points', 'wordpoints-importer' ), |
|
86 | - 'function' => array( $this, 'import_user_points' ), |
|
85 | + 'label' => __('User points', 'wordpoints-importer'), |
|
86 | + 'function' => array($this, 'import_user_points'), |
|
87 | 87 | ), |
88 | 88 | 'logs' => array( |
89 | - 'label' => __( 'Points logs', 'wordpoints-importer' ), |
|
90 | - 'function' => array( $this, 'import_points_logs' ), |
|
91 | - 'can_import' => array( $this, 'can_import_points_logs' ), |
|
89 | + 'label' => __('Points logs', 'wordpoints-importer'), |
|
90 | + 'function' => array($this, 'import_points_logs'), |
|
91 | + 'can_import' => array($this, 'can_import_points_logs'), |
|
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | 'ranks' => array( |
95 | 95 | 'ranks' => array( |
96 | - 'label' => __( 'Rank settings', 'wordpoints-importer' ), |
|
97 | - 'description' => __( 'If checked, the list of ranks is imported, and users will have the correct ranks assigned to them.', 'wordpoints-importer' ), |
|
98 | - 'function' => array( $this, 'import_ranks' ), |
|
96 | + 'label' => __('Rank settings', 'wordpoints-importer'), |
|
97 | + 'description' => __('If checked, the list of ranks is imported, and users will have the correct ranks assigned to them.', 'wordpoints-importer'), |
|
98 | + 'function' => array($this, 'import_ranks'), |
|
99 | 99 | ), |
100 | 100 | ), |
101 | 101 | ); |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function is_available() { |
108 | 108 | |
109 | - if ( ! $this->is_cubepoints_installed() ) { |
|
109 | + if (!$this->is_cubepoints_installed()) { |
|
110 | 110 | return new WP_Error( |
111 | 111 | 'cubepoints_not_installed' |
112 | - , __( 'CubePoints is not installed', 'wordpoints-importer' ) |
|
112 | + , __('CubePoints is not installed', 'wordpoints-importer') |
|
113 | 113 | ); |
114 | 114 | } |
115 | 115 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function is_cubepoints_installed() { |
125 | 125 | |
126 | - return (bool) get_option( 'cp_db_version' ); |
|
126 | + return (bool) get_option('cp_db_version'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function is_cubepoints_active() { |
135 | 135 | |
136 | - return function_exists( 'cp_ready' ); |
|
136 | + return function_exists('cp_ready'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -143,22 +143,22 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function import_excluded_users() { |
145 | 145 | |
146 | - $this->feedback->info( __( 'Importing excluded users…', 'wordpoints-importer' ) ); |
|
146 | + $this->feedback->info(__('Importing excluded users…', 'wordpoints-importer')); |
|
147 | 147 | |
148 | - $excluded_users = get_option( 'cp_topfilter' ); |
|
148 | + $excluded_users = get_option('cp_topfilter'); |
|
149 | 149 | |
150 | - if ( ! is_array( $excluded_users ) ) { |
|
151 | - $this->feedback->warning( __( 'No excluded users found.', 'wordpoints-importer' ) ); |
|
150 | + if (!is_array($excluded_users)) { |
|
151 | + $this->feedback->warning(__('No excluded users found.', 'wordpoints-importer')); |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $user_ids = array(); |
156 | 156 | |
157 | - foreach ( $excluded_users as $user_login ) { |
|
157 | + foreach ($excluded_users as $user_login) { |
|
158 | 158 | |
159 | - $user = get_user_by( 'login', $user_login ); |
|
159 | + $user = get_user_by('login', $user_login); |
|
160 | 160 | |
161 | - if ( $user instanceof WP_User ) { |
|
161 | + if ($user instanceof WP_User) { |
|
162 | 162 | $user_ids[] = $user->ID; |
163 | 163 | } |
164 | 164 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | ); |
169 | 169 | |
170 | 170 | $excluded_user_ids = array_unique( |
171 | - array_merge( $excluded_user_ids, $user_ids ) |
|
171 | + array_merge($excluded_user_ids, $user_ids) |
|
172 | 172 | ); |
173 | 173 | |
174 | 174 | wordpoints_update_maybe_network_option( |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | |
179 | 179 | $this->feedback->success( |
180 | 180 | sprintf( |
181 | - __( 'Imported %s excluded users.', 'wordpoints-importer' ) |
|
182 | - , count( $user_ids ) |
|
181 | + __('Imported %s excluded users.', 'wordpoints-importer') |
|
182 | + , count($user_ids) |
|
183 | 183 | ) |
184 | 184 | ); |
185 | 185 | } |
@@ -191,64 +191,64 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @param array $settings The settings for the points component import. |
193 | 193 | */ |
194 | - protected function import_points_settings( $settings ) { |
|
194 | + protected function import_points_settings($settings) { |
|
195 | 195 | |
196 | - $this->feedback->info( __( 'Importing points hooks…', 'wordpoints-importer' ) ); |
|
196 | + $this->feedback->info(__('Importing points hooks…', 'wordpoints-importer')); |
|
197 | 197 | |
198 | 198 | $options = array( |
199 | 199 | 'cp_comment_points' => array( |
200 | 200 | 'event' => 'comment_leave\post', |
201 | - 'target' => array( 'comment\post', 'author', 'user' ), |
|
201 | + 'target' => array('comment\post', 'author', 'user'), |
|
202 | 202 | /* translators: The post type name */ |
203 | - 'log_text' => __( 'Comment on a %s.', 'wordpoints-importer' ), |
|
203 | + 'log_text' => __('Comment on a %s.', 'wordpoints-importer'), |
|
204 | 204 | /* translators: The post type name */ |
205 | - 'description' => __( 'Commenting on a %s.', 'wordpoints-importer' ), |
|
205 | + 'description' => __('Commenting on a %s.', 'wordpoints-importer'), |
|
206 | 206 | 'legacy_log_type' => 'cubepoints-comment', |
207 | 207 | 'legacy_meta_key' => 'comment', |
208 | 208 | ), |
209 | 209 | 'cp_post_points' => array( |
210 | 210 | 'event' => 'post_publish\post', |
211 | - 'target' => array( 'post\post', 'author', 'user' ), |
|
211 | + 'target' => array('post\post', 'author', 'user'), |
|
212 | 212 | /* translators: The post type name */ |
213 | - 'log_text' => __( 'Published a Post.', 'wordpoints-importer' ), |
|
213 | + 'log_text' => __('Published a Post.', 'wordpoints-importer'), |
|
214 | 214 | /* translators: The post type name */ |
215 | - 'description' => __( 'Publishing a Post.', 'wordpoints-importer' ), |
|
215 | + 'description' => __('Publishing a Post.', 'wordpoints-importer'), |
|
216 | 216 | 'legacy_log_type' => 'cubepoints-post', |
217 | 217 | 'legacy_meta_key' => 'post', |
218 | 218 | // CubePoints doesn't remove points when a post is deleted. |
219 | - 'blocker' => array( 'toggle_off' => true ), |
|
220 | - 'points_legacy_repeat_blocker' => array( 'toggle_on' => true ), |
|
219 | + 'blocker' => array('toggle_off' => true), |
|
220 | + 'points_legacy_repeat_blocker' => array('toggle_on' => true), |
|
221 | 221 | ), |
222 | 222 | 'cp_reg_points' => array( |
223 | 223 | 'event' => 'user_register', |
224 | - 'log_text' => __( 'Registration.', 'wordpoints-importer' ), |
|
225 | - 'description' => __( 'Registration.', 'wordpoints-importer' ), |
|
224 | + 'log_text' => __('Registration.', 'wordpoints-importer'), |
|
225 | + 'description' => __('Registration.', 'wordpoints-importer'), |
|
226 | 226 | 'legacy_log_type' => 'cubepoints-register', |
227 | 227 | ), |
228 | 228 | 'cp_post_author_points' => array( |
229 | 229 | 'event' => 'comment_leave\post', |
230 | - 'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ), |
|
230 | + 'target' => array('comment\post', 'post\post', 'post\post', 'author', 'user'), |
|
231 | 231 | /* translators: The post type name */ |
232 | - 'log_text' => __( 'Received a comment on a %s.', 'wordpoints-importer' ), |
|
232 | + 'log_text' => __('Received a comment on a %s.', 'wordpoints-importer'), |
|
233 | 233 | /* translators: The post type name */ |
234 | - 'description' => __( 'Receiving a comment on a %s.', 'wordpoints-importer' ), |
|
234 | + 'description' => __('Receiving a comment on a %s.', 'wordpoints-importer'), |
|
235 | 235 | 'legacy_log_type' => 'cubepoints-post_author', |
236 | 236 | 'legacy_meta_key' => 'comment', |
237 | 237 | ), |
238 | 238 | ); |
239 | 239 | |
240 | 240 | // Don't import this module setting if the module isn't active. |
241 | - if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'post_author_points' ) ) { |
|
242 | - unset( $options['cp_post_author_points'] ); |
|
241 | + if (function_exists('cp_module_activated') && !cp_module_activated('post_author_points')) { |
|
242 | + unset($options['cp_post_author_points']); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $imported = 0; |
246 | 246 | |
247 | - foreach ( $options as $option => $hook_settings ) { |
|
247 | + foreach ($options as $option => $hook_settings) { |
|
248 | 248 | |
249 | - $points = get_option( $option ); |
|
249 | + $points = get_option($option); |
|
250 | 250 | |
251 | - if ( wordpoints_posint( $points ) ) { |
|
251 | + if (wordpoints_posint($points)) { |
|
252 | 252 | |
253 | 253 | $hook_settings['points'] = $points; |
254 | 254 | $hook_settings['points_type'] = $settings['points_type']; |
@@ -256,12 +256,12 @@ discard block |
||
256 | 256 | if ( |
257 | 257 | // The CubePoints post points were only awarded for Posts. |
258 | 258 | 'post_publish\post' !== $hook_settings['event'] |
259 | - && strpos( $hook_settings['event'], '\post' ) |
|
259 | + && strpos($hook_settings['event'], '\post') |
|
260 | 260 | ) { |
261 | 261 | |
262 | - $post_type_slugs = get_post_types( array( 'public' => true ) ); |
|
262 | + $post_type_slugs = get_post_types(array('public' => true)); |
|
263 | 263 | |
264 | - foreach ( $post_type_slugs as $post_type_slug ) { |
|
264 | + foreach ($post_type_slugs as $post_type_slug) { |
|
265 | 265 | |
266 | 266 | $added = $this->add_points_hook( |
267 | 267 | $this->format_settings_for_post_type( |
@@ -270,25 +270,25 @@ discard block |
||
270 | 270 | ) |
271 | 271 | ); |
272 | 272 | |
273 | - if ( $added ) { |
|
273 | + if ($added) { |
|
274 | 274 | $imported++; |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | } else { |
279 | - if ( $this->add_points_hook( $hook_settings ) ) { |
|
279 | + if ($this->add_points_hook($hook_settings)) { |
|
280 | 280 | $imported++; |
281 | 281 | } |
282 | 282 | } |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if ( $this->import_daily_points_hook( $settings ) ) { |
|
286 | + if ($this->import_daily_points_hook($settings)) { |
|
287 | 287 | $imported++; |
288 | 288 | } |
289 | 289 | |
290 | 290 | $this->feedback->success( |
291 | - sprintf( __( 'Imported %s points hooks.', 'wordpoints-importer' ), $imported ) |
|
291 | + sprintf(__('Imported %s points hooks.', 'wordpoints-importer'), $imported) |
|
292 | 292 | ); |
293 | 293 | } |
294 | 294 | |
@@ -301,24 +301,24 @@ discard block |
||
301 | 301 | * |
302 | 302 | * @return bool True if the settings were imported, false otherwise. |
303 | 303 | */ |
304 | - protected function import_daily_points_hook( $settings ) { |
|
304 | + protected function import_daily_points_hook($settings) { |
|
305 | 305 | |
306 | 306 | // Don't import this module setting if the module isn't active. |
307 | - if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) { |
|
307 | + if (function_exists('cp_module_activated') && !cp_module_activated('dailypoints')) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | |
311 | - $points = get_option( 'cp_module_dailypoints_points' ); |
|
312 | - $period = get_option( 'cp_module_dailypoints_time' ); |
|
311 | + $points = get_option('cp_module_dailypoints_points'); |
|
312 | + $period = get_option('cp_module_dailypoints_time'); |
|
313 | 313 | |
314 | - if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) { |
|
314 | + if (!wordpoints_int($points) || !wordpoints_posint($period)) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | 318 | return $this->add_points_hook( |
319 | 319 | array( |
320 | 320 | 'event' => 'user_visit', |
321 | - 'target' => array( 'current:user' ), |
|
321 | + 'target' => array('current:user'), |
|
322 | 322 | 'reactor' => 'points_legacy', |
323 | 323 | 'points' => $points, |
324 | 324 | 'points_type' => $settings['points_type'], |
@@ -326,13 +326,13 @@ discard block |
||
326 | 326 | 'fire' => array( |
327 | 327 | array( |
328 | 328 | 'length' => $period, |
329 | - 'args' => array( array( 'current:user' ) ), |
|
329 | + 'args' => array(array('current:user')), |
|
330 | 330 | 'relative' => true, |
331 | 331 | ), |
332 | 332 | ), |
333 | 333 | ), |
334 | - 'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
335 | - 'description' => __( 'Visiting the site.', 'wordpoints-importer' ), |
|
334 | + 'log_text' => __('Visiting the site.', 'wordpoints-importer'), |
|
335 | + 'description' => __('Visiting the site.', 'wordpoints-importer'), |
|
336 | 336 | 'points_legacy_reversals' => array(), |
337 | 337 | 'legacy_log_type' => 'cubepoints-dailypoints', |
338 | 338 | ) |
@@ -349,22 +349,22 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @return bool True if added successfully, or false on failure. |
351 | 351 | */ |
352 | - private function add_points_hook( $settings = array() ) { |
|
352 | + private function add_points_hook($settings = array()) { |
|
353 | 353 | |
354 | - $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' ); |
|
354 | + $reaction_store = wordpoints_hooks()->get_reaction_store('points'); |
|
355 | 355 | |
356 | 356 | $settings = array_merge( |
357 | 357 | array( |
358 | - 'target' => array( 'user' ), |
|
358 | + 'target' => array('user'), |
|
359 | 359 | 'reactor' => 'points_legacy', |
360 | - 'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ), |
|
360 | + 'points_legacy_reversals' => array('toggle_off' => 'toggle_on'), |
|
361 | 361 | ) |
362 | 362 | , $settings |
363 | 363 | ); |
364 | 364 | |
365 | - $reaction = $reaction_store->create_reaction( $settings ); |
|
365 | + $reaction = $reaction_store->create_reaction($settings); |
|
366 | 366 | |
367 | - if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) { |
|
367 | + if (!$reaction instanceof WordPoints_Hook_ReactionI) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | |
@@ -381,24 +381,24 @@ discard block |
||
381 | 381 | * |
382 | 382 | * @return array The settings modified for this particular post type. |
383 | 383 | */ |
384 | - protected function format_settings_for_post_type( $post_type, $settings ) { |
|
384 | + protected function format_settings_for_post_type($post_type, $settings) { |
|
385 | 385 | |
386 | 386 | $settings['event'] = str_replace( |
387 | 387 | '\post' |
388 | - , '\\' . $post_type |
|
388 | + , '\\'.$post_type |
|
389 | 389 | , $settings['event'] |
390 | 390 | ); |
391 | 391 | |
392 | 392 | $settings['target'] = str_replace( |
393 | 393 | '\post' |
394 | - , '\\' . $post_type |
|
394 | + , '\\'.$post_type |
|
395 | 395 | , $settings['target'] |
396 | 396 | ); |
397 | 397 | |
398 | - $labels = get_post_type_labels( get_post_type_object( $post_type ) ); |
|
398 | + $labels = get_post_type_labels(get_post_type_object($post_type)); |
|
399 | 399 | |
400 | - $settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name ); |
|
401 | - $settings['description'] = sprintf( $settings['description'], $labels->singular_name ); |
|
400 | + $settings['log_text'] = sprintf($settings['log_text'], $labels->singular_name); |
|
401 | + $settings['description'] = sprintf($settings['description'], $labels->singular_name); |
|
402 | 402 | |
403 | 403 | return $settings; |
404 | 404 | } |
@@ -410,21 +410,21 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param array $settings The settings for the points component import. |
412 | 412 | */ |
413 | - protected function import_user_points( $settings ) { |
|
413 | + protected function import_user_points($settings) { |
|
414 | 414 | |
415 | - $this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) ); |
|
415 | + $this->feedback->info(__('Importing users' points…', 'wordpoints-importer')); |
|
416 | 416 | |
417 | 417 | // We don't log the import transactions. |
418 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
418 | + add_filter('wordpoints_points_log', '__return_false'); |
|
419 | 419 | |
420 | 420 | $start = 0; |
421 | 421 | |
422 | 422 | // We do the import in batches. |
423 | - while ( $rows = $this->get_next_user_points_batch( $start ) ) { |
|
423 | + while ($rows = $this->get_next_user_points_batch($start)) { |
|
424 | 424 | |
425 | - $start += count( $rows ); |
|
425 | + $start += count($rows); |
|
426 | 426 | |
427 | - foreach ( $rows as $row ) { |
|
427 | + foreach ($rows as $row) { |
|
428 | 428 | |
429 | 429 | wordpoints_alter_points( |
430 | 430 | $row->user_id |
@@ -434,12 +434,12 @@ discard block |
||
434 | 434 | ); |
435 | 435 | } |
436 | 436 | |
437 | - unset( $rows ); |
|
437 | + unset($rows); |
|
438 | 438 | } |
439 | 439 | |
440 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
440 | + remove_filter('wordpoints_points_log', '__return_false'); |
|
441 | 441 | |
442 | - $this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) ); |
|
442 | + $this->feedback->success(sprintf(__('Imported points for %s users…', 'wordpoints-importer'), $start)); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * |
452 | 452 | * @return object[]|false The rows, or false. |
453 | 453 | */ |
454 | - protected function get_next_user_points_batch( $start ) { |
|
454 | + protected function get_next_user_points_batch($start) { |
|
455 | 455 | |
456 | 456 | global $wpdb; |
457 | 457 | |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | ) |
469 | 469 | ); // WPCS: cache OK. |
470 | 470 | |
471 | - if ( ! is_array( $rows ) ) { |
|
471 | + if (!is_array($rows)) { |
|
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | */ |
485 | 485 | public function can_import_points_logs() { |
486 | 486 | |
487 | - if ( ! $this->is_cubepoints_active() ) { |
|
487 | + if (!$this->is_cubepoints_active()) { |
|
488 | 488 | |
489 | 489 | return new WP_Error( |
490 | 490 | 'wordpoints_import_points_logs_cubepoints_inactive' |
491 | - , __( 'CubePoints must be active.', 'wordpoints-importer' ) |
|
491 | + , __('CubePoints must be active.', 'wordpoints-importer') |
|
492 | 492 | ); |
493 | 493 | } |
494 | 494 | |
@@ -502,17 +502,17 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @param array $settings The import settings for the points component. |
504 | 504 | */ |
505 | - protected function import_points_logs( $settings ) { |
|
505 | + protected function import_points_logs($settings) { |
|
506 | 506 | |
507 | - $this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) ); |
|
507 | + $this->feedback->info(__('Importing points logs…', 'wordpoints-importer')); |
|
508 | 508 | |
509 | 509 | $start = 0; |
510 | 510 | |
511 | - while ( $logs = $this->get_next_points_logs_batch( $start ) ) { |
|
511 | + while ($logs = $this->get_next_points_logs_batch($start)) { |
|
512 | 512 | |
513 | - $start += count( $logs ); |
|
513 | + $start += count($logs); |
|
514 | 514 | |
515 | - foreach ( $logs as $log ) { |
|
515 | + foreach ($logs as $log) { |
|
516 | 516 | |
517 | 517 | $this->import_points_log( |
518 | 518 | $log->uid |
@@ -523,14 +523,14 @@ discard block |
||
523 | 523 | 'cubepoints_type' => $log->type, |
524 | 524 | 'cubepoints_data' => $log->data, |
525 | 525 | ) |
526 | - , date( 'Y-m-d H:i:s', $log->timestamp ) |
|
526 | + , date('Y-m-d H:i:s', $log->timestamp) |
|
527 | 527 | ); |
528 | 528 | } |
529 | 529 | |
530 | - unset( $logs ); |
|
530 | + unset($logs); |
|
531 | 531 | } |
532 | 532 | |
533 | - $this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) ); |
|
533 | + $this->feedback->success(sprintf(__('Imported %s points log entries.', 'wordpoints-importer'), $start)); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param array $meta The metadata for this log. |
546 | 546 | * @param int $date The date the transaction took place. |
547 | 547 | */ |
548 | - protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) { |
|
548 | + protected function import_points_log($user_id, $points, $points_type, $log_type, $meta, $date) { |
|
549 | 549 | |
550 | 550 | global $wpdb; |
551 | 551 | |
@@ -556,54 +556,54 @@ discard block |
||
556 | 556 | 'points' => $points, |
557 | 557 | 'points_type' => $points_type, |
558 | 558 | 'log_type' => $log_type, |
559 | - 'text' => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ), |
|
559 | + 'text' => $this->render_points_log_text('', $user_id, $points, $points_type, $log_type, $meta), |
|
560 | 560 | 'date' => $date, |
561 | 561 | 'site_id' => $wpdb->siteid, |
562 | 562 | 'blog_id' => $wpdb->blogid, |
563 | 563 | ), |
564 | - array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' ) |
|
564 | + array('%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d') |
|
565 | 565 | ); |
566 | 566 | |
567 | - if ( false !== $result ) { |
|
567 | + if (false !== $result) { |
|
568 | 568 | |
569 | 569 | $log_id = (int) $wpdb->insert_id; |
570 | 570 | |
571 | 571 | // Set auto_reversed and original_log_id metadata for reversed logs. |
572 | - foreach ( $this->reversible_log_types as $reverse_type => $type ) { |
|
572 | + foreach ($this->reversible_log_types as $reverse_type => $type) { |
|
573 | 573 | |
574 | - if ( $meta['cubepoints_type'] === $type ) { |
|
574 | + if ($meta['cubepoints_type'] === $type) { |
|
575 | 575 | |
576 | 576 | // Save this log ID for later, in case this log was reversed. |
577 | 577 | // cubepoints_data will contain the entity ID. |
578 | - $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id; |
|
578 | + $this->reversible_log_ids[$type][$meta['cubepoints_data']] = $log_id; |
|
579 | 579 | |
580 | 580 | } elseif ( |
581 | 581 | $meta['cubepoints_type'] === $reverse_type |
582 | - && isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ) |
|
582 | + && isset($this->reversible_log_ids[$type][$meta['cubepoints_data']]) |
|
583 | 583 | ) { |
584 | 584 | |
585 | 585 | // This log was reverses another one. Set the original log ID. |
586 | - $meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ]; |
|
586 | + $meta['original_log_id'] = $this->reversible_log_ids[$type][$meta['cubepoints_data']]; |
|
587 | 587 | |
588 | 588 | // And mark the original as auto_reversed. |
589 | - wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id ); |
|
589 | + wordpoints_add_points_log_meta($meta['original_log_id'], 'auto_reversed', $log_id); |
|
590 | 590 | |
591 | 591 | // No need to keep this info anymore. |
592 | - unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] ); |
|
592 | + unset($this->reversible_log_ids[$type][$meta['cubepoints_data']]); |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | |
596 | 596 | // Set the entity IDs to their own meta keys, for the sake of reversals. |
597 | - if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) { |
|
598 | - $meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data']; |
|
597 | + if (isset($this->log_type_entities[$meta['cubepoints_type']])) { |
|
598 | + $meta[$this->log_type_entities[$meta['cubepoints_type']]] = $meta['cubepoints_data']; |
|
599 | 599 | } |
600 | 600 | |
601 | - foreach ( $meta as $meta_key => $meta_value ) { |
|
601 | + foreach ($meta as $meta_key => $meta_value) { |
|
602 | 602 | |
603 | - wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value ); |
|
603 | + wordpoints_add_points_log_meta($log_id, $meta_key, $meta_value); |
|
604 | 604 | } |
605 | 605 | |
606 | - do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id ); |
|
606 | + do_action('wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
@@ -612,10 +612,10 @@ discard block |
||
612 | 612 | * |
613 | 613 | * @since 1.0.0 |
614 | 614 | */ |
615 | - public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) { |
|
615 | + public function render_points_log_text($text, $user_id, $points, $points_type, $log_type, $meta) { |
|
616 | 616 | |
617 | 617 | ob_start(); |
618 | - do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] ); |
|
618 | + do_action('cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data']); |
|
619 | 619 | return ob_get_clean(); |
620 | 620 | } |
621 | 621 | |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | * |
629 | 629 | * @return object[]|false The rows from the database. |
630 | 630 | */ |
631 | - protected function get_next_points_logs_batch( $start ) { |
|
631 | + protected function get_next_points_logs_batch($start) { |
|
632 | 632 | |
633 | 633 | global $wpdb; |
634 | 634 | |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | $wpdb->prepare( |
637 | 637 | ' |
638 | 638 | SELECT * |
639 | - FROM `' . CP_DB . '` |
|
639 | + FROM `' . CP_DB.'` |
|
640 | 640 | ORDER BY `id` |
641 | 641 | LIMIT %d,500 |
642 | 642 | ' |
@@ -644,8 +644,8 @@ discard block |
||
644 | 644 | ) |
645 | 645 | ); // WPCS: cache OK. |
646 | 646 | |
647 | - if ( ! is_array( $logs ) ) { |
|
648 | - $this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) ); |
|
647 | + if (!is_array($logs)) { |
|
648 | + $this->feedback->error(__('Unable to retrieve the logs from CubePoints…', 'wordpoints-importer')); |
|
649 | 649 | return false; |
650 | 650 | } |
651 | 651 | |
@@ -659,24 +659,24 @@ discard block |
||
659 | 659 | * |
660 | 660 | * @param array $settings The import settings for the ranks component. |
661 | 661 | */ |
662 | - public function import_ranks( $settings ) { |
|
662 | + public function import_ranks($settings) { |
|
663 | 663 | |
664 | - $this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) ); |
|
664 | + $this->feedback->info(__('Importing ranks…', 'wordpoints-importer')); |
|
665 | 665 | |
666 | - $ranks_data = get_option( 'cp_module_ranks_data' ); |
|
666 | + $ranks_data = get_option('cp_module_ranks_data'); |
|
667 | 667 | |
668 | - if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) { |
|
669 | - $this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) ); |
|
668 | + if (empty($ranks_data) || !is_array($ranks_data)) { |
|
669 | + $this->feedback->error(__('No ranks found.', 'wordpoints-importer')); |
|
670 | 670 | return; |
671 | 671 | } |
672 | 672 | |
673 | 673 | $i = 0; |
674 | 674 | |
675 | 675 | // The base rank already exists, so we just update it. |
676 | - if ( isset( $ranks_data[0] ) ) { |
|
676 | + if (isset($ranks_data[0])) { |
|
677 | 677 | |
678 | 678 | wordpoints_update_rank( |
679 | - WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 ) |
|
679 | + WordPoints_Rank_Groups::get_group($settings['rank_group'])->get_rank(0) |
|
680 | 680 | , $ranks_data[0] |
681 | 681 | , 'base' |
682 | 682 | , $settings['rank_group'] |
@@ -685,28 +685,28 @@ discard block |
||
685 | 685 | |
686 | 686 | $i++; |
687 | 687 | |
688 | - unset( $ranks_data[0] ); |
|
688 | + unset($ranks_data[0]); |
|
689 | 689 | } |
690 | 690 | |
691 | - $points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) ); |
|
692 | - $rank_type = 'points-' . $points_type; |
|
691 | + $points_type = substr($settings['rank_group'], strlen('points_type-')); |
|
692 | + $rank_type = 'points-'.$points_type; |
|
693 | 693 | |
694 | - ksort( $ranks_data ); |
|
694 | + ksort($ranks_data); |
|
695 | 695 | |
696 | - foreach ( $ranks_data as $points => $rank_name ) { |
|
696 | + foreach ($ranks_data as $points => $rank_name) { |
|
697 | 697 | |
698 | 698 | wordpoints_add_rank( |
699 | 699 | $rank_name |
700 | 700 | , $rank_type |
701 | 701 | , $settings['rank_group'] |
702 | 702 | , $i |
703 | - , array( 'points' => $points, 'points_type' => $points_type ) |
|
703 | + , array('points' => $points, 'points_type' => $points_type) |
|
704 | 704 | ); |
705 | 705 | |
706 | 706 | $i++; |
707 | 707 | } |
708 | 708 | |
709 | - $this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) ); |
|
709 | + $this->feedback->success(sprintf(__('Imported %s ranks.', 'wordpoints-importer'), $i)); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 |
@@ -14,181 +14,181 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPoints_Importer_Admin_Test extends WordPoints_Points_UnitTestCase { |
16 | 16 | |
17 | - /** |
|
18 | - * Test that a points type must be supplied. |
|
19 | - * |
|
20 | - * @since 1.0.0 |
|
21 | - * |
|
22 | - * @covers ::wordpoints_importer_validate_points_type_setting |
|
23 | - */ |
|
24 | - public function test_validate_points_type_setting_not_set() { |
|
25 | - |
|
26 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
27 | - |
|
28 | - $valid = wordpoints_importer_validate_points_type_setting( |
|
29 | - true |
|
30 | - , array() |
|
31 | - , $feedback |
|
32 | - ); |
|
33 | - |
|
34 | - $this->assertFalse( $valid ); |
|
35 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Test that the points type supplied must be valid. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - * |
|
43 | - * @covers ::wordpoints_importer_validate_points_type_setting |
|
44 | - */ |
|
45 | - public function test_validate_points_type_setting_invalid() { |
|
46 | - |
|
47 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
48 | - |
|
49 | - $valid = wordpoints_importer_validate_points_type_setting( |
|
50 | - true |
|
51 | - , array( 'points_type' => 'invalid' ) |
|
52 | - , $feedback |
|
53 | - ); |
|
54 | - |
|
55 | - $this->assertFalse( $valid ); |
|
56 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Test that it returns true when supplied a valid points type. |
|
61 | - * |
|
62 | - * @since 1.0.0 |
|
63 | - * |
|
64 | - * @covers ::wordpoints_importer_validate_points_type_setting |
|
65 | - */ |
|
66 | - public function test_validate_points_type_setting_valid() { |
|
67 | - |
|
68 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
69 | - |
|
70 | - $valid = wordpoints_importer_validate_points_type_setting( |
|
71 | - true |
|
72 | - , array( 'points_type' => 'points' ) |
|
73 | - , $feedback |
|
74 | - ); |
|
75 | - |
|
76 | - $this->assertTrue( $valid ); |
|
77 | - $this->assertEmpty( $feedback->messages ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Test that it returns false when supplied a valid points type if $valid is false. |
|
82 | - * |
|
83 | - * @since 1.0.0 |
|
84 | - * |
|
85 | - * @covers ::wordpoints_importer_validate_points_type_setting |
|
86 | - */ |
|
87 | - public function test_validate_points_type_setting_valid_false() { |
|
88 | - |
|
89 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
90 | - |
|
91 | - $valid = wordpoints_importer_validate_points_type_setting( |
|
92 | - false |
|
93 | - , array( 'points_type' => 'points' ) |
|
94 | - , $feedback |
|
95 | - ); |
|
96 | - |
|
97 | - $this->assertFalse( $valid ); |
|
98 | - $this->assertEmpty( $feedback->messages ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Test that a rank group must be supplied. |
|
103 | - * |
|
104 | - * @since 1.1.0 |
|
105 | - * |
|
106 | - * @covers ::wordpoints_importer_validate_rank_group_setting |
|
107 | - */ |
|
108 | - public function test_validate_rank_group_setting_not_set() { |
|
109 | - |
|
110 | - wordpoints_register_points_ranks(); |
|
111 | - |
|
112 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
113 | - |
|
114 | - $valid = wordpoints_importer_validate_rank_group_setting( |
|
115 | - true |
|
116 | - , array() |
|
117 | - , $feedback |
|
118 | - ); |
|
119 | - |
|
120 | - $this->assertFalse( $valid ); |
|
121 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Test that the rank group supplied must be valid. |
|
126 | - * |
|
127 | - * @since 1.1.0 |
|
128 | - * |
|
129 | - * @covers ::wordpoints_importer_validate_rank_group_setting |
|
130 | - */ |
|
131 | - public function test_validate_rank_group_setting_invalid() { |
|
132 | - |
|
133 | - wordpoints_register_points_ranks(); |
|
134 | - |
|
135 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
136 | - |
|
137 | - $valid = wordpoints_importer_validate_rank_group_setting( |
|
138 | - true |
|
139 | - , array( 'rank_group' => 'invalid' ) |
|
140 | - , $feedback |
|
141 | - ); |
|
142 | - |
|
143 | - $this->assertFalse( $valid ); |
|
144 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Test that it returns true when supplied a valid rank group. |
|
149 | - * |
|
150 | - * @since 1.1.0 |
|
151 | - * |
|
152 | - * @covers ::wordpoints_importer_validate_rank_group_setting |
|
153 | - */ |
|
154 | - public function test_validate_rank_group_setting_valid() { |
|
155 | - |
|
156 | - wordpoints_register_points_ranks(); |
|
157 | - |
|
158 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
159 | - |
|
160 | - $valid = wordpoints_importer_validate_rank_group_setting( |
|
161 | - true |
|
162 | - , array( 'rank_group' => 'points_type-points' ) |
|
163 | - , $feedback |
|
164 | - ); |
|
165 | - |
|
166 | - $this->assertTrue( $valid ); |
|
167 | - $this->assertEmpty( $feedback->messages ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Test that it returns false when supplied a valid rank group if $valid is false. |
|
172 | - * |
|
173 | - * @since 1.1.0 |
|
174 | - * |
|
175 | - * @covers ::wordpoints_importer_validate_rank_group_setting |
|
176 | - */ |
|
177 | - public function test_validate_rank_group_setting_valid_false() { |
|
178 | - |
|
179 | - wordpoints_register_points_ranks(); |
|
180 | - |
|
181 | - $feedback = new WordPoints_Importer_Tests_Feedback; |
|
182 | - |
|
183 | - $valid = wordpoints_importer_validate_rank_group_setting( |
|
184 | - false |
|
185 | - , array( 'rank_group' => 'points_type-points' ) |
|
186 | - , $feedback |
|
187 | - ); |
|
188 | - |
|
189 | - $this->assertFalse( $valid ); |
|
190 | - $this->assertEmpty( $feedback->messages ); |
|
191 | - } |
|
17 | + /** |
|
18 | + * Test that a points type must be supplied. |
|
19 | + * |
|
20 | + * @since 1.0.0 |
|
21 | + * |
|
22 | + * @covers ::wordpoints_importer_validate_points_type_setting |
|
23 | + */ |
|
24 | + public function test_validate_points_type_setting_not_set() { |
|
25 | + |
|
26 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
27 | + |
|
28 | + $valid = wordpoints_importer_validate_points_type_setting( |
|
29 | + true |
|
30 | + , array() |
|
31 | + , $feedback |
|
32 | + ); |
|
33 | + |
|
34 | + $this->assertFalse( $valid ); |
|
35 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Test that the points type supplied must be valid. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + * |
|
43 | + * @covers ::wordpoints_importer_validate_points_type_setting |
|
44 | + */ |
|
45 | + public function test_validate_points_type_setting_invalid() { |
|
46 | + |
|
47 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
48 | + |
|
49 | + $valid = wordpoints_importer_validate_points_type_setting( |
|
50 | + true |
|
51 | + , array( 'points_type' => 'invalid' ) |
|
52 | + , $feedback |
|
53 | + ); |
|
54 | + |
|
55 | + $this->assertFalse( $valid ); |
|
56 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Test that it returns true when supplied a valid points type. |
|
61 | + * |
|
62 | + * @since 1.0.0 |
|
63 | + * |
|
64 | + * @covers ::wordpoints_importer_validate_points_type_setting |
|
65 | + */ |
|
66 | + public function test_validate_points_type_setting_valid() { |
|
67 | + |
|
68 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
69 | + |
|
70 | + $valid = wordpoints_importer_validate_points_type_setting( |
|
71 | + true |
|
72 | + , array( 'points_type' => 'points' ) |
|
73 | + , $feedback |
|
74 | + ); |
|
75 | + |
|
76 | + $this->assertTrue( $valid ); |
|
77 | + $this->assertEmpty( $feedback->messages ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Test that it returns false when supplied a valid points type if $valid is false. |
|
82 | + * |
|
83 | + * @since 1.0.0 |
|
84 | + * |
|
85 | + * @covers ::wordpoints_importer_validate_points_type_setting |
|
86 | + */ |
|
87 | + public function test_validate_points_type_setting_valid_false() { |
|
88 | + |
|
89 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
90 | + |
|
91 | + $valid = wordpoints_importer_validate_points_type_setting( |
|
92 | + false |
|
93 | + , array( 'points_type' => 'points' ) |
|
94 | + , $feedback |
|
95 | + ); |
|
96 | + |
|
97 | + $this->assertFalse( $valid ); |
|
98 | + $this->assertEmpty( $feedback->messages ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Test that a rank group must be supplied. |
|
103 | + * |
|
104 | + * @since 1.1.0 |
|
105 | + * |
|
106 | + * @covers ::wordpoints_importer_validate_rank_group_setting |
|
107 | + */ |
|
108 | + public function test_validate_rank_group_setting_not_set() { |
|
109 | + |
|
110 | + wordpoints_register_points_ranks(); |
|
111 | + |
|
112 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
113 | + |
|
114 | + $valid = wordpoints_importer_validate_rank_group_setting( |
|
115 | + true |
|
116 | + , array() |
|
117 | + , $feedback |
|
118 | + ); |
|
119 | + |
|
120 | + $this->assertFalse( $valid ); |
|
121 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Test that the rank group supplied must be valid. |
|
126 | + * |
|
127 | + * @since 1.1.0 |
|
128 | + * |
|
129 | + * @covers ::wordpoints_importer_validate_rank_group_setting |
|
130 | + */ |
|
131 | + public function test_validate_rank_group_setting_invalid() { |
|
132 | + |
|
133 | + wordpoints_register_points_ranks(); |
|
134 | + |
|
135 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
136 | + |
|
137 | + $valid = wordpoints_importer_validate_rank_group_setting( |
|
138 | + true |
|
139 | + , array( 'rank_group' => 'invalid' ) |
|
140 | + , $feedback |
|
141 | + ); |
|
142 | + |
|
143 | + $this->assertFalse( $valid ); |
|
144 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Test that it returns true when supplied a valid rank group. |
|
149 | + * |
|
150 | + * @since 1.1.0 |
|
151 | + * |
|
152 | + * @covers ::wordpoints_importer_validate_rank_group_setting |
|
153 | + */ |
|
154 | + public function test_validate_rank_group_setting_valid() { |
|
155 | + |
|
156 | + wordpoints_register_points_ranks(); |
|
157 | + |
|
158 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
159 | + |
|
160 | + $valid = wordpoints_importer_validate_rank_group_setting( |
|
161 | + true |
|
162 | + , array( 'rank_group' => 'points_type-points' ) |
|
163 | + , $feedback |
|
164 | + ); |
|
165 | + |
|
166 | + $this->assertTrue( $valid ); |
|
167 | + $this->assertEmpty( $feedback->messages ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Test that it returns false when supplied a valid rank group if $valid is false. |
|
172 | + * |
|
173 | + * @since 1.1.0 |
|
174 | + * |
|
175 | + * @covers ::wordpoints_importer_validate_rank_group_setting |
|
176 | + */ |
|
177 | + public function test_validate_rank_group_setting_valid_false() { |
|
178 | + |
|
179 | + wordpoints_register_points_ranks(); |
|
180 | + |
|
181 | + $feedback = new WordPoints_Importer_Tests_Feedback; |
|
182 | + |
|
183 | + $valid = wordpoints_importer_validate_rank_group_setting( |
|
184 | + false |
|
185 | + , array( 'rank_group' => 'points_type-points' ) |
|
186 | + , $feedback |
|
187 | + ); |
|
188 | + |
|
189 | + $this->assertFalse( $valid ); |
|
190 | + $this->assertEmpty( $feedback->messages ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // EOF |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | , $feedback |
32 | 32 | ); |
33 | 33 | |
34 | - $this->assertFalse( $valid ); |
|
35 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
34 | + $this->assertFalse($valid); |
|
35 | + $this->assertCount(1, $feedback->messages['warning']); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | |
49 | 49 | $valid = wordpoints_importer_validate_points_type_setting( |
50 | 50 | true |
51 | - , array( 'points_type' => 'invalid' ) |
|
51 | + , array('points_type' => 'invalid') |
|
52 | 52 | , $feedback |
53 | 53 | ); |
54 | 54 | |
55 | - $this->assertFalse( $valid ); |
|
56 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
55 | + $this->assertFalse($valid); |
|
56 | + $this->assertCount(1, $feedback->messages['warning']); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | |
70 | 70 | $valid = wordpoints_importer_validate_points_type_setting( |
71 | 71 | true |
72 | - , array( 'points_type' => 'points' ) |
|
72 | + , array('points_type' => 'points') |
|
73 | 73 | , $feedback |
74 | 74 | ); |
75 | 75 | |
76 | - $this->assertTrue( $valid ); |
|
77 | - $this->assertEmpty( $feedback->messages ); |
|
76 | + $this->assertTrue($valid); |
|
77 | + $this->assertEmpty($feedback->messages); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | |
91 | 91 | $valid = wordpoints_importer_validate_points_type_setting( |
92 | 92 | false |
93 | - , array( 'points_type' => 'points' ) |
|
93 | + , array('points_type' => 'points') |
|
94 | 94 | , $feedback |
95 | 95 | ); |
96 | 96 | |
97 | - $this->assertFalse( $valid ); |
|
98 | - $this->assertEmpty( $feedback->messages ); |
|
97 | + $this->assertFalse($valid); |
|
98 | + $this->assertEmpty($feedback->messages); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | , $feedback |
118 | 118 | ); |
119 | 119 | |
120 | - $this->assertFalse( $valid ); |
|
121 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
120 | + $this->assertFalse($valid); |
|
121 | + $this->assertCount(1, $feedback->messages['warning']); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | |
137 | 137 | $valid = wordpoints_importer_validate_rank_group_setting( |
138 | 138 | true |
139 | - , array( 'rank_group' => 'invalid' ) |
|
139 | + , array('rank_group' => 'invalid') |
|
140 | 140 | , $feedback |
141 | 141 | ); |
142 | 142 | |
143 | - $this->assertFalse( $valid ); |
|
144 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
143 | + $this->assertFalse($valid); |
|
144 | + $this->assertCount(1, $feedback->messages['warning']); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | |
160 | 160 | $valid = wordpoints_importer_validate_rank_group_setting( |
161 | 161 | true |
162 | - , array( 'rank_group' => 'points_type-points' ) |
|
162 | + , array('rank_group' => 'points_type-points') |
|
163 | 163 | , $feedback |
164 | 164 | ); |
165 | 165 | |
166 | - $this->assertTrue( $valid ); |
|
167 | - $this->assertEmpty( $feedback->messages ); |
|
166 | + $this->assertTrue($valid); |
|
167 | + $this->assertEmpty($feedback->messages); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | |
183 | 183 | $valid = wordpoints_importer_validate_rank_group_setting( |
184 | 184 | false |
185 | - , array( 'rank_group' => 'points_type-points' ) |
|
185 | + , array('rank_group' => 'points_type-points') |
|
186 | 186 | , $feedback |
187 | 187 | ); |
188 | 188 | |
189 | - $this->assertFalse( $valid ); |
|
190 | - $this->assertEmpty( $feedback->messages ); |
|
189 | + $this->assertFalse($valid); |
|
190 | + $this->assertEmpty($feedback->messages); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 |
@@ -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' => gmdate( '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' => gmdate( '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' => gmdate( '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' => gmdate( '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' => gmdate( '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' => gmdate('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' => gmdate( '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' => gmdate('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 |
@@ -18,37 +18,37 @@ |
||
18 | 18 | * @coversNothing |
19 | 19 | */ |
20 | 20 | class WordPoints_CubePoints_Importer_Post_Publish_Hook_Test |
21 | - extends WordPoints_Importer_Hook_UnitTestCase { |
|
21 | + extends WordPoints_Importer_Hook_UnitTestCase { |
|
22 | 22 | |
23 | - /** |
|
24 | - * @since 1.2.0 |
|
25 | - */ |
|
26 | - protected $cubepoints_option = 'cp_post_points'; |
|
23 | + /** |
|
24 | + * @since 1.2.0 |
|
25 | + */ |
|
26 | + protected $cubepoints_option = 'cp_post_points'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @since 1.2.0 |
|
30 | - * |
|
31 | - * @dataProvider data_provider_types |
|
32 | - */ |
|
33 | - public function test( $type ) { |
|
28 | + /** |
|
29 | + * @since 1.2.0 |
|
30 | + * |
|
31 | + * @dataProvider data_provider_types |
|
32 | + */ |
|
33 | + public function test( $type ) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before( $type ); |
|
36 | 36 | |
37 | - $user_id = $this->factory->user->create(); |
|
38 | - $post_id = $this->factory->post->create( |
|
39 | - array( 'post_author' => $user_id, 'post_status' => 'publish' ) |
|
40 | - ); |
|
37 | + $user_id = $this->factory->user->create(); |
|
38 | + $post_id = $this->factory->post->create( |
|
39 | + array( 'post_author' => $user_id, 'post_status' => 'publish' ) |
|
40 | + ); |
|
41 | 41 | |
42 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
42 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
43 | 43 | |
44 | - wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); |
|
44 | + wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); |
|
45 | 45 | |
46 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
46 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
47 | 47 | |
48 | - wp_delete_post( $post_id, true ); |
|
48 | + wp_delete_post( $post_id, true ); |
|
49 | 49 | |
50 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
51 | - } |
|
50 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | // EOF |
@@ -30,24 +30,24 @@ |
||
30 | 30 | * |
31 | 31 | * @dataProvider data_provider_types |
32 | 32 | */ |
33 | - public function test( $type ) { |
|
33 | + public function test($type) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before($type); |
|
36 | 36 | |
37 | 37 | $user_id = $this->factory->user->create(); |
38 | 38 | $post_id = $this->factory->post->create( |
39 | - array( 'post_author' => $user_id, 'post_status' => 'publish' ) |
|
39 | + array('post_author' => $user_id, 'post_status' => 'publish') |
|
40 | 40 | ); |
41 | 41 | |
42 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
42 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
43 | 43 | |
44 | - wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); |
|
44 | + wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); |
|
45 | 45 | |
46 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
46 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
47 | 47 | |
48 | - wp_delete_post( $post_id, true ); |
|
48 | + wp_delete_post($post_id, true); |
|
49 | 49 | |
50 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
50 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 |
@@ -18,51 +18,51 @@ |
||
18 | 18 | * @coversNothing |
19 | 19 | */ |
20 | 20 | class WordPoints_CubePoints_Importer_Comment_Leave_Hook_Test |
21 | - extends WordPoints_Importer_Hook_UnitTestCase { |
|
21 | + extends WordPoints_Importer_Hook_UnitTestCase { |
|
22 | 22 | |
23 | - /** |
|
24 | - * @since 1.2.0 |
|
25 | - */ |
|
26 | - protected $cubepoints_option = 'cp_comment_points'; |
|
23 | + /** |
|
24 | + * @since 1.2.0 |
|
25 | + */ |
|
26 | + protected $cubepoints_option = 'cp_comment_points'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @since 1.2.0 |
|
30 | - * |
|
31 | - * @dataProvider data_provider_types |
|
32 | - */ |
|
33 | - public function test( $type ) { |
|
28 | + /** |
|
29 | + * @since 1.2.0 |
|
30 | + * |
|
31 | + * @dataProvider data_provider_types |
|
32 | + */ |
|
33 | + public function test( $type ) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before( $type ); |
|
36 | 36 | |
37 | - update_option( 'cp_del_comment_points', 10 ); |
|
37 | + update_option( 'cp_del_comment_points', 10 ); |
|
38 | 38 | |
39 | - $user_id = $this->factory->user->create(); |
|
40 | - $post_id = $this->factory->post->create( |
|
41 | - array( 'post_author' => $this->factory->user->create() ) |
|
42 | - ); |
|
39 | + $user_id = $this->factory->user->create(); |
|
40 | + $post_id = $this->factory->post->create( |
|
41 | + array( 'post_author' => $this->factory->user->create() ) |
|
42 | + ); |
|
43 | 43 | |
44 | - $comment_id = $this->factory->comment->create( |
|
45 | - array( |
|
46 | - 'comment_post_ID' => $post_id, |
|
47 | - 'comment_approved' => 0, |
|
48 | - 'user_id' => $user_id, |
|
49 | - ) |
|
50 | - ); |
|
44 | + $comment_id = $this->factory->comment->create( |
|
45 | + array( |
|
46 | + 'comment_post_ID' => $post_id, |
|
47 | + 'comment_approved' => 0, |
|
48 | + 'user_id' => $user_id, |
|
49 | + ) |
|
50 | + ); |
|
51 | 51 | |
52 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
52 | + $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
53 | 53 | |
54 | - wp_update_comment( |
|
55 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
56 | - ); |
|
54 | + wp_update_comment( |
|
55 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
56 | + ); |
|
57 | 57 | |
58 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
58 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
59 | 59 | |
60 | - wp_update_comment( |
|
61 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
62 | - ); |
|
60 | + wp_update_comment( |
|
61 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
62 | + ); |
|
63 | 63 | |
64 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
65 | - } |
|
64 | + $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // EOF |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @dataProvider data_provider_types |
32 | 32 | */ |
33 | - public function test( $type ) { |
|
33 | + public function test($type) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before($type); |
|
36 | 36 | |
37 | - update_option( 'cp_del_comment_points', 10 ); |
|
37 | + update_option('cp_del_comment_points', 10); |
|
38 | 38 | |
39 | 39 | $user_id = $this->factory->user->create(); |
40 | 40 | $post_id = $this->factory->post->create( |
41 | - array( 'post_author' => $this->factory->user->create() ) |
|
41 | + array('post_author' => $this->factory->user->create()) |
|
42 | 42 | ); |
43 | 43 | |
44 | 44 | $comment_id = $this->factory->comment->create( |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | |
52 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
52 | + $this->assertEquals(0, $this->get_user_points($user_id)); |
|
53 | 53 | |
54 | 54 | wp_update_comment( |
55 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
55 | + array('comment_ID' => $comment_id, 'comment_approved' => 1) |
|
56 | 56 | ); |
57 | 57 | |
58 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
58 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
59 | 59 | |
60 | 60 | wp_update_comment( |
61 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
61 | + array('comment_ID' => $comment_id, 'comment_approved' => 0) |
|
62 | 62 | ); |
63 | 63 | |
64 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
64 | + $this->assertEquals(0, $this->get_user_points($user_id)); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 |
@@ -18,53 +18,53 @@ |
||
18 | 18 | * @coversNothing |
19 | 19 | */ |
20 | 20 | class WordPoints_CubePoints_Importer_Comment_Receive_Hook_Test |
21 | - extends WordPoints_Importer_Hook_UnitTestCase { |
|
21 | + extends WordPoints_Importer_Hook_UnitTestCase { |
|
22 | 22 | |
23 | - /** |
|
24 | - * @since 1.2.0 |
|
25 | - */ |
|
26 | - protected $cubepoints_option = 'cp_post_author_points'; |
|
23 | + /** |
|
24 | + * @since 1.2.0 |
|
25 | + */ |
|
26 | + protected $cubepoints_option = 'cp_post_author_points'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @since 1.2.0 |
|
30 | - * |
|
31 | - * @dataProvider data_provider_types |
|
32 | - */ |
|
33 | - public function test( $type ) { |
|
28 | + /** |
|
29 | + * @since 1.2.0 |
|
30 | + * |
|
31 | + * @dataProvider data_provider_types |
|
32 | + */ |
|
33 | + public function test( $type ) { |
|
34 | 34 | |
35 | - cp_module_activation_set( 'post_author_points', 'active' ); |
|
35 | + cp_module_activation_set( 'post_author_points', 'active' ); |
|
36 | 36 | |
37 | - update_option( 'cp_post_points', 0 ); |
|
37 | + update_option( 'cp_post_points', 0 ); |
|
38 | 38 | |
39 | - $this->before( $type ); |
|
39 | + $this->before( $type ); |
|
40 | 40 | |
41 | - $user_id = $this->factory->user->create(); |
|
42 | - $post_id = $this->factory->post->create( |
|
43 | - array( 'post_author' => $user_id ) |
|
44 | - ); |
|
41 | + $user_id = $this->factory->user->create(); |
|
42 | + $post_id = $this->factory->post->create( |
|
43 | + array( 'post_author' => $user_id ) |
|
44 | + ); |
|
45 | 45 | |
46 | - $comment_id = $this->factory->comment->create( |
|
47 | - array( |
|
48 | - 'comment_post_ID' => $post_id, |
|
49 | - 'comment_approved' => 0, |
|
50 | - 'user_id' => $this->factory->user->create(), |
|
51 | - ) |
|
52 | - ); |
|
46 | + $comment_id = $this->factory->comment->create( |
|
47 | + array( |
|
48 | + 'comment_post_ID' => $post_id, |
|
49 | + 'comment_approved' => 0, |
|
50 | + 'user_id' => $this->factory->user->create(), |
|
51 | + ) |
|
52 | + ); |
|
53 | 53 | |
54 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
54 | + $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
55 | 55 | |
56 | - wp_update_comment( |
|
57 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
58 | - ); |
|
56 | + wp_update_comment( |
|
57 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
58 | + ); |
|
59 | 59 | |
60 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
60 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
61 | 61 | |
62 | - wp_update_comment( |
|
63 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
64 | - ); |
|
62 | + wp_update_comment( |
|
63 | + array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
64 | + ); |
|
65 | 65 | |
66 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
67 | - } |
|
66 | + $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // EOF |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @dataProvider data_provider_types |
32 | 32 | */ |
33 | - public function test( $type ) { |
|
33 | + public function test($type) { |
|
34 | 34 | |
35 | - cp_module_activation_set( 'post_author_points', 'active' ); |
|
35 | + cp_module_activation_set('post_author_points', 'active'); |
|
36 | 36 | |
37 | - update_option( 'cp_post_points', 0 ); |
|
37 | + update_option('cp_post_points', 0); |
|
38 | 38 | |
39 | - $this->before( $type ); |
|
39 | + $this->before($type); |
|
40 | 40 | |
41 | 41 | $user_id = $this->factory->user->create(); |
42 | 42 | $post_id = $this->factory->post->create( |
43 | - array( 'post_author' => $user_id ) |
|
43 | + array('post_author' => $user_id) |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | $comment_id = $this->factory->comment->create( |
@@ -51,19 +51,19 @@ discard block |
||
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
54 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
54 | + $this->assertEquals(0, $this->get_user_points($user_id)); |
|
55 | 55 | |
56 | 56 | wp_update_comment( |
57 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 1 ) |
|
57 | + array('comment_ID' => $comment_id, 'comment_approved' => 1) |
|
58 | 58 | ); |
59 | 59 | |
60 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
60 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
61 | 61 | |
62 | 62 | wp_update_comment( |
63 | - array( 'comment_ID' => $comment_id, 'comment_approved' => 0 ) |
|
63 | + array('comment_ID' => $comment_id, 'comment_approved' => 0) |
|
64 | 64 | ); |
65 | 65 | |
66 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
66 | + $this->assertEquals(0, $this->get_user_points($user_id)); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 |
@@ -18,30 +18,30 @@ |
||
18 | 18 | * @coversNothing |
19 | 19 | */ |
20 | 20 | class WordPoints_CubePoints_Importer_User_Register_Hook_Test |
21 | - extends WordPoints_Importer_Hook_UnitTestCase { |
|
21 | + extends WordPoints_Importer_Hook_UnitTestCase { |
|
22 | 22 | |
23 | - /** |
|
24 | - * @since 1.2.0 |
|
25 | - */ |
|
26 | - protected $cubepoints_option = 'cp_reg_points'; |
|
23 | + /** |
|
24 | + * @since 1.2.0 |
|
25 | + */ |
|
26 | + protected $cubepoints_option = 'cp_reg_points'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @since 1.2.0 |
|
30 | - * |
|
31 | - * @dataProvider data_provider_types |
|
32 | - */ |
|
33 | - public function test( $type ) { |
|
28 | + /** |
|
29 | + * @since 1.2.0 |
|
30 | + * |
|
31 | + * @dataProvider data_provider_types |
|
32 | + */ |
|
33 | + public function test( $type ) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before( $type ); |
|
36 | 36 | |
37 | - $user_id = $this->factory->user->create(); |
|
37 | + $user_id = $this->factory->user->create(); |
|
38 | 38 | |
39 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
39 | + $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
40 | 40 | |
41 | - self::delete_user( $user_id ); |
|
41 | + self::delete_user( $user_id ); |
|
42 | 42 | |
43 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
44 | - } |
|
43 | + $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | // EOF |
@@ -30,17 +30,17 @@ |
||
30 | 30 | * |
31 | 31 | * @dataProvider data_provider_types |
32 | 32 | */ |
33 | - public function test( $type ) { |
|
33 | + public function test($type) { |
|
34 | 34 | |
35 | - $this->before( $type ); |
|
35 | + $this->before($type); |
|
36 | 36 | |
37 | 37 | $user_id = $this->factory->user->create(); |
38 | 38 | |
39 | - $this->assertEquals( 10, $this->get_user_points( $user_id ) ); |
|
39 | + $this->assertEquals(10, $this->get_user_points($user_id)); |
|
40 | 40 | |
41 | - self::delete_user( $user_id ); |
|
41 | + self::delete_user($user_id); |
|
42 | 42 | |
43 | - $this->assertEquals( 0, $this->get_user_points( $user_id ) ); |
|
43 | + $this->assertEquals(0, $this->get_user_points($user_id)); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 |
@@ -16,295 +16,295 @@ |
||
16 | 16 | */ |
17 | 17 | class WordPoints_Importer_Importer_Test extends WordPoints_UnitTestCase { |
18 | 18 | |
19 | - /** |
|
20 | - * The mock importer used in the tests. |
|
21 | - * |
|
22 | - * @since 1.0.0 |
|
23 | - * |
|
24 | - * @var WordPoints_Importer_Mock |
|
25 | - */ |
|
26 | - protected $importer; |
|
27 | - |
|
28 | - /** |
|
29 | - * The components assigned to the mock importer. |
|
30 | - * |
|
31 | - * @since 1.0.0 |
|
32 | - * |
|
33 | - * @var array[] |
|
34 | - */ |
|
35 | - protected $importer_components; |
|
36 | - |
|
37 | - /** |
|
38 | - * @since 1.0.0 |
|
39 | - */ |
|
40 | - public function setUp() { |
|
41 | - |
|
42 | - parent::setUp(); |
|
43 | - |
|
44 | - $this->importer = new WordPoints_Importer_Mock( 'Mock' ); |
|
45 | - $this->importer->components = array( |
|
46 | - 'points' => array( |
|
47 | - 'user_points' => array( |
|
48 | - 'label' => 'User points', |
|
49 | - 'function' => array( $this->importer, 'do_an_import' ), |
|
50 | - 'can_import' => array( $this->importer, 'can_import' ), |
|
51 | - ), |
|
52 | - ), |
|
53 | - ); |
|
54 | - |
|
55 | - $this->importer_components = $this->importer->components; |
|
56 | - |
|
57 | - remove_action( |
|
58 | - 'wordpoints_import_settings_valid-points' |
|
59 | - , 'wordpoints_importer_validate_points_type_setting' |
|
60 | - ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Test that it returns true when a component is supported. |
|
65 | - * |
|
66 | - * @since 1.0.0 |
|
67 | - * |
|
68 | - * @covers WordPoints_Importer::supports_component |
|
69 | - */ |
|
70 | - public function test_supports_supported_component() { |
|
71 | - |
|
72 | - $this->assertTrue( $this->importer->supports_component( 'points' ) ); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Test that it returns false when a component isn't supported. |
|
77 | - * |
|
78 | - * @since 1.0.0 |
|
79 | - * |
|
80 | - * @covers WordPoints_Importer::supports_component |
|
81 | - */ |
|
82 | - public function test_supports_unsupported_component() { |
|
83 | - |
|
84 | - $this->assertFalse( $this->importer->supports_component( 'unsupported' ) ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Test that it returns the settings for a component. |
|
89 | - * |
|
90 | - * @since 1.0.0 |
|
91 | - * |
|
92 | - * @covers WordPoints_Importer::get_options_for_component |
|
93 | - */ |
|
94 | - public function test_get_options_for_component() { |
|
95 | - |
|
96 | - $this->assertEquals( |
|
97 | - $this->importer_components['points'] |
|
98 | - , $this->importer->get_options_for_component( 'points' ) |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Test that it returns the settings for an unsupported component. |
|
104 | - * |
|
105 | - * @since 1.0.0 |
|
106 | - * |
|
107 | - * @covers WordPoints_Importer::get_options_for_component |
|
108 | - */ |
|
109 | - public function test_get_options_for_unsupported_component() { |
|
110 | - |
|
111 | - $this->assertEquals( |
|
112 | - array() |
|
113 | - , $this->importer->get_options_for_component( 'unsupported' ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Test that it gives a warning for uninstalled components. |
|
119 | - * |
|
120 | - * @since 1.0.0 |
|
121 | - * |
|
122 | - * @covers WordPoints_Importer::do_import |
|
123 | - */ |
|
124 | - public function test_do_import_not_installed() { |
|
125 | - |
|
126 | - $this->importer->components = array( |
|
127 | - 'uninstalled' => array( 'method' => 'do_an_import' ), |
|
128 | - ); |
|
129 | - |
|
130 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
131 | - $this->importer->do_import( |
|
132 | - array( 'uninstalled' => array( 'do' => 'yes' ) ) |
|
133 | - , $feedback |
|
134 | - ); |
|
135 | - |
|
136 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
137 | - |
|
138 | - // The import shouldn't have been performed. |
|
139 | - $this->assertEmpty( $this->importer->imports ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Test that it gives a warning for unsupported components. |
|
144 | - * |
|
145 | - * @since 1.0.0 |
|
146 | - * |
|
147 | - * @covers WordPoints_Importer::do_import |
|
148 | - */ |
|
149 | - public function test_do_import_not_supported() { |
|
150 | - |
|
151 | - $this->importer->components = array(); |
|
152 | - |
|
153 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
154 | - $this->importer->do_import( |
|
155 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
156 | - , $feedback |
|
157 | - ); |
|
158 | - |
|
159 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
160 | - |
|
161 | - // The import shouldn't have been performed. |
|
162 | - $this->assertEmpty( $this->importer->imports ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Test that it skips a component if validation fails. |
|
167 | - * |
|
168 | - * @since 1.0.0 |
|
169 | - * |
|
170 | - * @covers WordPoints_Importer::do_import |
|
171 | - */ |
|
172 | - public function test_do_import_validates_settings() { |
|
173 | - |
|
174 | - $this->listen_for_filter( 'wordpoints_import_settings_valid-points' ); |
|
175 | - |
|
176 | - add_filter( 'wordpoints_import_settings_valid-points', '__return_false' ); |
|
177 | - |
|
178 | - $this->importer->do_import( |
|
179 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
180 | - , new WordPoints_Importer_Tests_Feedback() |
|
181 | - ); |
|
182 | - |
|
183 | - $this->assertEquals( |
|
184 | - 1 |
|
185 | - , $this->filter_was_called( 'wordpoints_import_settings_valid-points' ) |
|
186 | - ); |
|
187 | - |
|
188 | - // The import shouldn't have been performed. |
|
189 | - $this->assertEmpty( $this->importer->imports ); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Test that it skips an unsupported option. |
|
194 | - * |
|
195 | - * @since 1.0.0 |
|
196 | - * |
|
197 | - * @covers WordPoints_Importer::do_import |
|
198 | - */ |
|
199 | - public function test_do_import_invalid_option() { |
|
200 | - |
|
201 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
202 | - |
|
203 | - $this->importer->do_import( |
|
204 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
205 | - , $feedback |
|
206 | - ); |
|
207 | - |
|
208 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
209 | - |
|
210 | - // The import shouldn't have been performed. |
|
211 | - $this->assertEmpty( $this->importer->imports ); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Test that it skips a disabled option. |
|
216 | - * |
|
217 | - * @since 1.0.0 |
|
218 | - * |
|
219 | - * @covers WordPoints_Importer::do_import |
|
220 | - */ |
|
221 | - public function test_do_import_disabled_option() { |
|
222 | - |
|
223 | - $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
224 | - |
|
225 | - $this->importer->components['points']['user_points']['can_import'] = |
|
226 | - array( $this->importer, 'cant_import' ); |
|
227 | - |
|
228 | - $this->importer->do_import( |
|
229 | - array( 'points' => array( 'user_points' => '1' ) ) |
|
230 | - , $feedback |
|
231 | - ); |
|
232 | - |
|
233 | - $this->assertCount( 1, $this->importer->can_imports ); |
|
234 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
235 | - |
|
236 | - // The import shouldn't have been performed. |
|
237 | - $this->assertEmpty( $this->importer->imports ); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Test that the can_import function is passed any settings. |
|
242 | - * |
|
243 | - * @since 1.0.0 |
|
244 | - * |
|
245 | - * @covers WordPoints_Importer::do_import |
|
246 | - */ |
|
247 | - public function test_do_import_can_import_passed_settings() { |
|
248 | - |
|
249 | - $this->importer->do_import( |
|
250 | - array( |
|
251 | - 'points' => array( |
|
252 | - 'user_points' => '1', |
|
253 | - '_data' => array( 'testing' => 1 ), |
|
254 | - ), |
|
255 | - ) |
|
256 | - , new WordPoints_Importer_Tests_Feedback() |
|
257 | - ); |
|
258 | - |
|
259 | - $this->assertCount( 1, $this->importer->can_imports ); |
|
260 | - $this->assertEquals( |
|
261 | - array( 'testing' => 1 ) |
|
262 | - , $this->importer->can_imports[0] |
|
263 | - ); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Test that it calls the importer function. |
|
268 | - * |
|
269 | - * @since 1.0.0 |
|
270 | - * |
|
271 | - * @covers WordPoints_Importer::do_import |
|
272 | - */ |
|
273 | - public function test_do_import() { |
|
274 | - |
|
275 | - $this->importer->do_import( |
|
276 | - array( 'points' => array( 'user_points' => '1' ) ) |
|
277 | - , new WordPoints_Importer_Tests_Feedback() |
|
278 | - ); |
|
279 | - |
|
280 | - $this->assertCount( 1, $this->importer->imports ); |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Test that the import function is passed any settings. |
|
285 | - * |
|
286 | - * @since 1.0.0 |
|
287 | - * |
|
288 | - * @covers WordPoints_Importer::do_import |
|
289 | - */ |
|
290 | - public function test_do_import_passed_settings() { |
|
291 | - |
|
292 | - $this->importer->do_import( |
|
293 | - array( |
|
294 | - 'points' => array( |
|
295 | - 'user_points' => '1', |
|
296 | - '_data' => array( 'testing' => 1 ), |
|
297 | - ), |
|
298 | - ) |
|
299 | - , new WordPoints_Importer_Tests_Feedback() |
|
300 | - ); |
|
301 | - |
|
302 | - $this->assertCount( 1, $this->importer->imports ); |
|
303 | - $this->assertEquals( |
|
304 | - array( 'testing' => 1 ) |
|
305 | - , $this->importer->imports[0] |
|
306 | - ); |
|
307 | - } |
|
19 | + /** |
|
20 | + * The mock importer used in the tests. |
|
21 | + * |
|
22 | + * @since 1.0.0 |
|
23 | + * |
|
24 | + * @var WordPoints_Importer_Mock |
|
25 | + */ |
|
26 | + protected $importer; |
|
27 | + |
|
28 | + /** |
|
29 | + * The components assigned to the mock importer. |
|
30 | + * |
|
31 | + * @since 1.0.0 |
|
32 | + * |
|
33 | + * @var array[] |
|
34 | + */ |
|
35 | + protected $importer_components; |
|
36 | + |
|
37 | + /** |
|
38 | + * @since 1.0.0 |
|
39 | + */ |
|
40 | + public function setUp() { |
|
41 | + |
|
42 | + parent::setUp(); |
|
43 | + |
|
44 | + $this->importer = new WordPoints_Importer_Mock( 'Mock' ); |
|
45 | + $this->importer->components = array( |
|
46 | + 'points' => array( |
|
47 | + 'user_points' => array( |
|
48 | + 'label' => 'User points', |
|
49 | + 'function' => array( $this->importer, 'do_an_import' ), |
|
50 | + 'can_import' => array( $this->importer, 'can_import' ), |
|
51 | + ), |
|
52 | + ), |
|
53 | + ); |
|
54 | + |
|
55 | + $this->importer_components = $this->importer->components; |
|
56 | + |
|
57 | + remove_action( |
|
58 | + 'wordpoints_import_settings_valid-points' |
|
59 | + , 'wordpoints_importer_validate_points_type_setting' |
|
60 | + ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Test that it returns true when a component is supported. |
|
65 | + * |
|
66 | + * @since 1.0.0 |
|
67 | + * |
|
68 | + * @covers WordPoints_Importer::supports_component |
|
69 | + */ |
|
70 | + public function test_supports_supported_component() { |
|
71 | + |
|
72 | + $this->assertTrue( $this->importer->supports_component( 'points' ) ); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Test that it returns false when a component isn't supported. |
|
77 | + * |
|
78 | + * @since 1.0.0 |
|
79 | + * |
|
80 | + * @covers WordPoints_Importer::supports_component |
|
81 | + */ |
|
82 | + public function test_supports_unsupported_component() { |
|
83 | + |
|
84 | + $this->assertFalse( $this->importer->supports_component( 'unsupported' ) ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Test that it returns the settings for a component. |
|
89 | + * |
|
90 | + * @since 1.0.0 |
|
91 | + * |
|
92 | + * @covers WordPoints_Importer::get_options_for_component |
|
93 | + */ |
|
94 | + public function test_get_options_for_component() { |
|
95 | + |
|
96 | + $this->assertEquals( |
|
97 | + $this->importer_components['points'] |
|
98 | + , $this->importer->get_options_for_component( 'points' ) |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Test that it returns the settings for an unsupported component. |
|
104 | + * |
|
105 | + * @since 1.0.0 |
|
106 | + * |
|
107 | + * @covers WordPoints_Importer::get_options_for_component |
|
108 | + */ |
|
109 | + public function test_get_options_for_unsupported_component() { |
|
110 | + |
|
111 | + $this->assertEquals( |
|
112 | + array() |
|
113 | + , $this->importer->get_options_for_component( 'unsupported' ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Test that it gives a warning for uninstalled components. |
|
119 | + * |
|
120 | + * @since 1.0.0 |
|
121 | + * |
|
122 | + * @covers WordPoints_Importer::do_import |
|
123 | + */ |
|
124 | + public function test_do_import_not_installed() { |
|
125 | + |
|
126 | + $this->importer->components = array( |
|
127 | + 'uninstalled' => array( 'method' => 'do_an_import' ), |
|
128 | + ); |
|
129 | + |
|
130 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
131 | + $this->importer->do_import( |
|
132 | + array( 'uninstalled' => array( 'do' => 'yes' ) ) |
|
133 | + , $feedback |
|
134 | + ); |
|
135 | + |
|
136 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
137 | + |
|
138 | + // The import shouldn't have been performed. |
|
139 | + $this->assertEmpty( $this->importer->imports ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Test that it gives a warning for unsupported components. |
|
144 | + * |
|
145 | + * @since 1.0.0 |
|
146 | + * |
|
147 | + * @covers WordPoints_Importer::do_import |
|
148 | + */ |
|
149 | + public function test_do_import_not_supported() { |
|
150 | + |
|
151 | + $this->importer->components = array(); |
|
152 | + |
|
153 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
154 | + $this->importer->do_import( |
|
155 | + array( 'points' => array( 'do' => 'yes' ) ) |
|
156 | + , $feedback |
|
157 | + ); |
|
158 | + |
|
159 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
160 | + |
|
161 | + // The import shouldn't have been performed. |
|
162 | + $this->assertEmpty( $this->importer->imports ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Test that it skips a component if validation fails. |
|
167 | + * |
|
168 | + * @since 1.0.0 |
|
169 | + * |
|
170 | + * @covers WordPoints_Importer::do_import |
|
171 | + */ |
|
172 | + public function test_do_import_validates_settings() { |
|
173 | + |
|
174 | + $this->listen_for_filter( 'wordpoints_import_settings_valid-points' ); |
|
175 | + |
|
176 | + add_filter( 'wordpoints_import_settings_valid-points', '__return_false' ); |
|
177 | + |
|
178 | + $this->importer->do_import( |
|
179 | + array( 'points' => array( 'do' => 'yes' ) ) |
|
180 | + , new WordPoints_Importer_Tests_Feedback() |
|
181 | + ); |
|
182 | + |
|
183 | + $this->assertEquals( |
|
184 | + 1 |
|
185 | + , $this->filter_was_called( 'wordpoints_import_settings_valid-points' ) |
|
186 | + ); |
|
187 | + |
|
188 | + // The import shouldn't have been performed. |
|
189 | + $this->assertEmpty( $this->importer->imports ); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Test that it skips an unsupported option. |
|
194 | + * |
|
195 | + * @since 1.0.0 |
|
196 | + * |
|
197 | + * @covers WordPoints_Importer::do_import |
|
198 | + */ |
|
199 | + public function test_do_import_invalid_option() { |
|
200 | + |
|
201 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
202 | + |
|
203 | + $this->importer->do_import( |
|
204 | + array( 'points' => array( 'do' => 'yes' ) ) |
|
205 | + , $feedback |
|
206 | + ); |
|
207 | + |
|
208 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
209 | + |
|
210 | + // The import shouldn't have been performed. |
|
211 | + $this->assertEmpty( $this->importer->imports ); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Test that it skips a disabled option. |
|
216 | + * |
|
217 | + * @since 1.0.0 |
|
218 | + * |
|
219 | + * @covers WordPoints_Importer::do_import |
|
220 | + */ |
|
221 | + public function test_do_import_disabled_option() { |
|
222 | + |
|
223 | + $feedback = new WordPoints_Importer_Tests_Feedback(); |
|
224 | + |
|
225 | + $this->importer->components['points']['user_points']['can_import'] = |
|
226 | + array( $this->importer, 'cant_import' ); |
|
227 | + |
|
228 | + $this->importer->do_import( |
|
229 | + array( 'points' => array( 'user_points' => '1' ) ) |
|
230 | + , $feedback |
|
231 | + ); |
|
232 | + |
|
233 | + $this->assertCount( 1, $this->importer->can_imports ); |
|
234 | + $this->assertCount( 1, $feedback->messages['warning'] ); |
|
235 | + |
|
236 | + // The import shouldn't have been performed. |
|
237 | + $this->assertEmpty( $this->importer->imports ); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Test that the can_import function is passed any settings. |
|
242 | + * |
|
243 | + * @since 1.0.0 |
|
244 | + * |
|
245 | + * @covers WordPoints_Importer::do_import |
|
246 | + */ |
|
247 | + public function test_do_import_can_import_passed_settings() { |
|
248 | + |
|
249 | + $this->importer->do_import( |
|
250 | + array( |
|
251 | + 'points' => array( |
|
252 | + 'user_points' => '1', |
|
253 | + '_data' => array( 'testing' => 1 ), |
|
254 | + ), |
|
255 | + ) |
|
256 | + , new WordPoints_Importer_Tests_Feedback() |
|
257 | + ); |
|
258 | + |
|
259 | + $this->assertCount( 1, $this->importer->can_imports ); |
|
260 | + $this->assertEquals( |
|
261 | + array( 'testing' => 1 ) |
|
262 | + , $this->importer->can_imports[0] |
|
263 | + ); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Test that it calls the importer function. |
|
268 | + * |
|
269 | + * @since 1.0.0 |
|
270 | + * |
|
271 | + * @covers WordPoints_Importer::do_import |
|
272 | + */ |
|
273 | + public function test_do_import() { |
|
274 | + |
|
275 | + $this->importer->do_import( |
|
276 | + array( 'points' => array( 'user_points' => '1' ) ) |
|
277 | + , new WordPoints_Importer_Tests_Feedback() |
|
278 | + ); |
|
279 | + |
|
280 | + $this->assertCount( 1, $this->importer->imports ); |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Test that the import function is passed any settings. |
|
285 | + * |
|
286 | + * @since 1.0.0 |
|
287 | + * |
|
288 | + * @covers WordPoints_Importer::do_import |
|
289 | + */ |
|
290 | + public function test_do_import_passed_settings() { |
|
291 | + |
|
292 | + $this->importer->do_import( |
|
293 | + array( |
|
294 | + 'points' => array( |
|
295 | + 'user_points' => '1', |
|
296 | + '_data' => array( 'testing' => 1 ), |
|
297 | + ), |
|
298 | + ) |
|
299 | + , new WordPoints_Importer_Tests_Feedback() |
|
300 | + ); |
|
301 | + |
|
302 | + $this->assertCount( 1, $this->importer->imports ); |
|
303 | + $this->assertEquals( |
|
304 | + array( 'testing' => 1 ) |
|
305 | + , $this->importer->imports[0] |
|
306 | + ); |
|
307 | + } |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // EOF |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | |
42 | 42 | parent::setUp(); |
43 | 43 | |
44 | - $this->importer = new WordPoints_Importer_Mock( 'Mock' ); |
|
44 | + $this->importer = new WordPoints_Importer_Mock('Mock'); |
|
45 | 45 | $this->importer->components = array( |
46 | 46 | 'points' => array( |
47 | 47 | 'user_points' => array( |
48 | 48 | 'label' => 'User points', |
49 | - 'function' => array( $this->importer, 'do_an_import' ), |
|
50 | - 'can_import' => array( $this->importer, 'can_import' ), |
|
49 | + 'function' => array($this->importer, 'do_an_import'), |
|
50 | + 'can_import' => array($this->importer, 'can_import'), |
|
51 | 51 | ), |
52 | 52 | ), |
53 | 53 | ); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function test_supports_supported_component() { |
71 | 71 | |
72 | - $this->assertTrue( $this->importer->supports_component( 'points' ) ); |
|
72 | + $this->assertTrue($this->importer->supports_component('points')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function test_supports_unsupported_component() { |
83 | 83 | |
84 | - $this->assertFalse( $this->importer->supports_component( 'unsupported' ) ); |
|
84 | + $this->assertFalse($this->importer->supports_component('unsupported')); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | $this->assertEquals( |
97 | 97 | $this->importer_components['points'] |
98 | - , $this->importer->get_options_for_component( 'points' ) |
|
98 | + , $this->importer->get_options_for_component('points') |
|
99 | 99 | ); |
100 | 100 | } |
101 | 101 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $this->assertEquals( |
112 | 112 | array() |
113 | - , $this->importer->get_options_for_component( 'unsupported' ) |
|
113 | + , $this->importer->get_options_for_component('unsupported') |
|
114 | 114 | ); |
115 | 115 | } |
116 | 116 | |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | public function test_do_import_not_installed() { |
125 | 125 | |
126 | 126 | $this->importer->components = array( |
127 | - 'uninstalled' => array( 'method' => 'do_an_import' ), |
|
127 | + 'uninstalled' => array('method' => 'do_an_import'), |
|
128 | 128 | ); |
129 | 129 | |
130 | 130 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
131 | 131 | $this->importer->do_import( |
132 | - array( 'uninstalled' => array( 'do' => 'yes' ) ) |
|
132 | + array('uninstalled' => array('do' => 'yes')) |
|
133 | 133 | , $feedback |
134 | 134 | ); |
135 | 135 | |
136 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
136 | + $this->assertCount(1, $feedback->messages['warning']); |
|
137 | 137 | |
138 | 138 | // The import shouldn't have been performed. |
139 | - $this->assertEmpty( $this->importer->imports ); |
|
139 | + $this->assertEmpty($this->importer->imports); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -152,14 +152,14 @@ discard block |
||
152 | 152 | |
153 | 153 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
154 | 154 | $this->importer->do_import( |
155 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
155 | + array('points' => array('do' => 'yes')) |
|
156 | 156 | , $feedback |
157 | 157 | ); |
158 | 158 | |
159 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
159 | + $this->assertCount(1, $feedback->messages['warning']); |
|
160 | 160 | |
161 | 161 | // The import shouldn't have been performed. |
162 | - $this->assertEmpty( $this->importer->imports ); |
|
162 | + $this->assertEmpty($this->importer->imports); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -171,22 +171,22 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function test_do_import_validates_settings() { |
173 | 173 | |
174 | - $this->listen_for_filter( 'wordpoints_import_settings_valid-points' ); |
|
174 | + $this->listen_for_filter('wordpoints_import_settings_valid-points'); |
|
175 | 175 | |
176 | - add_filter( 'wordpoints_import_settings_valid-points', '__return_false' ); |
|
176 | + add_filter('wordpoints_import_settings_valid-points', '__return_false'); |
|
177 | 177 | |
178 | 178 | $this->importer->do_import( |
179 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
179 | + array('points' => array('do' => 'yes')) |
|
180 | 180 | , new WordPoints_Importer_Tests_Feedback() |
181 | 181 | ); |
182 | 182 | |
183 | 183 | $this->assertEquals( |
184 | 184 | 1 |
185 | - , $this->filter_was_called( 'wordpoints_import_settings_valid-points' ) |
|
185 | + , $this->filter_was_called('wordpoints_import_settings_valid-points') |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | // The import shouldn't have been performed. |
189 | - $this->assertEmpty( $this->importer->imports ); |
|
189 | + $this->assertEmpty($this->importer->imports); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
202 | 202 | |
203 | 203 | $this->importer->do_import( |
204 | - array( 'points' => array( 'do' => 'yes' ) ) |
|
204 | + array('points' => array('do' => 'yes')) |
|
205 | 205 | , $feedback |
206 | 206 | ); |
207 | 207 | |
208 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
208 | + $this->assertCount(1, $feedback->messages['warning']); |
|
209 | 209 | |
210 | 210 | // The import shouldn't have been performed. |
211 | - $this->assertEmpty( $this->importer->imports ); |
|
211 | + $this->assertEmpty($this->importer->imports); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -223,18 +223,18 @@ discard block |
||
223 | 223 | $feedback = new WordPoints_Importer_Tests_Feedback(); |
224 | 224 | |
225 | 225 | $this->importer->components['points']['user_points']['can_import'] = |
226 | - array( $this->importer, 'cant_import' ); |
|
226 | + array($this->importer, 'cant_import'); |
|
227 | 227 | |
228 | 228 | $this->importer->do_import( |
229 | - array( 'points' => array( 'user_points' => '1' ) ) |
|
229 | + array('points' => array('user_points' => '1')) |
|
230 | 230 | , $feedback |
231 | 231 | ); |
232 | 232 | |
233 | - $this->assertCount( 1, $this->importer->can_imports ); |
|
234 | - $this->assertCount( 1, $feedback->messages['warning'] ); |
|
233 | + $this->assertCount(1, $this->importer->can_imports); |
|
234 | + $this->assertCount(1, $feedback->messages['warning']); |
|
235 | 235 | |
236 | 236 | // The import shouldn't have been performed. |
237 | - $this->assertEmpty( $this->importer->imports ); |
|
237 | + $this->assertEmpty($this->importer->imports); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | array( |
251 | 251 | 'points' => array( |
252 | 252 | 'user_points' => '1', |
253 | - '_data' => array( 'testing' => 1 ), |
|
253 | + '_data' => array('testing' => 1), |
|
254 | 254 | ), |
255 | 255 | ) |
256 | 256 | , new WordPoints_Importer_Tests_Feedback() |
257 | 257 | ); |
258 | 258 | |
259 | - $this->assertCount( 1, $this->importer->can_imports ); |
|
259 | + $this->assertCount(1, $this->importer->can_imports); |
|
260 | 260 | $this->assertEquals( |
261 | - array( 'testing' => 1 ) |
|
261 | + array('testing' => 1) |
|
262 | 262 | , $this->importer->can_imports[0] |
263 | 263 | ); |
264 | 264 | } |
@@ -273,11 +273,11 @@ discard block |
||
273 | 273 | public function test_do_import() { |
274 | 274 | |
275 | 275 | $this->importer->do_import( |
276 | - array( 'points' => array( 'user_points' => '1' ) ) |
|
276 | + array('points' => array('user_points' => '1')) |
|
277 | 277 | , new WordPoints_Importer_Tests_Feedback() |
278 | 278 | ); |
279 | 279 | |
280 | - $this->assertCount( 1, $this->importer->imports ); |
|
280 | + $this->assertCount(1, $this->importer->imports); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | array( |
294 | 294 | 'points' => array( |
295 | 295 | 'user_points' => '1', |
296 | - '_data' => array( 'testing' => 1 ), |
|
296 | + '_data' => array('testing' => 1), |
|
297 | 297 | ), |
298 | 298 | ) |
299 | 299 | , new WordPoints_Importer_Tests_Feedback() |
300 | 300 | ); |
301 | 301 | |
302 | - $this->assertCount( 1, $this->importer->imports ); |
|
302 | + $this->assertCount(1, $this->importer->imports); |
|
303 | 303 | $this->assertEquals( |
304 | - array( 'testing' => 1 ) |
|
304 | + array('testing' => 1) |
|
305 | 305 | , $this->importer->imports[0] |
306 | 306 | ); |
307 | 307 | } |
@@ -16,149 +16,149 @@ |
||
16 | 16 | */ |
17 | 17 | class WordPoints_Importers_Test extends WP_UnitTestCase { |
18 | 18 | |
19 | - /** |
|
20 | - * Backup of the importers when the test begins. |
|
21 | - * |
|
22 | - * @since 1.0.0 |
|
23 | - * |
|
24 | - * @var array[] |
|
25 | - */ |
|
26 | - protected $_backup_importers; |
|
27 | - |
|
28 | - /** |
|
29 | - * @since 1.0.0 |
|
30 | - */ |
|
31 | - public function setUp() { |
|
32 | - |
|
33 | - parent::setUp(); |
|
34 | - |
|
35 | - $this->_backup_importers = WordPoints_Importers::get(); |
|
36 | - |
|
37 | - WordPoints_Importers::register( |
|
38 | - 'test' |
|
39 | - , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
40 | - ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @since 1.0.0 |
|
46 | - */ |
|
47 | - public function tearDown() { |
|
48 | - |
|
49 | - $importers = WordPoints_Importers::get(); |
|
50 | - |
|
51 | - foreach ( $this->_backup_importers as $slug => $args ) { |
|
52 | - |
|
53 | - if ( ! isset( $importers[ $slug ] ) ) { |
|
54 | - WordPoints_Importers::register( $slug, $args ); |
|
55 | - } |
|
56 | - |
|
57 | - unset( $importers[ $slug ] ); |
|
58 | - } |
|
59 | - |
|
60 | - foreach ( $importers as $slug => $args ) { |
|
61 | - WordPoints_Importers::deregister( $slug ); |
|
62 | - } |
|
63 | - |
|
64 | - parent::tearDown(); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Test registration. |
|
69 | - * |
|
70 | - * @since 1.0.0 |
|
71 | - * |
|
72 | - * @covers WordPoints_Importers::register |
|
73 | - * @covers WordPoints_Importers::get |
|
74 | - */ |
|
75 | - public function test_register() { |
|
76 | - |
|
77 | - WordPoints_Importers::register( |
|
78 | - __METHOD__ |
|
79 | - , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
80 | - ); |
|
81 | - |
|
82 | - $importers = WordPoints_Importers::get(); |
|
83 | - |
|
84 | - $this->assertArrayHasKey( 'test', $importers ); |
|
85 | - $this->assertEquals( |
|
86 | - array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
87 | - , $importers['test'] |
|
88 | - ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Test that deregister() deregisters the importer. |
|
93 | - * |
|
94 | - * @since 1.0.0 |
|
95 | - * |
|
96 | - * @covers WordPoints_Importers::register |
|
97 | - * @covers WordPoints_Importers::get |
|
98 | - */ |
|
99 | - public function test_deregister() { |
|
100 | - |
|
101 | - WordPoints_Importers::deregister( 'test' ); |
|
102 | - |
|
103 | - $importers = WordPoints_Importers::get(); |
|
104 | - |
|
105 | - $this->assertArrayNotHasKey( 'test', $importers ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Test that is_registered() returns true for a registered importer. |
|
110 | - * |
|
111 | - * @since 1.0.0 |
|
112 | - * |
|
113 | - * @covers WordPoints_Importers::is_registered |
|
114 | - */ |
|
115 | - public function test_is_registered() { |
|
116 | - |
|
117 | - $this->assertTrue( WordPoints_Importers::is_registered( 'test' ) ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Test that is_registered() returns false for an unregistered importer. |
|
122 | - * |
|
123 | - * @since 1.0.0 |
|
124 | - * |
|
125 | - * @covers WordPoints_Importers::is_registered |
|
126 | - */ |
|
127 | - public function test_is_registered_unregistered() { |
|
128 | - |
|
129 | - WordPoints_Importers::deregister( 'test' ); |
|
130 | - |
|
131 | - $this->assertFalse( WordPoints_Importers::is_registered( 'test' ) ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Test that get_importer() returns false for an unregistered importer. |
|
136 | - * |
|
137 | - * @since 1.0.0 |
|
138 | - * |
|
139 | - * @covers WordPoints_Importers::get_importer |
|
140 | - */ |
|
141 | - public function test_get_unregistered_importer() { |
|
142 | - |
|
143 | - WordPoints_Importers::deregister( 'test' ); |
|
144 | - |
|
145 | - $this->assertFalse( WordPoints_Importers::get_importer( 'test' ) ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Test that get_importer() returns an importer object. |
|
150 | - * |
|
151 | - * @since 1.0.0 |
|
152 | - * |
|
153 | - * @covers WordPoints_Importers::get_importer |
|
154 | - */ |
|
155 | - public function test_get_importer() { |
|
156 | - |
|
157 | - $this->assertInstanceOf( |
|
158 | - 'WordPoints_Importer_Mock' |
|
159 | - , WordPoints_Importers::get_importer( 'test' ) |
|
160 | - ); |
|
161 | - } |
|
19 | + /** |
|
20 | + * Backup of the importers when the test begins. |
|
21 | + * |
|
22 | + * @since 1.0.0 |
|
23 | + * |
|
24 | + * @var array[] |
|
25 | + */ |
|
26 | + protected $_backup_importers; |
|
27 | + |
|
28 | + /** |
|
29 | + * @since 1.0.0 |
|
30 | + */ |
|
31 | + public function setUp() { |
|
32 | + |
|
33 | + parent::setUp(); |
|
34 | + |
|
35 | + $this->_backup_importers = WordPoints_Importers::get(); |
|
36 | + |
|
37 | + WordPoints_Importers::register( |
|
38 | + 'test' |
|
39 | + , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
40 | + ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @since 1.0.0 |
|
46 | + */ |
|
47 | + public function tearDown() { |
|
48 | + |
|
49 | + $importers = WordPoints_Importers::get(); |
|
50 | + |
|
51 | + foreach ( $this->_backup_importers as $slug => $args ) { |
|
52 | + |
|
53 | + if ( ! isset( $importers[ $slug ] ) ) { |
|
54 | + WordPoints_Importers::register( $slug, $args ); |
|
55 | + } |
|
56 | + |
|
57 | + unset( $importers[ $slug ] ); |
|
58 | + } |
|
59 | + |
|
60 | + foreach ( $importers as $slug => $args ) { |
|
61 | + WordPoints_Importers::deregister( $slug ); |
|
62 | + } |
|
63 | + |
|
64 | + parent::tearDown(); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Test registration. |
|
69 | + * |
|
70 | + * @since 1.0.0 |
|
71 | + * |
|
72 | + * @covers WordPoints_Importers::register |
|
73 | + * @covers WordPoints_Importers::get |
|
74 | + */ |
|
75 | + public function test_register() { |
|
76 | + |
|
77 | + WordPoints_Importers::register( |
|
78 | + __METHOD__ |
|
79 | + , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
80 | + ); |
|
81 | + |
|
82 | + $importers = WordPoints_Importers::get(); |
|
83 | + |
|
84 | + $this->assertArrayHasKey( 'test', $importers ); |
|
85 | + $this->assertEquals( |
|
86 | + array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
87 | + , $importers['test'] |
|
88 | + ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Test that deregister() deregisters the importer. |
|
93 | + * |
|
94 | + * @since 1.0.0 |
|
95 | + * |
|
96 | + * @covers WordPoints_Importers::register |
|
97 | + * @covers WordPoints_Importers::get |
|
98 | + */ |
|
99 | + public function test_deregister() { |
|
100 | + |
|
101 | + WordPoints_Importers::deregister( 'test' ); |
|
102 | + |
|
103 | + $importers = WordPoints_Importers::get(); |
|
104 | + |
|
105 | + $this->assertArrayNotHasKey( 'test', $importers ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Test that is_registered() returns true for a registered importer. |
|
110 | + * |
|
111 | + * @since 1.0.0 |
|
112 | + * |
|
113 | + * @covers WordPoints_Importers::is_registered |
|
114 | + */ |
|
115 | + public function test_is_registered() { |
|
116 | + |
|
117 | + $this->assertTrue( WordPoints_Importers::is_registered( 'test' ) ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Test that is_registered() returns false for an unregistered importer. |
|
122 | + * |
|
123 | + * @since 1.0.0 |
|
124 | + * |
|
125 | + * @covers WordPoints_Importers::is_registered |
|
126 | + */ |
|
127 | + public function test_is_registered_unregistered() { |
|
128 | + |
|
129 | + WordPoints_Importers::deregister( 'test' ); |
|
130 | + |
|
131 | + $this->assertFalse( WordPoints_Importers::is_registered( 'test' ) ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Test that get_importer() returns false for an unregistered importer. |
|
136 | + * |
|
137 | + * @since 1.0.0 |
|
138 | + * |
|
139 | + * @covers WordPoints_Importers::get_importer |
|
140 | + */ |
|
141 | + public function test_get_unregistered_importer() { |
|
142 | + |
|
143 | + WordPoints_Importers::deregister( 'test' ); |
|
144 | + |
|
145 | + $this->assertFalse( WordPoints_Importers::get_importer( 'test' ) ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Test that get_importer() returns an importer object. |
|
150 | + * |
|
151 | + * @since 1.0.0 |
|
152 | + * |
|
153 | + * @covers WordPoints_Importers::get_importer |
|
154 | + */ |
|
155 | + public function test_get_importer() { |
|
156 | + |
|
157 | + $this->assertInstanceOf( |
|
158 | + 'WordPoints_Importer_Mock' |
|
159 | + , WordPoints_Importers::get_importer( 'test' ) |
|
160 | + ); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | } |
164 | 164 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | WordPoints_Importers::register( |
38 | 38 | 'test' |
39 | - , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
39 | + , array('class' => 'WordPoints_Importer_Mock', 'name' => 'Test') |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | } |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | |
49 | 49 | $importers = WordPoints_Importers::get(); |
50 | 50 | |
51 | - foreach ( $this->_backup_importers as $slug => $args ) { |
|
51 | + foreach ($this->_backup_importers as $slug => $args) { |
|
52 | 52 | |
53 | - if ( ! isset( $importers[ $slug ] ) ) { |
|
54 | - WordPoints_Importers::register( $slug, $args ); |
|
53 | + if (!isset($importers[$slug])) { |
|
54 | + WordPoints_Importers::register($slug, $args); |
|
55 | 55 | } |
56 | 56 | |
57 | - unset( $importers[ $slug ] ); |
|
57 | + unset($importers[$slug]); |
|
58 | 58 | } |
59 | 59 | |
60 | - foreach ( $importers as $slug => $args ) { |
|
61 | - WordPoints_Importers::deregister( $slug ); |
|
60 | + foreach ($importers as $slug => $args) { |
|
61 | + WordPoints_Importers::deregister($slug); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | parent::tearDown(); |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | |
77 | 77 | WordPoints_Importers::register( |
78 | 78 | __METHOD__ |
79 | - , array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
79 | + , array('class' => 'WordPoints_Importer_Mock', 'name' => 'Test') |
|
80 | 80 | ); |
81 | 81 | |
82 | 82 | $importers = WordPoints_Importers::get(); |
83 | 83 | |
84 | - $this->assertArrayHasKey( 'test', $importers ); |
|
84 | + $this->assertArrayHasKey('test', $importers); |
|
85 | 85 | $this->assertEquals( |
86 | - array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' ) |
|
86 | + array('class' => 'WordPoints_Importer_Mock', 'name' => 'Test') |
|
87 | 87 | , $importers['test'] |
88 | 88 | ); |
89 | 89 | } |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function test_deregister() { |
100 | 100 | |
101 | - WordPoints_Importers::deregister( 'test' ); |
|
101 | + WordPoints_Importers::deregister('test'); |
|
102 | 102 | |
103 | 103 | $importers = WordPoints_Importers::get(); |
104 | 104 | |
105 | - $this->assertArrayNotHasKey( 'test', $importers ); |
|
105 | + $this->assertArrayNotHasKey('test', $importers); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function test_is_registered() { |
116 | 116 | |
117 | - $this->assertTrue( WordPoints_Importers::is_registered( 'test' ) ); |
|
117 | + $this->assertTrue(WordPoints_Importers::is_registered('test')); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function test_is_registered_unregistered() { |
128 | 128 | |
129 | - WordPoints_Importers::deregister( 'test' ); |
|
129 | + WordPoints_Importers::deregister('test'); |
|
130 | 130 | |
131 | - $this->assertFalse( WordPoints_Importers::is_registered( 'test' ) ); |
|
131 | + $this->assertFalse(WordPoints_Importers::is_registered('test')); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function test_get_unregistered_importer() { |
142 | 142 | |
143 | - WordPoints_Importers::deregister( 'test' ); |
|
143 | + WordPoints_Importers::deregister('test'); |
|
144 | 144 | |
145 | - $this->assertFalse( WordPoints_Importers::get_importer( 'test' ) ); |
|
145 | + $this->assertFalse(WordPoints_Importers::get_importer('test')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $this->assertInstanceOf( |
158 | 158 | 'WordPoints_Importer_Mock' |
159 | - , WordPoints_Importers::get_importer( 'test' ) |
|
159 | + , WordPoints_Importers::get_importer('test') |
|
160 | 160 | ); |
161 | 161 | } |
162 | 162 |