- Timestamp:
- 06/16/2018 10:42:16 AM (6 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
- Property svn:mergeinfo changed
/trunk merged: 42726,42728,43356
- Property svn:mergeinfo changed
-
branches/4.9/tests/phpunit/tests/admin/includesCommunityEvents.php
r43082 r43357 258 258 259 259 /** 260 * Test: get_events() should return the events with the WordCamp pinned in the prepared list. 261 * 262 * @since 4.9.7 263 */ 264 public function test_get_events_pin_wordcamp() { 265 add_filter( 'pre_http_request', array( $this, '_http_request_valid_response_unpinned_wordcamp' ) ); 266 267 $response_body = $this->instance->get_events(); 268 269 /* 270 * San Diego was at position 3 in the mock API response, but pinning puts it at position 2, 271 * so that it remains in the list. The other events should remain unchanged. 272 */ 273 $this->assertCount( 3, $response_body['events'] ); 274 $this->assertEquals( $response_body['events'][0]['title'], 'Flexbox + CSS Grid: Magic for Responsive Layouts' ); 275 $this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' ); 276 $this->assertEquals( $response_body['events'][2]['title'], 'WordCamp San Diego' ); 277 278 remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_unpinned_wordcamp' ) ); 279 } 280 281 /** 282 * Simulates a valid HTTP response where a WordCamp needs to be pinned higher than it's default position. 283 * 284 * @since 4.9.7 285 * 286 * @return array A mock HTTP response. 287 */ 288 public function _http_request_valid_response_unpinned_wordcamp() { 289 return array( 290 'headers' => '', 291 'response' => array( 'code' => 200 ), 292 'cookies' => '', 293 'filename' => '', 294 'body' => wp_json_encode( 295 array( 296 'location' => $this->get_user_location(), 297 'events' => array( 298 array( 299 'type' => 'meetup', 300 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts', 301 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/', 302 'meetup' => 'The East Bay WordPress Meetup Group', 303 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/', 304 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Monday 1pm' ) ), 305 'location' => array( 306 'location' => 'Oakland, CA, USA', 307 'country' => 'us', 308 'latitude' => 37.808453, 309 'longitude' => -122.26593, 310 ), 311 ), 312 array( 313 'type' => 'meetup', 314 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy', 315 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/', 316 'meetup' => 'WordPress Bay Area Foothills Group', 317 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/', 318 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Tuesday 1:30pm' ) ), 319 'location' => array( 320 'location' => 'Milpitas, CA, USA', 321 'country' => 'us', 322 'latitude' => 37.432813, 323 'longitude' => -121.907095, 324 ), 325 ), 326 array( 327 'type' => 'meetup', 328 'title' => 'WordPress Q&A', 329 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/', 330 'meetup' => 'The San Jose WordPress Meetup', 331 'meetup_url' => 'https://www.meetup.com/sanjosewp/', 332 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Wednesday 5:30pm' ) ), 333 'location' => array( 334 'location' => 'Milpitas, CA, USA', 335 'country' => 'us', 336 'latitude' => 37.244194, 337 'longitude' => -121.889313, 338 ), 339 ), 340 array( 341 'type' => 'wordcamp', 342 'title' => 'WordCamp San Diego', 343 'url' => 'https://2018.sandiego.wordcamp.org', 344 'meetup' => null, 345 'meetup_url' => null, 346 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Thursday 9am' ) ), 347 'location' => array( 348 'location' => 'San Diego, CA', 349 'country' => 'US', 350 'latitude' => 32.7220419, 351 'longitude' => -117.1534513, 352 ), 353 ), 354 ), 355 ) 356 ), 357 ); 358 } 359 360 /** 361 * Test: get_events() shouldn't stick an extra WordCamp when there's already one that naturally 362 * falls into the list. 363 * 364 * @since 4.9.7 365 */ 366 public function test_get_events_dont_pin_multiple_wordcamps() { 367 add_filter( 'pre_http_request', array( $this, '_http_request_valid_response_multiple_wordcamps' ) ); 368 369 $response_body = $this->instance->get_events(); 370 371 /* 372 * The first meetup should be removed because it's expired, while the next 3 events are selected. 373 * WordCamp LA should not be stuck to the list, because San Diego already appears naturally. 374 */ 375 $this->assertCount( 3, $response_body['events'] ); 376 $this->assertEquals( $response_body['events'][0]['title'], 'WordCamp San Diego' ); 377 $this->assertEquals( $response_body['events'][1]['title'], 'Part 3- Site Maintenance - Tools to Make It Easy' ); 378 $this->assertEquals( $response_body['events'][2]['title'], 'WordPress Q&A' ); 379 380 remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response_multiple_wordcamps' ) ); 381 } 382 383 /** 384 * Simulates a valid HTTP response where a WordCamp needs to be pinned higher than it's default position. 385 * no need to pin extra camp b/c one already exists in response 386 * 387 * @since 4.9.7 388 * 389 * @return array A mock HTTP response. 390 */ 391 public function _http_request_valid_response_multiple_wordcamps() { 392 return array( 393 'headers' => '', 394 'response' => array( 'code' => 200 ), 395 'cookies' => '', 396 'filename' => '', 397 'body' => wp_json_encode( 398 array( 399 'location' => $this->get_user_location(), 400 'events' => array( 401 array( 402 'type' => 'meetup', 403 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts', 404 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/', 405 'meetup' => 'The East Bay WordPress Meetup Group', 406 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/', 407 'date' => date( 'Y-m-d H:i:s', strtotime( '2 days ago' ) ), 408 'location' => array( 409 'location' => 'Oakland, CA, USA', 410 'country' => 'us', 411 'latitude' => 37.808453, 412 'longitude' => -122.26593, 413 ), 414 ), 415 array( 416 'type' => 'wordcamp', 417 'title' => 'WordCamp San Diego', 418 'url' => 'https://2018.sandiego.wordcamp.org', 419 'meetup' => null, 420 'meetup_url' => null, 421 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Tuesday 9am' ) ), 422 'location' => array( 423 'location' => 'San Diego, CA', 424 'country' => 'US', 425 'latitude' => 32.7220419, 426 'longitude' => -117.1534513, 427 ), 428 ), 429 array( 430 'type' => 'meetup', 431 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy', 432 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/', 433 'meetup' => 'WordPress Bay Area Foothills Group', 434 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/', 435 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Wednesday 1:30pm' ) ), 436 'location' => array( 437 'location' => 'Milpitas, CA, USA', 438 'country' => 'us', 439 'latitude' => 37.432813, 440 'longitude' => -121.907095, 441 ), 442 ), 443 array( 444 'type' => 'meetup', 445 'title' => 'WordPress Q&A', 446 'url' => 'https://www.meetup.com/sanjosewp/events/245419844/', 447 'meetup' => 'The San Jose WordPress Meetup', 448 'meetup_url' => 'https://www.meetup.com/sanjosewp/', 449 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Thursday 5:30pm' ) ), 450 'location' => array( 451 'location' => 'Milpitas, CA, USA', 452 'country' => 'us', 453 'latitude' => 37.244194, 454 'longitude' => -121.889313, 455 ), 456 ), 457 array( 458 'type' => 'wordcamp', 459 'title' => 'WordCamp Los Angeles', 460 'url' => 'https://2018.la.wordcamp.org', 461 'meetup' => null, 462 'meetup_url' => null, 463 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Friday 9am' ) ), 464 'location' => array( 465 'location' => 'Los Angeles, CA', 466 'country' => 'US', 467 'latitude' => 34.050888, 468 'longitude' => -118.285426, 469 ), 470 ), 471 ), 472 ) 473 ), 474 ); 475 } 476 477 /** 260 478 * Test that get_unsafe_client_ip() properly anonymizes all possible address formats 261 479 *
Note: See TracChangeset
for help on using the changeset viewer.