See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
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. 13 // 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/>. 16 17 /** 18 * GeoIP tests 19 * 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 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * GeoIp data file parsing test. 31 */ 32 class core_iplookup_geoplugin_testcase extends advanced_testcase { 33 34 /** 35 * Load required test libraries 36 */ 37 public static function setUpBeforeClass(): void { 38 global $CFG; 39 require_once("{$CFG->dirroot}/iplookup/lib.php"); 40 } 41 42 /** 43 * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php 44 */ 45 public function setUp() { 46 if (!PHPUNIT_LONGTEST) { 47 $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); 48 } 49 } 50 51 /** 52 * Test IPv4 address 53 * 54 * @covers ::iplookup_find_location 55 */ 56 public function test_ipv4(): void { 57 $result = iplookup_find_location('50.0.184.0'); 58 59 $this->assertInternalType('array', $result); 60 $this->assertInternalType('float', $result['latitude']); 61 $this->assertInternalType('float', $result['longitude']); 62 $this->assertInternalType('string', $result['city']); 63 $this->assertInternalType('string', $result['country']); 64 $this->assertInternalType('array', $result['title']); 65 $this->assertInternalType('string', $result['title'][0]); 66 $this->assertInternalType('string', $result['title'][1]); 67 $this->assertNull($result['error']); 68 } 69 70 /** 71 * Test IPv6 address (unsupported by Geoplugin) 72 * 73 * @covers ::iplookup_find_location 74 */ 75 public function test_ipv6(): void { 76 $result = iplookup_find_location('2a01:8900:2:3:8c6c:c0db:3d33:9ce6'); 77 $this->assertEquals($result['error'], get_string('invalidipformat', 'error')); 78 } 79 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body