Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea -...
17
namespace core;
-
 
18
 
-
 
19
defined('MOODLE_INTERNAL') || die();
-
 
20
 
-
 
21
global $CFG;
-
 
22
 
-
 
23
require_once("{$CFG->libdir}/filelib.php");
-
 
24
require_once("{$CFG->dirroot}/iplookup/lib.php");
-
 
25
 
17
namespace core;
26
 
18
 
27
/**
19
/**
28
 * GeoIp data file parsing test.
20
 * GeoIp data file parsing test.
29
 *
21
 *
30
 * @package    core
22
 * @package    core
31
 * @category   test
23
 * @category   test
32
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
24
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
26
 */
34
 */
27
final class geoip_test extends \advanced_testcase {
-
 
28
    #[\Override]
-
 
29
    public static function setUpBeforeClass(): void {
35
class geoip_test extends \advanced_testcase {
30
        global $CFG;
-
 
31
 
-
 
32
        parent::setUpBeforeClass();
-
 
33
 
36
    public function setUp(): void {
34
        require_once("{$CFG->libdir}/filelib.php");
Línea 37... Línea 35...
37
        $this->resetAfterTest();
35
        require_once("{$CFG->dirroot}/iplookup/lib.php");
38
    }
36
    }
39
 
37
 
40
    /**
38
    /**
41
     * Setup the GeoIP2File system.
39
     * Setup the GeoIP2File system.
42
     */
40
     */
43
    public function setup_geoip2file() {
41
    public function setup_geoip2file(): void {
Línea 44... Línea 42...
44
        global $CFG;
42
        global $CFG;
Línea 50... Línea 48...
50
     *
48
     *
51
     * @dataProvider ip_provider
49
     * @dataProvider ip_provider
52
     * @param   string  $ip The IP to test
50
     * @param   string  $ip The IP to test
53
     */
51
     */
54
    public function test_ip($ip): void {
52
    public function test_ip($ip): void {
-
 
53
        global $CFG;
-
 
54
        if (!defined('TEST_GEOIP_APIKEY') || empty(TEST_GEOIP_APIKEY)) {
-
 
55
            $this->markTestSkipped('External geo tests are disabled.');
-
 
56
        }
-
 
57
        $this->resetAfterTest();
-
 
58
        $CFG->geopluginapikey = TEST_GEOIP_APIKEY;
55
        $this->setup_geoip2file();
59
        $this->setup_geoip2file();
Línea 56... Línea 60...
56
 
60
 
57
        // Note: The results we get from the iplookup tests are beyond our control.
61
        // Note: The results we get from the iplookup tests are beyond our control.
58
        // We used to check a specific IP to a known location, but these have become less reliable and change too
62
        // We used to check a specific IP to a known location, but these have become less reliable and change too
Línea 74... Línea 78...
74
    /**
78
    /**
75
     * Data provider for IP lookup test.
79
     * Data provider for IP lookup test.
76
     *
80
     *
77
     * @return array
81
     * @return array
78
     */
82
     */
79
    public function ip_provider() {
83
    public static function ip_provider(): array {
80
        return [
84
        return [
81
            'IPv4: IPV4 test' => ['81.2.69.142'],
85
            'IPv4: IPV4 test' => ['81.2.69.142'],
82
            'IPv6: IPV6 test' => ['2001:252:1::1:1:1'],
86
            'IPv6: IPV6 test' => ['2001:252:1::1:1:1'],
83
        ];
87
        ];
84
    }
88
    }