Completed
Push — master ( 207dd4...0cb291 )
by J.D.
13s
created
src/includes/importers/cubepoints.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -65,6 +65,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +668 added lines, -668 removed lines patch added patch discarded remove patch
@@ -14,702 +14,702 @@
 block discarded – undo
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 Reactions', '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 reactions…', '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
-		} // End foreach ( $options ).
286
-
287
-		if ( $this->import_daily_points_hook( $settings ) ) {
288
-			$imported++;
289
-		}
290
-
291
-		$this->feedback->success(
292
-			sprintf( __( 'Imported %s points reactions.', 'wordpoints-importer' ), $imported )
293
-		);
294
-	}
295
-
296
-	/**
297
-	 * Import the settings for the Daily Points module to a points hook.
298
-	 *
299
-	 * @since 1.1.0
300
-	 *
301
-	 * @param array $settings The settings for the points component import.
302
-	 *
303
-	 * @return bool True if the settings were imported, false otherwise.
304
-	 */
305
-	protected function import_daily_points_hook( $settings ) {
306
-
307
-		// Don't import this module setting if the module isn't active.
308
-		if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) {
309
-			return false;
310
-		}
311
-
312
-		$points = get_option( 'cp_module_dailypoints_points' );
313
-		$period = get_option( 'cp_module_dailypoints_time' );
314
-
315
-		if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) {
316
-			return false;
317
-		}
318
-
319
-		return $this->add_points_hook(
320
-			array(
321
-				'event' => 'user_visit',
322
-				'target' => array( 'current:user' ),
323
-				'reactor' => 'points_legacy',
324
-				'points' => $points,
325
-				'points_type' => $settings['points_type'],
326
-				'points_legacy_periods' => array(
327
-					'fire' => array(
328
-						array(
329
-							'length' => $period,
330
-							'args' => array( array( 'current:user' ) ),
331
-							'relative' => true,
332
-						),
333
-					),
334
-				),
335
-				'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ),
336
-				'description' => __( 'Visiting the site.', 'wordpoints-importer' ),
337
-				'points_legacy_reversals' => array(),
338
-				'legacy_log_type' => 'cubepoints-dailypoints',
339
-			)
340
-		);
341
-	}
342
-
343
-	/**
344
-	 * Programmatically create a new instance of a points hook.
345
-	 *
346
-	 * @since 1.0.0
347
-	 * @since 1.2.0 Now just accepts a single argument, $settings.
348
-	 *
349
-	 * @param array $settings The settings for this hook.
350
-	 *
351
-	 * @return bool True if added successfully, or false on failure.
352
-	 */
353
-	private function add_points_hook( $settings = array() ) {
354
-
355
-		$reaction_store = wordpoints_hooks()->get_reaction_store( 'points' );
356
-
357
-		$settings = array_merge(
358
-			array(
359
-				'target' => array( 'user' ),
360
-				'reactor' => 'points_legacy',
361
-				'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ),
362
-			)
363
-			, $settings
364
-		);
365
-
366
-		$reaction = $reaction_store->create_reaction( $settings );
367
-
368
-		if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) {
369
-			return false;
370
-		}
371
-
372
-		return true;
373
-	}
374
-
375
-	/**
376
-	 * Format the settings for a reaction for a particular post type.
377
-	 *
378
-	 * @since 1.2.0
379
-	 *
380
-	 * @param string $post_type The slug of the post type to format the settings for.
381
-	 * @param array  $settings  The reaction settings.
382
-	 *
383
-	 * @return array The settings modified for this particular post type.
384
-	 */
385
-	protected function format_settings_for_post_type( $post_type, $settings ) {
386
-
387
-		$settings['event'] = str_replace(
388
-			'\post'
389
-			, '\\' . $post_type
390
-			, $settings['event']
391
-		);
392
-
393
-		$settings['target'] = str_replace(
394
-			'\post'
395
-			, '\\' . $post_type
396
-			, $settings['target']
397
-		);
398
-
399
-		$labels = get_post_type_labels( get_post_type_object( $post_type ) );
400
-
401
-		$settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name );
402
-		$settings['description'] = sprintf( $settings['description'], $labels->singular_name );
403
-
404
-		return $settings;
405
-	}
406
-
407
-	/**
408
-	 * Import the user points.
409
-	 *
410
-	 * @since 1.0.0
411
-	 *
412
-	 * @param array $settings The settings for the points component import.
413
-	 */
414
-	protected function import_user_points( $settings ) {
415
-
416
-		$this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) );
417
-
418
-		// We don't log the import transactions.
419
-		add_filter( 'wordpoints_points_log', '__return_false' );
420
-
421
-		$start = 0;
422
-
423
-		// We do the import in batches.
424
-		while ( $rows = $this->get_next_user_points_batch( $start ) ) {
425
-
426
-			$start += count( $rows );
427
-
428
-			foreach ( $rows as $row ) {
429
-
430
-				wordpoints_alter_points(
431
-					$row->user_id
432
-					, $row->points
433
-					, $settings['points_type']
434
-					, 'cubepoints_import' // This is only for the hooks, it isn't being logged.
435
-				);
436
-			}
437
-
438
-			unset( $rows );
439
-		}
440
-
441
-		remove_filter( 'wordpoints_points_log', '__return_false' );
442
-
443
-		$this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) );
444
-	}
445
-
446
-	/**
447
-	 * Get a batch of user points to import.
448
-	 *
449
-	 * @since 1.0.0
450
-	 *
451
-	 * @param int $start The offset number to begin counting at.
452
-	 *
453
-	 * @return object[]|false The rows, or false.
454
-	 */
455
-	protected function get_next_user_points_batch( $start ) {
456
-
457
-		global $wpdb;
458
-
459
-		$rows = $wpdb->get_results(
460
-			$wpdb->prepare(
461
-				"
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 Reactions', '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 reactions…', '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
+        } // End foreach ( $options ).
286
+
287
+        if ( $this->import_daily_points_hook( $settings ) ) {
288
+            $imported++;
289
+        }
290
+
291
+        $this->feedback->success(
292
+            sprintf( __( 'Imported %s points reactions.', 'wordpoints-importer' ), $imported )
293
+        );
294
+    }
295
+
296
+    /**
297
+     * Import the settings for the Daily Points module to a points hook.
298
+     *
299
+     * @since 1.1.0
300
+     *
301
+     * @param array $settings The settings for the points component import.
302
+     *
303
+     * @return bool True if the settings were imported, false otherwise.
304
+     */
305
+    protected function import_daily_points_hook( $settings ) {
306
+
307
+        // Don't import this module setting if the module isn't active.
308
+        if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) {
309
+            return false;
310
+        }
311
+
312
+        $points = get_option( 'cp_module_dailypoints_points' );
313
+        $period = get_option( 'cp_module_dailypoints_time' );
314
+
315
+        if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) {
316
+            return false;
317
+        }
318
+
319
+        return $this->add_points_hook(
320
+            array(
321
+                'event' => 'user_visit',
322
+                'target' => array( 'current:user' ),
323
+                'reactor' => 'points_legacy',
324
+                'points' => $points,
325
+                'points_type' => $settings['points_type'],
326
+                'points_legacy_periods' => array(
327
+                    'fire' => array(
328
+                        array(
329
+                            'length' => $period,
330
+                            'args' => array( array( 'current:user' ) ),
331
+                            'relative' => true,
332
+                        ),
333
+                    ),
334
+                ),
335
+                'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ),
336
+                'description' => __( 'Visiting the site.', 'wordpoints-importer' ),
337
+                'points_legacy_reversals' => array(),
338
+                'legacy_log_type' => 'cubepoints-dailypoints',
339
+            )
340
+        );
341
+    }
342
+
343
+    /**
344
+     * Programmatically create a new instance of a points hook.
345
+     *
346
+     * @since 1.0.0
347
+     * @since 1.2.0 Now just accepts a single argument, $settings.
348
+     *
349
+     * @param array $settings The settings for this hook.
350
+     *
351
+     * @return bool True if added successfully, or false on failure.
352
+     */
353
+    private function add_points_hook( $settings = array() ) {
354
+
355
+        $reaction_store = wordpoints_hooks()->get_reaction_store( 'points' );
356
+
357
+        $settings = array_merge(
358
+            array(
359
+                'target' => array( 'user' ),
360
+                'reactor' => 'points_legacy',
361
+                'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ),
362
+            )
363
+            , $settings
364
+        );
365
+
366
+        $reaction = $reaction_store->create_reaction( $settings );
367
+
368
+        if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) {
369
+            return false;
370
+        }
371
+
372
+        return true;
373
+    }
374
+
375
+    /**
376
+     * Format the settings for a reaction for a particular post type.
377
+     *
378
+     * @since 1.2.0
379
+     *
380
+     * @param string $post_type The slug of the post type to format the settings for.
381
+     * @param array  $settings  The reaction settings.
382
+     *
383
+     * @return array The settings modified for this particular post type.
384
+     */
385
+    protected function format_settings_for_post_type( $post_type, $settings ) {
386
+
387
+        $settings['event'] = str_replace(
388
+            '\post'
389
+            , '\\' . $post_type
390
+            , $settings['event']
391
+        );
392
+
393
+        $settings['target'] = str_replace(
394
+            '\post'
395
+            , '\\' . $post_type
396
+            , $settings['target']
397
+        );
398
+
399
+        $labels = get_post_type_labels( get_post_type_object( $post_type ) );
400
+
401
+        $settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name );
402
+        $settings['description'] = sprintf( $settings['description'], $labels->singular_name );
403
+
404
+        return $settings;
405
+    }
406
+
407
+    /**
408
+     * Import the user points.
409
+     *
410
+     * @since 1.0.0
411
+     *
412
+     * @param array $settings The settings for the points component import.
413
+     */
414
+    protected function import_user_points( $settings ) {
415
+
416
+        $this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) );
417
+
418
+        // We don't log the import transactions.
419
+        add_filter( 'wordpoints_points_log', '__return_false' );
420
+
421
+        $start = 0;
422
+
423
+        // We do the import in batches.
424
+        while ( $rows = $this->get_next_user_points_batch( $start ) ) {
425
+
426
+            $start += count( $rows );
427
+
428
+            foreach ( $rows as $row ) {
429
+
430
+                wordpoints_alter_points(
431
+                    $row->user_id
432
+                    , $row->points
433
+                    , $settings['points_type']
434
+                    , 'cubepoints_import' // This is only for the hooks, it isn't being logged.
435
+                );
436
+            }
437
+
438
+            unset( $rows );
439
+        }
440
+
441
+        remove_filter( 'wordpoints_points_log', '__return_false' );
442
+
443
+        $this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) );
444
+    }
445
+
446
+    /**
447
+     * Get a batch of user points to import.
448
+     *
449
+     * @since 1.0.0
450
+     *
451
+     * @param int $start The offset number to begin counting at.
452
+     *
453
+     * @return object[]|false The rows, or false.
454
+     */
455
+    protected function get_next_user_points_batch( $start ) {
456
+
457
+        global $wpdb;
458
+
459
+        $rows = $wpdb->get_results(
460
+            $wpdb->prepare(
461
+                "
462 462
 					SELECT `user_id`, `meta_value` as points
463 463
 					FROM {$wpdb->usermeta}
464 464
 					WHERE `meta_key` = 'cpoints'
465 465
 					ORDER BY `umeta_id`
466 466
 					LIMIT %d,500
467 467
 				"
468
-				, $start
469
-			)
470
-		); // WPCS: cache OK.
471
-
472
-		if ( ! is_array( $rows ) ) {
473
-			return false;
474
-		}
475
-
476
-		return $rows;
477
-	}
478
-
479
-	/**
480
-	 * Check if the points logs can be imported.
481
-	 *
482
-	 * @since 1.0.0
483
-	 *
484
-	 * @return true|WP_Error True on success or a WP_Error on failure.
485
-	 */
486
-	public function can_import_points_logs() {
487
-
488
-		if ( ! $this->is_cubepoints_active() ) {
489
-
490
-			return new WP_Error(
491
-				'wordpoints_import_points_logs_cubepoints_inactive'
492
-				, __( 'CubePoints must be active.', 'wordpoints-importer' )
493
-			);
494
-		}
495
-
496
-		return true;
497
-	}
498
-
499
-	/**
500
-	 * Import the points logs.
501
-	 *
502
-	 * @since 1.0.0
503
-	 *
504
-	 * @param array $settings The import settings for the points component.
505
-	 */
506
-	protected function import_points_logs( $settings ) {
507
-
508
-		$this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) );
509
-
510
-		$start = 0;
511
-
512
-		while ( $logs = $this->get_next_points_logs_batch( $start ) ) {
513
-
514
-			$start += count( $logs );
515
-
516
-			foreach ( $logs as $log ) {
517
-
518
-				$this->import_points_log(
519
-					$log->uid
520
-					, $log->points
521
-					, $settings['points_type']
522
-					, "cubepoints-{$log->type}"
523
-					, array(
524
-						'cubepoints_type' => $log->type,
525
-						'cubepoints_data' => $log->data,
526
-					)
527
-					, date( 'Y-m-d H:i:s', $log->timestamp )
528
-				);
529
-			}
530
-
531
-			unset( $logs );
532
-		}
533
-
534
-		$this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) );
535
-	}
536
-
537
-	/**
538
-	 * Import a points log.
539
-	 *
540
-	 * @since 1.0.0
541
-	 *
542
-	 * @param int    $user_id     The ID of the user the log is for.
543
-	 * @param int    $points      The number of points awarded.
544
-	 * @param string $points_type The points type.
545
-	 * @param string $log_type    The log type.
546
-	 * @param array  $meta        The metadata for this log.
547
-	 * @param int    $date        The date the transaction took place.
548
-	 */
549
-	protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) {
550
-
551
-		global $wpdb;
552
-
553
-		$result = $wpdb->insert(
554
-			$wpdb->wordpoints_points_logs,
555
-			array(
556
-				'user_id'     => $user_id,
557
-				'points'      => $points,
558
-				'points_type' => $points_type,
559
-				'log_type'    => $log_type,
560
-				'text'        => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ),
561
-				'date'        => $date,
562
-				'site_id'     => $wpdb->siteid,
563
-				'blog_id'     => $wpdb->blogid,
564
-			),
565
-			array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' )
566
-		);
567
-
568
-		if ( false !== $result ) {
569
-
570
-			$log_id = (int) $wpdb->insert_id;
571
-
572
-			// Set auto_reversed and original_log_id metadata for reversed logs.
573
-			foreach ( $this->reversible_log_types as $reverse_type => $type ) {
574
-
575
-				if ( $meta['cubepoints_type'] === $type ) {
576
-
577
-					// Save this log ID for later, in case this log was reversed.
578
-					// cubepoints_data will contain the entity ID.
579
-					$this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id;
580
-
581
-				} elseif (
582
-					$meta['cubepoints_type'] === $reverse_type
583
-					&& isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] )
584
-				) {
585
-
586
-					// This log was reverses another one. Set the original log ID.
587
-					$meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ];
588
-
589
-					// And mark the original as auto_reversed.
590
-					wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id );
591
-
592
-					// No need to keep this info anymore.
593
-					unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] );
594
-				}
595
-			}
596
-
597
-			// Set the entity IDs to their own meta keys, for the sake of reversals.
598
-			if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) {
599
-				$meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data'];
600
-			}
601
-
602
-			foreach ( $meta as $meta_key => $meta_value ) {
603
-
604
-				wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value );
605
-			}
606
-
607
-			do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id );
608
-
609
-		} // End if ( inserted successfully ).
610
-	}
611
-
612
-	/**
613
-	 * Generate the log text when importing a points log.
614
-	 *
615
-	 * @since 1.0.0
616
-	 */
617
-	public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) {
618
-
619
-		ob_start();
620
-		do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] );
621
-		return ob_get_clean();
622
-	}
623
-
624
-	/**
625
-	 * Get the next 500 points logs from CubePoints.
626
-	 *
627
-	 * @since 1.0.0
628
-	 *
629
-	 * @param int $start The offset number to begin counting the 500 at.
630
-	 *
631
-	 * @return object[]|false The rows from the database.
632
-	 */
633
-	protected function get_next_points_logs_batch( $start ) {
634
-
635
-		global $wpdb;
636
-
637
-		$logs = $wpdb->get_results( // WPCS: unprepared SQL OK.
638
-			$wpdb->prepare( // WPCS: unprepared SQL OK.
639
-				'
468
+                , $start
469
+            )
470
+        ); // WPCS: cache OK.
471
+
472
+        if ( ! is_array( $rows ) ) {
473
+            return false;
474
+        }
475
+
476
+        return $rows;
477
+    }
478
+
479
+    /**
480
+     * Check if the points logs can be imported.
481
+     *
482
+     * @since 1.0.0
483
+     *
484
+     * @return true|WP_Error True on success or a WP_Error on failure.
485
+     */
486
+    public function can_import_points_logs() {
487
+
488
+        if ( ! $this->is_cubepoints_active() ) {
489
+
490
+            return new WP_Error(
491
+                'wordpoints_import_points_logs_cubepoints_inactive'
492
+                , __( 'CubePoints must be active.', 'wordpoints-importer' )
493
+            );
494
+        }
495
+
496
+        return true;
497
+    }
498
+
499
+    /**
500
+     * Import the points logs.
501
+     *
502
+     * @since 1.0.0
503
+     *
504
+     * @param array $settings The import settings for the points component.
505
+     */
506
+    protected function import_points_logs( $settings ) {
507
+
508
+        $this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) );
509
+
510
+        $start = 0;
511
+
512
+        while ( $logs = $this->get_next_points_logs_batch( $start ) ) {
513
+
514
+            $start += count( $logs );
515
+
516
+            foreach ( $logs as $log ) {
517
+
518
+                $this->import_points_log(
519
+                    $log->uid
520
+                    , $log->points
521
+                    , $settings['points_type']
522
+                    , "cubepoints-{$log->type}"
523
+                    , array(
524
+                        'cubepoints_type' => $log->type,
525
+                        'cubepoints_data' => $log->data,
526
+                    )
527
+                    , date( 'Y-m-d H:i:s', $log->timestamp )
528
+                );
529
+            }
530
+
531
+            unset( $logs );
532
+        }
533
+
534
+        $this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) );
535
+    }
536
+
537
+    /**
538
+     * Import a points log.
539
+     *
540
+     * @since 1.0.0
541
+     *
542
+     * @param int    $user_id     The ID of the user the log is for.
543
+     * @param int    $points      The number of points awarded.
544
+     * @param string $points_type The points type.
545
+     * @param string $log_type    The log type.
546
+     * @param array  $meta        The metadata for this log.
547
+     * @param int    $date        The date the transaction took place.
548
+     */
549
+    protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) {
550
+
551
+        global $wpdb;
552
+
553
+        $result = $wpdb->insert(
554
+            $wpdb->wordpoints_points_logs,
555
+            array(
556
+                'user_id'     => $user_id,
557
+                'points'      => $points,
558
+                'points_type' => $points_type,
559
+                'log_type'    => $log_type,
560
+                'text'        => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ),
561
+                'date'        => $date,
562
+                'site_id'     => $wpdb->siteid,
563
+                'blog_id'     => $wpdb->blogid,
564
+            ),
565
+            array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' )
566
+        );
567
+
568
+        if ( false !== $result ) {
569
+
570
+            $log_id = (int) $wpdb->insert_id;
571
+
572
+            // Set auto_reversed and original_log_id metadata for reversed logs.
573
+            foreach ( $this->reversible_log_types as $reverse_type => $type ) {
574
+
575
+                if ( $meta['cubepoints_type'] === $type ) {
576
+
577
+                    // Save this log ID for later, in case this log was reversed.
578
+                    // cubepoints_data will contain the entity ID.
579
+                    $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id;
580
+
581
+                } elseif (
582
+                    $meta['cubepoints_type'] === $reverse_type
583
+                    && isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] )
584
+                ) {
585
+
586
+                    // This log was reverses another one. Set the original log ID.
587
+                    $meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ];
588
+
589
+                    // And mark the original as auto_reversed.
590
+                    wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id );
591
+
592
+                    // No need to keep this info anymore.
593
+                    unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] );
594
+                }
595
+            }
596
+
597
+            // Set the entity IDs to their own meta keys, for the sake of reversals.
598
+            if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) {
599
+                $meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data'];
600
+            }
601
+
602
+            foreach ( $meta as $meta_key => $meta_value ) {
603
+
604
+                wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value );
605
+            }
606
+
607
+            do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id );
608
+
609
+        } // End if ( inserted successfully ).
610
+    }
611
+
612
+    /**
613
+     * Generate the log text when importing a points log.
614
+     *
615
+     * @since 1.0.0
616
+     */
617
+    public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) {
618
+
619
+        ob_start();
620
+        do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] );
621
+        return ob_get_clean();
622
+    }
623
+
624
+    /**
625
+     * Get the next 500 points logs from CubePoints.
626
+     *
627
+     * @since 1.0.0
628
+     *
629
+     * @param int $start The offset number to begin counting the 500 at.
630
+     *
631
+     * @return object[]|false The rows from the database.
632
+     */
633
+    protected function get_next_points_logs_batch( $start ) {
634
+
635
+        global $wpdb;
636
+
637
+        $logs = $wpdb->get_results( // WPCS: unprepared SQL OK.
638
+            $wpdb->prepare( // WPCS: unprepared SQL OK.
639
+                '
640 640
 					SELECT *
641 641
 					FROM `' . CP_DB . '`
642 642
 					ORDER BY `id`
643 643
 					LIMIT %d,500
644 644
 				'
645
-				, $start
646
-			)
647
-		); // WPCS: cache OK.
645
+                , $start
646
+            )
647
+        ); // WPCS: cache OK.
648 648
 
