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