function setUp()
 {
     parent::setUp();
     add_filter('geoip_detect_get_external_ip_adress', array($this, 'filter_set_test_ip'), 101);
     $this->assertEquals(GEOIP_DETECT_TEST_IP, geoip_detect_get_external_ip_adress());
     setlocale(LC_NUMERIC, 'C');
     // Set locale to always use . as decimal point
 }
 function testShortcode()
 {
     add_filter('geoip_detect_get_external_ip_adress', 'geoip_detect_get_external_ip_adress_test_set_test_ip', 101);
     $this->assertEquals(GEOIP_DETECT_TEST_IP, geoip_detect_get_external_ip_adress());
     $string = do_shortcode('[geoip_detect property="country_name"]');
     $this->assertNotEmpty($string, '[geoip_detect property="country_name"]', "The Geoip Detect shortcode did not generate any output");
     $this->assertNotEquals($string, '[geoip_detect property="country_name"]', "The Geoip Detect shortcode does not seem to be called");
     $this->assertNotContains('<!--', $string, "Geoip Detect shortcode threw an error: " . $string);
     $string = do_shortcode('[geoip_detect property="INVALID"]');
     $this->assertContains('<!--', $string, "Geoip Detect Shortcode threw no error in spite of invalid property name: " . $string);
 }
Example #3
0
/**
 * If no information was found, use the external IP of the server and try again.
 * This is necessary to allow local development servers to return sensical data.
 * 
 * @param geoiprecord $record Information found.
 * @return geoiprecord	Hopefully more accurate information. 
 */
function geoip_detect_add_external_ip($record)
{
    static $avoid_recursion = false;
    // Flag in order to retry only once
    if ($avoid_recursion) {
        return $record;
    }
    // This is the retry with the external adress, so don't do anything
    if (!is_object($record)) {
        $external_ip = geoip_detect_get_external_ip_adress();
        $avoid_recursion = true;
        $record = geoip_detect_get_info_from_ip($external_ip);
        $avoid_recursion = false;
    }
    return $record;
}