function test_user_import_fields() { // This test calls geocoding services, but allows for failure global $geo_mashup_options; $geo_mashup_options->set_valid_options(array('overall' => array('import_custom_field' => 'geo'))); GeoMashupDB::add_geodata_sync_hooks(); $user_id = $this->factory->user->create(); $this->assertEmpty(GeoMashupDB::get_object_location('user', $user_id)); update_user_meta($user_id, 'geo', 'Paris, France'); $error = get_user_meta($user_id, 'geocoding_error', true); if ($error) { // If we can't geocode, no location is saved $this->assertEmpty(GeoMashupDB::get_object_location('user', $user_id)); } else { $location = GeoMashupDB::get_object_location('user', $user_id); $this->assertEquals(48, intval($location->lat)); $this->assertEquals(2, intval($location->lng)); // A second update overwrites if successful update_user_meta($user_id, 'geo', 'Paris, Texas'); $error = get_user_meta($user_id, 'geocoding_error', true); if ($error) { // Failed geocoding due to lack of internet leaves the first result $location = GeoMashupDB::get_object_location('user', $user_id); $this->assertEquals(48, intval($location->lat), $error); $this->assertEquals(2, intval($location->lng), $error); } else { // Location is updated to Paris, TX $location = GeoMashupDB::get_object_location('user', $user_id); $this->assertEquals(33, intval($location->lat)); $this->assertEquals(-95, intval($location->lng)); } } }