/** * Test that redundant checks work. * * @group Plugins */ public function testGeoIpUpdaterRedundantChecks() { GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::$providers = null; // create empty ISP & Org files $this->createEmptyISPOrgFiles(); // run redundant checks $updater = new Piwik_UserCountry_GeoIPAutoUpdater_publictest(); $updater->performRedundantDbChecks(); // check that files are renamed correctly $this->checkBrokenGeoIPState(); // create empty files again & run checks again $this->createEmptyISPOrgFiles(); $updater->performRedundantDbChecks(); // check that w/ broken files already there, redundant checks still work correctly $this->checkBrokenGeoIPState(); }
private function setLocationProvider($file) { GeoIp::$dbNames['loc'] = array($file); GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::$providers = null; LocationProvider::setCurrentProvider(self::GEOIP_IMPL_TO_TEST); if (LocationProvider::getCurrentProviderId() !== self::GEOIP_IMPL_TO_TEST) { throw new Exception("Failed to set the current location provider to '" . self::GEOIP_IMPL_TO_TEST . "'."); } $possibleFiles = GeoIp::$dbNames['loc']; if (GeoIp::getPathToGeoIpDatabase($possibleFiles) === false) { throw new Exception("The GeoIP location provider cannot find the '{$file}' file! Tests will fail."); } }
<?php /** * Proxy to normal piwik.php, but in testing mode * * - Use the tests database to record Tracking data * - Allows to overwrite the Visitor IP, and Server datetime * */ use Piwik\DataTable\Manager; use Piwik\Option; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Site; use Piwik\Tracker\Cache; use Piwik\Tracker; require realpath(dirname(__FILE__)) . "/includes.php"; // Wrapping the request inside ob_start() calls to ensure that the Test // calling us waits for the full request to process before unblocking ob_start(); try { Piwik_TestingEnvironment::addHooks(); GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files'; Tracker::setTestEnvironment(); Manager::getInstance()->deleteAll(); Option::clearCache(); Site::clearCache(); include PIWIK_INCLUDE_PATH . '/piwik.php'; } catch (Exception $ex) { echo "Unexpected error during tracking: " . $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n"; } ob_end_flush();
public function tearDown() { LocationProvider::$providers = null; GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files'; ManyVisitsWithGeoIP::unsetLocationProvider(); }