/** * Print both global or post related places in json. It's executed via Ajax * * @uses wl_shortcode_geomap_get_places() in order to retrieve places * @uses wl_shortcode_geomap_prepare_map() in order to encode retireved places in a Leaflet friendly format * * @param array $places An array of place posts. * * @return array An array of place posts. */ function wl_shortcode_geomap_ajax() { // Get the post Id. $post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null; $places = wl_shortcode_geomap_get_places($post_id); $map_data = wl_shortcode_geomap_prepare_map($places); wl_core_send_json($map_data); }
/** * Create: * * 2 Posts * * 1 Place entity referenced by both posts * * Check that the geomap popup of the place contains a link to the two posts. */ function testPlacePopupRelatedPosts() { // Create two posts. $post_id_1 = wl_create_post('', 'post-1', 'Post 1', 'publish', 'post'); $post_id_2 = wl_create_post('', 'post-2', 'Post 2', 'publish', 'post'); // Create a place- $place_id = wl_create_post("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); wl_set_entity_main_type($place_id, 'http://schema.org/Place'); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LATITUDE, 40.12, true); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 72.3, true); // Reference place from both posts- wl_core_add_relation_instance($post_id_1, WL_WHERE_RELATION, $place_id); wl_core_add_relation_instance($post_id_2, WL_WHERE_RELATION, $place_id); // Check referencing. $places = wl_shortcode_geomap_get_places($post_id_1); $this->assertCount(1, $places); $this->assertEquals($places[0]->ID, $place_id); // Check json formatted data. $response = wl_shortcode_geomap_prepare_map($places); // Check object attributes $poi = $response['features'][0]; $this->assertTrue(isset($poi)); $this->assertTrue(isset($poi['properties'])); $this->assertTrue(isset($poi['properties']['popupContent'])); // Check if popup contains links to the two posts $popup = $poi['properties']['popupContent']; $link1 = esc_attr(get_permalink($post_id_1)); $this->assertContains($link1, $popup); $link2 = esc_attr(get_permalink($post_id_2)); $this->assertContains($link2, $popup); // Check no thumbnail has been echoed $this->assertNotContains('<img', $popup); }