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