649
-		if ( ! is_array( $logs ) ) {
650
-			$this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) );
651
-			return false;
652
-		}
649
+        if ( ! is_array( $logs ) ) {
650
+            $this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) );
651
+            return false;
652
+        }
653 653
 
654
-		return $logs;
655
-	}
654
+        return $logs;
655
+    }
656 656
 
657
-	/**
658
-	 * Import ranks.
659
-	 *
660
-	 * @since 1.1.0
661
-	 *
662
-	 * @param array $settings The import settings for the ranks component.
663
-	 */
664
-	public function import_ranks( $settings ) {
657
+    /**
658
+     * Import ranks.
659
+     *
660
+     * @since 1.1.0
661
+     *
662
+     * @param array $settings The import settings for the ranks component.
663
+     */
664
+    public function import_ranks( $settings ) {
665 665
 
666
-		$this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) );
666
+        $this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) );
667 667
 
668
-		$ranks_data = get_option( 'cp_module_ranks_data' );
668
+        $ranks_data = get_option( 'cp_module_ranks_data' );
669 669
 
670
-		if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) {
671
-			$this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) );
672
-			return;
673
-		}
670
+        if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) {
671
+            $this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) );
672
+            return;
673
+        }
674 674
 
675
-		$i = 0;
675
+        $i = 0;
676 676
 
