| 261 | |
| 262 | /** |
| 263 | * Test: get_events() should return the events with the WordCamp pinned in the prepared list. |
| 264 | * |
| 265 | * @since 5.0.0 |
| 266 | */ |
| 267 | public function test_get_events_pin_wordcamp() { |
| 268 | add_filter( 'pre_http_request', array( $this, '_http_request_valid_response_unpinned_wordcamp' ) ); |
| 269 | |
| 270 | $response_body = $this->instance->get_events(); |
| 271 | |
| 272 | /* |
| 273 | * San Diego was at position 3 in the mock API response, but pinning puts it at position 2, |
| 274 | * so that it remains in the list. |
| 275 | */ |
| 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 5.0.0 |
| 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 Sunday 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 Wednesday 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 Thursday 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 Saturday' ) ), |
| 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 | |