Merge branch 'MDL-36941_master-fix' of git://github.com/markn86/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 28 Mar 2018 15:39:40 +0000 (17:39 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 28 Mar 2018 16:42:18 +0000 (18:42 +0200)
1  2 
iplookup/tests/geoip_test.php
lib/db/upgrade.php

@@@ -88,42 -80,32 +88,42 @@@ class core_iplookup_geoip_testcase exte
          $CFG->geoip2file = $geoipfile;
      }
  
 -    public function test_ipv4() {
 -        $result = iplookup_find_location('192.30.255.112');
 -
 -        $this->assertEquals('array', gettype($result));
 -        $this->assertEquals('San Francisco', $result['city']);
 -        $this->assertEquals(-122.3933, $result['longitude'], 'Coordinates are out of accepted tolerance', 0.01);
 -        $this->assertEquals(37.7697, $result['latitude'], 'Coordinates are out of accepted tolerance', 0.01);
 +    /**
 +     * Test the format of data returned in the iplookup_find_location function.
 +     *
 +     * @dataProvider ip_provider
 +     * @param   string  $ip The IP to test
 +     */
 +    public function test_ip($ip) {
 +        $this->setup_geoip2file();
 +
 +        // Note: The results we get from the iplookup tests are beyond our control.
 +        // We used to check a specific IP to a known location, but these have become less reliable and change too
 +        // frequently to be used for testing.
 +
 +        $result = iplookup_find_location($ip);
 +
 +        $this->assertInternalType('array', $result);
 +        $this->assertInternalType('float', $result['latitude']);
 +        $this->assertInternalType('float', $result['longitude']);
 +        $this->assertInternalType('string', $result['city']);
 +        $this->assertInternalType('string', $result['country']);
 +        $this->assertInternalType('array', $result['title']);
 +        $this->assertInternalType('string', $result['title'][0]);
 +        $this->assertInternalType('string', $result['title'][1]);
          $this->assertNull($result['error']);
 -        $this->assertEquals('array', gettype($result['title']));
 -        $this->assertEquals('San Francisco', $result['title'][0]);
 -        $this->assertEquals('United States', $result['title'][1]);
      }
  
 -    public function test_ipv6() {
 -        // NOTE: these tests can be altered by the geoip dataset, there has been an attempt to get
 -        // a 'reliable' result.
 -
 -        $result = iplookup_find_location('2607:f010:3fe:fff1::ff:fe00:25');
 -
 -        $this->assertEquals('array', gettype($result));
 -        $this->assertEquals('Los Angeles', $result['city']);
 -        $this->assertEquals(-118.2987, $result['longitude'], 'Coordinates are out of accepted tolerance', 0.01);
 -        $this->assertEquals(33.7866, $result['latitude'], 'Coordinates are out of accepted tolerance', 0.01);
 -        $this->assertNull($result['error']);
 -        $this->assertEquals('array', gettype($result['title']));
 -        $this->assertEquals('Los Angeles', $result['title'][0]);
 -        $this->assertEquals('United States', $result['title'][1]);
 +    /**
 +     * Data provider for IP lookup test.
 +     *
 +     * @return array
 +     */
 +    public function ip_provider() {
 +        return [
 +            'IPv4: Sample suggested by maxmind themselves' => ['24.24.24.24'],
-             'IPv4: github.com' =>  ['192.30.255.112'],
++            'IPv4: github.com' => ['192.30.255.112'],
 +            'IPv6: UCLA' => ['2607:f010:3fe:fff1::ff:fe00:25'],
 +        ];
      }
  }
@@@ -2191,11 -2191,11 +2191,12 @@@ function xmldb_main_upgrade($oldversion
      }
  
      if ($oldversion < 2018032700.00) {
--
          // Update default search engine to search_simpledb if global search is disabled and there is no solr index defined.
          if (empty($CFG->enableglobalsearch) && empty(get_config('search_solr', 'indexname'))) {
              set_config('searchengine', 'simpledb');
          }
++
++        // Main savepoint reached.
          upgrade_main_savepoint(true, 2018032700.00);
      }