677
-		// The base rank already exists, so we just update it.
678
-		if ( isset( $ranks_data[0] ) ) {
677
+        // The base rank already exists, so we just update it.
678
+        if ( isset( $ranks_data[0] ) ) {
679 679
 
680
-			wordpoints_update_rank(
681
-				WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 )
682
-				, $ranks_data[0]
683
-				, 'base'
684
-				, $settings['rank_group']
685
-				, 0
686
-			);
680
+            wordpoints_update_rank(
681
+                WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 )
682
+                , $ranks_data[0]
683
+                , 'base'
684
+                , $settings['rank_group']
685
+                , 0
686
+            );
687 687
 
688
-			$i++;
688
+            $i++;
689 689
 
690
-			unset( $ranks_data[0] );
691
-		}
690
+            unset( $ranks_data[0] );
691
+        }
692 692
 
693
-		$points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) );
694
-		$rank_type = 'points-' . $points_type;
693
+        $points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) );
694
+        $rank_type = 'points-' . $points_type;
695 695
 
696
-		ksort( $ranks_data );
696
+        ksort( $ranks_data );
697 697
 
698
-		foreach ( $ranks_data as $points => $rank_name ) {
698
+        foreach ( $ranks_data as $points => $rank_name ) {
699 699
 
700
-			wordpoints_add_rank(
701
-				$rank_name
702
-				, $rank_type
703
-				, $settings['rank_group']
704
-				, $i
705
-				, array( 'points' => $points, 'points_type' => $points_type )
706
-			);
700
+            wordpoints_add_rank(
701
+                $rank_name
702
+                , $rank_type
703
+                , $settings['rank_group']
704
+                , $i
705
+                , array( 'points' => $points, 'points_type' => $points_type )
706
+            );
707 707
 
708
-			$i++;
709
-		}
708
+            $i++;
709
+        }
710 710
 
