From 49aed6f6ca5f5e8ba0c837161f9f97923315619d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 10 Jan 2020 16:31:27 -0300 Subject: [PATCH] Remove alternatives for deprecated methods --- includes/class-wc-geolocation.php | 4 +- .../class-wc-tests-geolite-integration.php | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/unit-tests/geolocation/class-wc-tests-geolite-integration.php diff --git a/includes/class-wc-geolocation.php b/includes/class-wc-geolocation.php index 6cb98138021..b770c169f5f 100644 --- a/includes/class-wc-geolocation.php +++ b/includes/class-wc-geolocation.php @@ -177,7 +177,7 @@ class WC_Geolocation { * @return string */ public static function get_local_database_path( $deprecated = '2' ) { - wc_deprecated_function( 'WC_Geolocation::get_local_database_path', '3.9.0', 'WC_Integration_MaxMind_Database_Service::get_database_path' ); + wc_deprecated_function( 'WC_Geolocation::get_local_database_path', '3.9.0' ); $integration = wc()->integrations->get_integration( 'maxmind_geolocation' ); return $integration->get_database_service()->get_database_path(); } @@ -189,7 +189,7 @@ class WC_Geolocation { * Extract files with PharData. Tool built into PHP since 5.3. */ public static function update_database() { - wc_deprecated_function( 'WC_Geolocation::update_database', '3.9.0', 'WC_Integration_MaxMind_Geolocation::update_database' ); + wc_deprecated_function( 'WC_Geolocation::update_database', '3.9.0' ); $integration = wc()->integrations->get_integration( 'maxmind_geolocation' ); $integration->update_database(); } diff --git a/tests/unit-tests/geolocation/class-wc-tests-geolite-integration.php b/tests/unit-tests/geolocation/class-wc-tests-geolite-integration.php new file mode 100644 index 00000000000..92a92c32417 --- /dev/null +++ b/tests/unit-tests/geolocation/class-wc-tests-geolite-integration.php @@ -0,0 +1,43 @@ +integrations->get_integration( 'maxmind_geolocation' ); + $integration->update_database(); + + // Download GeoLite2 database. + WC_Geolocation::update_database(); + + // OpenDNS IP address. + $ipv4 = '208.67.220.220'; + $ipv6 = '2620:0:ccc::2'; + + // Init GeoLite. + $geolite = new WC_Geolite_Integration( WC_Geolocation::get_local_database_path() ); + + // Check for IPv4. + $this->assertEquals( 'US', $geolite->get_country_iso( $ipv4 ) ); + + // Check for IPv6. + $this->assertEquals( 'US', $geolite->get_country_iso( $ipv6 ) ); + + // Check for non-valid IP. + $this->assertEquals( '', $geolite->get_country_iso( 'foobar' ) ); + } +}