Skip to content

Commit

Permalink
Merge branch 'MDL-67593-master' of https://github.com/snake/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Dec 31, 2019
2 parents 53384db + dbf29da commit cba5ccc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 47 deletions.
Binary file added iplookup/tests/fixtures/GeoIP2-City-Test.mmdb
Binary file not shown.
10 changes: 10 additions & 0 deletions iplookup/tests/fixtures/README.txt
@@ -0,0 +1,10 @@
GeoIP2-City-Test.mmdb:
Copyright: maxmind (github.com/maxmind)

https://github.com/maxmind/MaxMind-DB/blob/master/test-data/GeoIP2-City-Test.mmdb

Licence: Creative Commons Attribution-ShareAlike 3.0 Unported License

http://creativecommons.org/licenses/by-sa/3.0/

No changes have been made to this file.
48 changes: 3 additions & 45 deletions iplookup/tests/geoip_test.php
Expand Up @@ -36,56 +36,15 @@
*/
class core_iplookup_geoip_testcase extends advanced_testcase {
public function setUp() {
if (!PHPUNIT_LONGTEST) {
// These tests are intensive and required downloads.
$this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
}

$this->resetAfterTest();
}


/**
* Setup the GeoIP2File system.
*/
public function setup_geoip2file() {
global $CFG;

// Store the file somewhere where it won't be wiped out..
$gzfile = "$CFG->dataroot/phpunit/geoip/GeoLite2-City.mmdb.gz";
check_dir_exists(dirname($gzfile));
if (file_exists($gzfile) and (filemtime($gzfile) < time() - 60*60*24*30)) {
// Delete file if older than 1 month.
unlink($gzfile);
}

if (!file_exists($gzfile)) {
download_file_content('http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz',
null, null, false, 300, 20, false, $gzfile);
}

$this->assertTrue(file_exists($gzfile));

$geoipfile = str_replace('.gz', '', $gzfile);

// Open our files (in binary mode).
$file = gzopen($gzfile, 'rb');
$geoipfilebuf = fopen($geoipfile, 'wb');

// Keep repeating until the end of the input file.
while (!gzeof($file)) {
// Read buffer-size bytes.
// Both fwrite and gzread and binary-safe.
fwrite($geoipfilebuf, gzread($file, 4096));
}

// Files are done, close files.
fclose($geoipfilebuf);
gzclose($file);

$this->assertTrue(file_exists($geoipfile));

$CFG->geoip2file = $geoipfile;
$CFG->geoip2file = "$CFG->dirroot/iplookup/tests/fixtures/GeoIP2-City-Test.mmdb";
}

/**
Expand Down Expand Up @@ -121,9 +80,8 @@ public function test_ip($ip) {
*/
public function ip_provider() {
return [
'IPv4: Sample suggested by maxmind themselves' => ['24.24.24.24'],
'IPv4: github.com' => ['192.30.255.112'],
'IPv6: UCLA' => ['2607:f010:3fe:fff1::ff:fe00:25'],
'IPv4: IPV4 test' => ['81.2.69.142'],
'IPv6: IPV6 test' => ['2001:252:1::1:1:1'],
];
}
}
2 changes: 1 addition & 1 deletion lang/en/admin.php
Expand Up @@ -256,7 +256,7 @@
$string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. The default value, "language", leaves it to the string "fullnamedisplay" in the current language pack to decide. Some languages have different name display conventions.
For most mono-lingual sites the most efficient setting is "firstname lastname", but you may choose to hide surnames altogether. Placeholders that can be used are: firstname, lastname, firstnamephonetic, lastnamephonetic, middlename, and alternatename.';
$string['configgeoipfile'] = 'Location of GeoLite2 City binary data file. This file is not part of Moodle distribution and must be obtained separately from <a href="https://www.maxmind.com/">MaxMind</a>. You can either buy a commercial version or use the free version. Simply download <a href="https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz" >https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz</a> and extract it into "{$a}" directory on your server.';
$string['configgeoipfile'] = 'Location of GeoLite2 City binary data file. This file is not part of Moodle distribution and must be obtained separately from <a href="https://www.maxmind.com/">MaxMind</a>. You can either buy a commercial version or use the free version. You\'ll need to register to download the City database file, which you can do at <a href="https://dev.maxmind.com/geoip/geoip2/geolite2/" >https://dev.maxmind.com/geoip/geoip2/geolite2/</a>. Once you\'ve registered and downloaded the file, extract it into "{$a}" directory on your server.';
$string['configgetremoteaddrconf'] = 'If your server is behind a reverse proxy, you can use this setting to specify which HTTP headers can be trusted to contain the remote IP address. The headers are read in order, using the first one that is available.';
$string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook. Users need to have at least one of these roles in a course to be shown in the gradebook for that course.';
$string['configgradeexport'] = 'Choose which gradebook export formats are your primary methods for exporting grades. Chosen plugins will then set and use a "last exported" field for every grade. For example, this might result in exported records being identified as being "new" or "updated". If you are not sure about this then leave everything unchecked.';
Expand Down
2 changes: 1 addition & 1 deletion lib/maxmind/readme_moodle.txt
Expand Up @@ -27,4 +27,4 @@ unzip v1.5.1.zip
mv GeoIP2-php-2.10.0/src/ /path/to/moodle/lib/maxmind/GeoIp2/
mv MaxMind-DB-Reader-php-1.5.1/src/MaxMind/ /path/to/moodle/lib/maxmind/MaxMind/

4) Run unit tests on iplookup/tests/geoip_test.php with PHPUNIT_LONGTEST defined.
4) Run unit tests on iplookup/tests/geoip_test.php.

0 comments on commit cba5ccc

Please sign in to comment.