711
-		$this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) );
712
-	}
711
+        $this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) );
712
+    }
713 713
 }
714 714
 
715 715
 // EOF
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -66,36 +66,36 @@  discard block
 block discarded – undo
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 Reactions', '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 Reactions', '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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 reactions…', 'wordpoints-importer' ) );
196
+		$this->feedback->info(__('Importing points reactions…', '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
 block discarded – undo
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,13 +270,13 @@  discard block
 block discarded – undo
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
 				}
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 
285 285
 		} // End foreach ( $options ).
286 286
 
287
-		if ( $this->import_daily_points_hook( $settings ) ) {
287
+		if ($this->import_daily_points_hook($settings)) {
288 288
 			$imported++;
289 289
 		}
290 290
 
291 291
 		$this->feedback->success(
292
-			sprintf( __( 'Imported %s points reactions.', 'wordpoints-importer' ), $imported )
292
+			sprintf(__('Imported %s points reactions.', 'wordpoints-importer'), $imported)
293 293
 		);
294 294
 	}
295 295
 
@@ -302,24 +302,24 @@  discard block
 block discarded – undo
302 302
 	 *
303 303
 	 * @return bool True if the settings were imported, false otherwise.
304 304
 	 */
305
-	protected function import_daily_points_hook( $settings ) {
305
+	protected function import_daily_points_hook($settings) {
306 306
 
307 307
 		// Don't import this module setting if the module isn't active.
308
-		if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) {
308
+		if (function_exists('cp_module_activated') && !cp_module_activated('dailypoints')) {
309 309
 			return false;
310 310
 		}
311 311
 
312
-		$points = get_option( 'cp_module_dailypoints_points' );
313
-		$period = get_option( 'cp_module_dailypoints_time' );
312
+		$points = get_option('cp_module_dailypoints_points');
313
+		$period = get_option('cp_module_dailypoints_time');
314 314
 
315
-		if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) {
315
+		if (!wordpoints_int($points) || !wordpoints_posint($period)) {
316 316
 			return false;
317 317
 		}
318 318
 
319 319
 		return $this->add_points_hook(
320 320
 			array(
321 321
 				'event' => 'user_visit',
322
-				'target' => array( 'current:user' ),
322
+				'target' => array('current:user'),
323 323
 				'reactor' => 'points_legacy',
324 324
 				'points' => $points,
325 325
 				'points_type' => $settings['points_type'],
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
 					'fire' => array(
328 328
 						array(
329 329
 							'length' => $period,
330
-							'args' => array( array( 'current:user' ) ),
330
+							'args' => array(array('current:user')),
331 331
 							'relative' => true,
332 332
 						),
333 333
 					),
334 334
 				),
335
-				'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ),
336
-				'description' => __( 'Visiting the site.', 'wordpoints-importer' ),
335
+				'log_text' => __('Visiting the site.', 'wordpoints-importer'),
336
+				'description' => __('Visiting the site.', 'wordpoints-importer'),
337 337
 				'points_legacy_reversals' => array(),
338 338
 				'legacy_log_type' => 'cubepoints-dailypoints',
339 339
 			)
@@ -350,22 +350,22 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return bool True if added successfully, or false on failure.
352 352
 	 */
353
-	private function add_points_hook( $settings = array() ) {
353
+	private function add_points_hook($settings = array()) {
354 354
 
355
-		$reaction_store = wordpoints_hooks()->get_reaction_store( 'points' );
355
+		$reaction_store = wordpoints_hooks()->get_reaction_store('points');
356 356
 
357 357
 		$settings = array_merge(
358 358
 			array(
359
-				'target' => array( 'user' ),
359
+				'target' => array('user'),
360 360
 				'reactor' => 'points_legacy',
361
-				'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ),
361
+				'points_legacy_reversals' => array('toggle_off' => 'toggle_on'),
362 362
 			)
363 363
 			, $settings
364 364
 		);
365 365
 
366
-		$reaction = $reaction_store->create_reaction( $settings );
366
+		$reaction = $reaction_store->create_reaction($settings);
367 367
 
368
-		if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) {
368
+		if (!$reaction instanceof WordPoints_Hook_ReactionI) {
369 369
 			return false;
370 370
 		}
371 371
 
@@ -382,24 +382,24 @@  discard block
 block discarded – undo
382 382
 	 *
383 383
 	 * @return array The settings modified for this particular post type.
384 384
 	 */
385
-	protected function format_settings_for_post_type( $post_type, $settings ) {
385
+	protected function format_settings_for_post_type($post_type, $settings) {
386 386
 
387 387
 		$settings['event'] = str_replace(
388 388
 			'\post'
389
-			, '\\' . $post_type
389
+			, '\\'.$post_type
390 390
 			, $settings['event']
391 391
 		);
392 392
 
393 393
 		$settings['target'] = str_replace(
394 394
 			'\post'
395
-			, '\\' . $post_type
395
+			, '\\'.$post_type
396 396
 			, $settings['target']
397 397
 		);
398 398
 
399
-		$labels = get_post_type_labels( get_post_type_object( $post_type ) );
399
+		$labels = get_post_type_labels(get_post_type_object($post_type));
400 400
 
401
-		$settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name );
402
-		$settings['description'] = sprintf( $settings['description'], $labels->singular_name );
401
+		$settings['log_text'] = sprintf($settings['log_text'], $labels->singular_name);
402
+		$settings['description'] = sprintf($settings['description'], $labels->singular_name);
403 403
 
404 404
 		return $settings;
405 405
 	}
@@ -411,21 +411,21 @@  discard block
 block discarded – undo
411 411
 	 *
412 412
 	 * @param array $settings The settings for the points component import.
413 413
 	 */
414
-	protected function import_user_points( $settings ) {
414
+	protected function import_user_points($settings) {
415 415
 
416
-		$this->feedback->info( __( 'Importing users' points…', 'wordpoints-importer' ) );
416
+		$this->feedback->info(__('Importing users' points…', 'wordpoints-importer'));
417 417
 
418 418
 		// We don't log the import transactions.
419
-		add_filter( 'wordpoints_points_log', '__return_false' );
419
+		add_filter('wordpoints_points_log', '__return_false');
420 420
 
421 421
 		$start = 0;
422 422
 
423 423
 		// We do the import in batches.
424
-		while ( $rows = $this->get_next_user_points_batch( $start ) ) {
424
+		while ($rows = $this->get_next_user_points_batch($start)) {
425 425
 
426
-			$start += count( $rows );
426
+			$start += count($rows);
427 427
 
428
-			foreach ( $rows as $row ) {
428
+			foreach ($rows as $row) {
429 429
 
430 430
 				wordpoints_alter_points(
431 431
 					$row->user_id
@@ -435,12 +435,12 @@  discard block
 block discarded – undo
435 435
 				);
436 436
 			}
437 437
 
438
-			unset( $rows );
438
+			unset($rows);
439 439
 		}
440 440
 
441
-		remove_filter( 'wordpoints_points_log', '__return_false' );
441
+		remove_filter('wordpoints_points_log', '__return_false');
442 442
 
443
-		$this->feedback->success( sprintf( __( 'Imported points for %s users…', 'wordpoints-importer' ), $start ) );
443
+		$this->feedback->success(sprintf(__('Imported points for %s users…', 'wordpoints-importer'), $start));
444 444
 	}
445 445
 
446 446
 	/**
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 	 *
453 453
 	 * @return object[]|false The rows, or false.
454 454
 	 */
455
-	protected function get_next_user_points_batch( $start ) {
455
+	protected function get_next_user_points_batch($start) {
456 456
 
457 457
 		global $wpdb;
458 458
 
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
 			)
470 470
 		); // WPCS: cache OK.
471 471
 
472
-		if ( ! is_array( $rows ) ) {
472
+		if (!is_array($rows)) {
473 473
 			return false;
474 474
 		}
475 475
 
@@ -485,11 +485,11 @@  discard block
 block discarded – undo
485 485
 	 */
486 486
 	public function can_import_points_logs() {
487 487
 
488
-		if ( ! $this->is_cubepoints_active() ) {
488
+		if (!$this->is_cubepoints_active()) {
489 489
 
490 490
 			return new WP_Error(
491 491
 				'wordpoints_import_points_logs_cubepoints_inactive'
492
-				, __( 'CubePoints must be active.', 'wordpoints-importer' )
492
+				, __('CubePoints must be active.', 'wordpoints-importer')
493 493
 			);
494 494
 		}
495 495
 
@@ -503,17 +503,17 @@  discard block
 block discarded – undo
503 503
 	 *
504 504
 	 * @param array $settings The import settings for the points component.
505 505
 	 */
506
-	protected function import_points_logs( $settings ) {
506
+	protected function import_points_logs($settings) {
507 507
 
508
-		$this->feedback->info( __( 'Importing points logs…', 'wordpoints-importer' ) );
508
+		$this->feedback->info(__('Importing points logs…', 'wordpoints-importer'));
509 509
 
510 510
 		$start = 0;
511 511
 
512
-		while ( $logs = $this->get_next_points_logs_batch( $start ) ) {
512
+		while ($logs = $this->get_next_points_logs_batch($start)) {
513 513
 
514
-			$start += count( $logs );
514
+			$start += count($logs);
515 515
 
516
-			foreach ( $logs as $log ) {
516
+			foreach ($logs as $log) {
517 517
 
518 518
 				$this->import_points_log(
519 519
 					$log->uid
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 						'cubepoints_type' => $log->type,
525 525
 						'cubepoints_data' => $log->data,
526 526
 					)
527
-					, date( 'Y-m-d H:i:s', $log->timestamp )
527
+					, date('Y-m-d H:i:s', $log->timestamp)
528 528
 				);
529 529
 			}
530 530
 
531
-			unset( $logs );
531
+			unset($logs);
532 532
 		}
533 533
 
534
-		$this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) );
534
+		$this->feedback->success(sprintf(__('Imported %s points log entries.', 'wordpoints-importer'), $start));
535 535
 	}
536 536
 
537 537
 	/**
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 	 * @param array  $meta        The metadata for this log.
547 547
 	 * @param int    $date        The date the transaction took place.
548 548
 	 */
549
-	protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) {
549
+	protected function import_points_log($user_id, $points, $points_type, $log_type, $meta, $date) {
550 550
 
551 551
 		global $wpdb;
552 552
 
@@ -557,54 +557,54 @@  discard block
 block discarded – undo
557 557
 				'points'      => $points,
558 558
 				'points_type' => $points_type,
559 559
 				'log_type'    => $log_type,
560
-				'text'        => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ),
560
+				'text'        => $this->render_points_log_text('', $user_id, $points, $points_type, $log_type, $meta),
561 561
 				'date'        => $date,
562 562
 				'site_id'     => $wpdb->siteid,
563 563
 				'blog_id'     => $wpdb->blogid,
564 564
 			),
565
-			array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' )
565
+			array('%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d')
566 566
 		);
567 567
 
568
-		if ( false !== $result ) {
568
+		if (false !== $result) {
569 569
 
570 570
 			$log_id = (int) $wpdb->insert_id;
571 571
 
572 572
 			// Set auto_reversed and original_log_id metadata for reversed logs.
573
-			foreach ( $this->reversible_log_types as $reverse_type => $type ) {
573
+			foreach ($this->reversible_log_types as $reverse_type => $type) {
574 574
 
575
-				if ( $meta['cubepoints_type'] === $type ) {
575
+				if ($meta['cubepoints_type'] === $type) {
576 576
 
577 577
 					// Save this log ID for later, in case this log was reversed.
578 578
 					// cubepoints_data will contain the entity ID.
579
-					$this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id;
579
+					$this->reversible_log_ids[$type][$meta['cubepoints_data']] = $log_id;
580 580
 
581 581
 				} elseif (
582 582
 					$meta['cubepoints_type'] === $reverse_type
583
-					&& isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] )
583
+					&& isset($this->reversible_log_ids[$type][$meta['cubepoints_data']])
584 584
 				) {
585 585
 
586 586
 					// This log was reverses another one. Set the original log ID.
587
-					$meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ];
587
+					$meta['original_log_id'] = $this->reversible_log_ids[$type][$meta['cubepoints_data']];
588 588
 
589 589
 					// And mark the original as auto_reversed.
590
-					wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id );
590
+					wordpoints_add_points_log_meta($meta['original_log_id'], 'auto_reversed', $log_id);
591 591
 
592 592
 					// No need to keep this info anymore.
593
-					unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] );
593
+					unset($this->reversible_log_ids[$type][$meta['cubepoints_data']]);
594 594
 				}
595 595
 			}
596 596
 
597 597
 			// Set the entity IDs to their own meta keys, for the sake of reversals.
598
-			if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) {
599
-				$meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data'];
598
+			if (isset($this->log_type_entities[$meta['cubepoints_type']])) {
599
+				$meta[$this->log_type_entities[$meta['cubepoints_type']]] = $meta['cubepoints_data'];
600 600
 			}
601 601
 
602
-			foreach ( $meta as $meta_key => $meta_value ) {
602
+			foreach ($meta as $meta_key => $meta_value) {
603 603
 
604
-				wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value );
604
+				wordpoints_add_points_log_meta($log_id, $meta_key, $meta_value);
605 605
 			}
606 606
 
607
-			do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id );
607
+			do_action('wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id);
608 608
 
609 609
 		} // End if ( inserted successfully ).
610 610
 	}
@@ -614,10 +614,10 @@  discard block
 block discarded – undo
614 614
 	 *
615 615
 	 * @since 1.0.0
616 616
 	 */
617
-	public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) {
617
+	public function render_points_log_text($text, $user_id, $points, $points_type, $log_type, $meta) {
618 618
 
619 619
 		ob_start();
620
-		do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] );
620
+		do_action('cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data']);
621 621
 		return ob_get_clean();
622 622
 	}
623 623
 
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 *
631 631
 	 * @return object[]|false The rows from the database.
632 632
 	 */
633
-	protected function get_next_points_logs_batch( $start ) {
633
+	protected function get_next_points_logs_batch($start) {
634 634
 
635 635
 		global $wpdb;
636 636
 
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 			$wpdb->prepare( // WPCS: unprepared SQL OK.
639 639
 				'
640 640
 					SELECT *
641
-					FROM `' . CP_DB . '`
641
+					FROM `' . CP_DB.'`
642 642
 					ORDER BY `id`
643 643
 					LIMIT %d,500
644 644
 				'
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 			)
647 647
 		); // WPCS: cache OK.
648 648
 
649
-		if ( ! is_array( $logs ) ) {
650
-			$this->feedback->error( __( 'Unable to retrieve the logs from CubePoints…', 'wordpoints-importer' ) );
649
+		if (!is_array($logs)) {
650
+			$this->feedback->error(__('Unable to retrieve the logs from CubePoints…', 'wordpoints-importer'));
651 651
 			return false;
652 652
 		}
653 653
 
@@ -661,24 +661,24 @@  discard block
 block discarded – undo
661 661
 	 *
662 662
 	 * @param array $settings The import settings for the ranks component.
663 663
 	 */
664
-	public function import_ranks( $settings ) {
664
+	public function import_ranks($settings) {
665 665
 
666
-		$this->feedback->info( __( 'Importing ranks…', 'wordpoints-importer' ) );
666
+		$this->feedback->info(__('Importing ranks…', 'wordpoints-importer'));
667 667
 
668
-		$ranks_data = get_option( 'cp_module_ranks_data' );
668
+		$ranks_data = get_option('cp_module_ranks_data');
669 669
 
670
-		if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) {
671
-			$this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) );
670
+		if (empty($ranks_data) || !is_array($ranks_data)) {
671
+			$this->feedback->error(__('No ranks found.', 'wordpoints-importer'));
672 672
 			return;
673 673
 		}
674 674
 
675 675
 		$i = 0;
676 676
 
677 677
 		// The base rank already exists, so we just update it.
678
-		if ( isset( $ranks_data[0] ) ) {
678
+		if (isset($ranks_data[0])) {
679 679
 
680 680
 			wordpoints_update_rank(
681
-				WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 )
681
+				WordPoints_Rank_Groups::get_group($settings['rank_group'])->get_rank(0)
682 682
 				, $ranks_data[0]
683 683
 				, 'base'
684 684
 				, $settings['rank_group']
@@ -687,28 +687,28 @@  discard block
 block discarded – undo
687 687
 
688 688
 			$i++;
689 689
 
690
-			unset( $ranks_data[0] );
690
+			unset($ranks_data[0]);
691 691
 		}
692 692
 
693
-		$points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) );
694
-		$rank_type = 'points-' . $points_type;
693
+		$points_type = substr($settings['rank_group'], strlen('points_type-'));
694
+		$rank_type = 'points-'.$points_type;
695 695
 
696
-		ksort( $ranks_data );
696
+		ksort($ranks_data);
697 697
 
698
-		foreach ( $ranks_data as $points => $rank_name ) {
698
+		foreach ($ranks_data as $points => $rank_name) {
699 699
 
700 700
 			wordpoints_add_rank(
701 701
 				$rank_name
702 702
 				, $rank_type
703 703
 				, $settings['rank_group']
704 704
 				, $i
705
-				, array( 'points' => $points, 'points_type' => $points_type )
705
+				, array('points' => $points, 'points_type' => $points_type)
706 706
 			);
707 707
 
708 708
 			$i++;
709 709
 		}
710 710
 
711
-		$this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) );
711
+		$this->feedback->success(sprintf(__('Imported %s ranks.', 'wordpoints-importer'), $i));
712 712
 	}
713 713
 }
714 714
 
Please login to merge, or discard this patch.
tests/phpunit/tests/admin-functions.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -14,181 +14,181 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/tests/importers/cubepoints/hooks/post-publish.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -18,37 +18,37 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,24 +30,24 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/tests/importers/cubepoints/hooks/comment-leave.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -18,51 +18,51 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/tests/importers/cubepoints/hooks/comment-receive.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -18,53 +18,53 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,17 +30,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/tests/importers/cubepoints/hooks/user-register.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -18,30 +18,30 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,17 +30,17 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/tests/importer.php 2 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -16,295 +16,295 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
tests/phpunit/tests/importers.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -16,149 +16,149 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/phpunit/includes/mocks.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -14,88 +14,88 @@
 block discarded – undo
14 14
  */
15 15
 class WordPoints_Importer_Mock extends WordPoints_Importer {
16 16
 
17
-	/**
18
-	 * @since 1.0.0
19
-	 */
20
-	public $components;
21
-
22
-	/**
23
-	 * The "imports" performed.
24
-	 *
25
-	 * @since 1.0.0
26
-	 *
27
-	 * @var array
28
-	 */
29
-	public $imports;
30
-
31
-	/**
32
-	 * The "imports" for that were checked for possible performance.
33
-	 *
34
-	 * @since 1.0.0
35
-	 *
36
-	 * @var array
37
-	 */
38
-	public $can_imports;
39
-
40
-	/**
41
-	 * Whether this importer is available.
42
-	 *
43
-	 * @since 1.0.0
44
-	 *
45
-	 * @var true|WP_Error
46
-	 */
47
-	public $is_available = true;
48
-
49
-	/**
50
-	 * @since 1.0.0
51
-	 */
52
-	public function is_available() {
53
-		return $this->is_available;
54
-	}
55
-
56
-	/**
57
-	 * Mock an import method.
58
-	 *
59
-	 * @since 1.0.0
60
-	 *
61
-	 * @param array $settings The settings for this "component".
62
-	 */
63
-	public function do_an_import( $settings ) {
64
-
65
-		$this->imports[] = $settings;
66
-	}
67
-
68
-	/**
69
-	 * Mock a can_import method.
70
-	 *
71
-	 * @since 1.0.0
72
-	 *
73
-	 * @param array $settings The settings for this "component".
74
-	 *
75
-	 * @return true
76
-	 */
77
-	public function can_import( $settings ) {
78
-
79
-		$this->can_imports[] = $settings;
80
-
81
-		return true;
82
-	}
83
-
84
-	/**
85
-	 * Return a WP_Error because we can't do the import for an option.
86
-	 *
87
-	 * @since 1.0.0
88
-	 *
89
-	 * @param array $settings The settings for this "component".
90
-	 *
91
-	 * @return WP_Error An error.
92
-	 */
93
-	public function cant_import( $settings ) {
94
-
95
-		$this->can_imports[] = $settings;
96
-
97
-		return new WP_Error();
98
-	}
17
+    /**
18
+     * @since 1.0.0
19
+     */
20
+    public $components;
21
+
22
+    /**
23
+     * The "imports" performed.
24
+     *
25
+     * @since 1.0.0
26
+     *
27
+     * @var array
28
+     */
29
+    public $imports;
30
+
31
+    /**
32
+     * The "imports" for that were checked for possible performance.
33
+     *
34
+     * @since 1.0.0
35
+     *
36
+     * @var array
37
+     */
38
+    public $can_imports;
39
+
40
+    /**
41
+     * Whether this importer is available.
42
+     *
43
+     * @since 1.0.0
44
+     *
45
+     * @var true|WP_Error
46
+     */
47
+    public $is_available = true;
48
+
49
+    /**
50
+     * @since 1.0.0
51
+     */
52
+    public function is_available() {
53
+        return $this->is_available;
54
+    }
55
+
56
+    /**
57
+     * Mock an import method.
58
+     *
59
+     * @since 1.0.0
60
+     *
61
+     * @param array $settings The settings for this "component".
62
+     */
63
+    public function do_an_import( $settings ) {
64
+
65
+        $this->imports[] = $settings;
66
+    }
67
+
68
+    /**
69
+     * Mock a can_import method.
70
+     *
71
+     * @since 1.0.0
72
+     *
73
+     * @param array $settings The settings for this "component".
74
+     *
75
+     * @return true
76
+     */
77
+    public function can_import( $settings ) {
78
+
79
+        $this->can_imports[] = $settings;
80
+
81
+        return true;
82
+    }
83
+
84
+    /**
85
+     * Return a WP_Error because we can't do the import for an option.
86
+     *
87
+     * @since 1.0.0
88
+     *
89
+     * @param array $settings The settings for this "component".
90
+     *
91
+     * @return WP_Error An error.
92
+     */
93
+    public function cant_import( $settings ) {
94
+
95
+        $this->can_imports[] = $settings;
96
+
97
+        return new WP_Error();
98
+    }
99 99
 }
100 100
 
101 101
 // EOF
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @param array $settings The settings for this "component".
62 62
 	 */
63
-	public function do_an_import( $settings ) {
63
+	public function do_an_import($settings) {
64 64
 
65 65
 		$this->imports[] = $settings;
66 66
 	}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return true
76 76
 	 */
77
-	public function can_import( $settings ) {
77
+	public function can_import($settings) {
78 78
 
79 79
 		$this->can_imports[] = $settings;
80 80
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return WP_Error An error.
92 92
 	 */
93
-	public function cant_import( $settings ) {
93
+	public function cant_import($settings) {
94 94
 
95 95
 		$this->can_imports[] = $settings;
96 96
 
Please login to merge, or discard this patch.