Merge branch 'w23_MDL-39503_m25_signup' of git://github.com/skodak/moodle into MOODLE...
[moodle.git] / iplookup / tests / geoplugin_test.php
blob5cf0ecc030bf56fc905f7c9757b952156608134e
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * GeoIP tests
20 * @package core_iplookup
21 * @category phpunit
22 * @copyright 2012 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 /**
30 * GeoIp data file parsing test.
32 class geoplugin_testcase extends advanced_testcase {
34 public function test_geoip() {
35 global $CFG;
36 require_once("$CFG->libdir/filelib.php");
37 require_once("$CFG->dirroot/iplookup/lib.php");
39 if (!PHPUNIT_LONGTEST) {
40 // we do not want to DDOS their server, right?
41 return;
44 $this->resetAfterTest();
46 $CFG->geoipfile = '';
48 $result = iplookup_find_location('147.230.16.1');
50 $this->assertEquals('array', gettype($result));
51 $this->assertEquals('Liberec', $result['city']);
52 $this->assertEquals(15.0653, $result['longitude'], '', 0.001);
53 $this->assertEquals(50.7639, $result['latitude'], '', 0.001);
54 $this->assertNull($result['error']);
55 $this->assertEquals('array', gettype($result['title']));
56 $this->assertEquals('Liberec', $result['title'][0]);
57 $this->assertEquals('Czech Republic', $result['title'][1]);