Skip to content

Commit 336f508

Browse files
author
Benjamin Pick
committed
check redirection [ci skip]
1 parent c1eec6c commit 336f508

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

tests/test-updater.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class UpdateTest extends WP_UnitTestCase_GeoIP_Detect {
55
function set_up() {
66
parent::set_up();
77

8-
add_filter('pre_option_geoip-detect-auto_license_key', [ $this, 'filter_set_user_secret' ], 101);
9-
108
// unlink uploads file if exists
119
if (function_exists('geoip_detect_get_database_upload_filename')) {
1210
$filename = geoip_detect_get_database_upload_filename();
@@ -17,10 +15,16 @@ function set_up() {
1715

1816
function tear_down() {
1917
remove_filter('pre_option_geoip-detect-auto_license_key', [ $this, 'filter_set_user_secret' ], 101);
18+
remove_filter('pre_option_geoip-detect-auto_license_key', [ $this, 'filter_set_invalid_user_secret' ], 100);
19+
remove_filter('geoip_detect2_download_url', [ $this, 'filter_set_test_file' ], 101);
2020

2121
parent::tear_down();
2222
}
2323

24+
function filter_set_invalid_user_secret() {
25+
return 'bla';
26+
}
27+
2428
function filter_set_user_secret() {
2529
$id = getenv('WP_MAXMIND_USER_SECRET');
2630
if ($id)
@@ -30,11 +34,21 @@ function filter_set_user_secret() {
3034
return 'asdfsadf';
3135
}
3236
}
37+
38+
function filter_set_test_file() {
39+
// Yes, use http instead of https to test redirect
40+
return 'http://github.com/yellowtree/geoip-detect/raw/develop/tests/GeoLite2-Country.mmdb.tar.gz';
41+
}
3342

3443
/**
3544
* @group external-http
3645
*/
3746
function testUpdate() {
47+
add_filter('pre_option_geoip-detect-auto_license_key', [ $this, 'filter_set_user_secret' ], 101);
48+
$this->assertUpdateWorks();
49+
}
50+
51+
function assertUpdateWorks() {
3852
$s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource();
3953

4054
$this->assertTrue( $s->maxmindUpdate(true) );
@@ -43,4 +57,14 @@ function testUpdate() {
4357
$record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP);
4458
$this->assertValidGeoIP2Record($record, GEOIP_DETECT_TEST_IP);
4559
}
60+
61+
/**
62+
* @group external-http
63+
*/
64+
function testUpdateWithTestFile() {
65+
add_filter('pre_option_geoip-detect-auto_license_key', [ $this, 'filter_set_invalid_user_secret' ], 100);
66+
add_filter('geoip_detect2_download_url', [ $this, 'filter_set_test_file' ], 101);
67+
$this->assertUpdateWorks();
68+
}
69+
4670
}

0 commit comments

Comments
 (0)