diff options
Diffstat (limited to 'plugins/UserCountry/tests/Unit/UserCountryTest.php')
-rw-r--r-- | plugins/UserCountry/tests/Unit/UserCountryTest.php | 122 |
1 files changed, 1 insertions, 121 deletions
diff --git a/plugins/UserCountry/tests/Unit/UserCountryTest.php b/plugins/UserCountry/tests/Unit/UserCountryTest.php index b28c5fc9d1..8f624c6ab4 100644 --- a/plugins/UserCountry/tests/Unit/UserCountryTest.php +++ b/plugins/UserCountry/tests/Unit/UserCountryTest.php @@ -10,11 +10,6 @@ namespace Piwik\Plugins\UserCountry\tests\Unit; use Piwik\Container\StaticContainer; use Piwik\Intl\Data\Provider\RegionDataProvider; -use Piwik\Plugins\UserCountry\GeoIPAutoUpdater; -use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; -use Piwik\Plugins\UserCountry\LocationProvider; -use Exception; -use Piwik\Tests\Framework\Fixture; require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/UserCountry.php'; require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; @@ -73,119 +68,4 @@ class UserCountryTest extends \PHPUnit\Framework\TestCase $this->assertArrayHasKey($country, $countries, $filename); } } - - /** - * 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(); - } - - /** - * @group Plugins - * - * @dataProvider getInvalidGeoIpUrlsToTest - */ - public function testGeoIpDownloadInvalidUrl($url) - { - // unset translations, otherwise Exception message will be translated - Fixture::resetTranslations(); - - $updater = new Piwik_UserCountry_GeoIPAutoUpdater_publictest(); - try { - $updater->downloadFile('loc', $url); - $this->fail("Downloading invalid url succeeded!"); - } catch (Exception $ex) { - $this->assertEquals("UserCountry_UnsupportedArchiveType", $ex->getMessage()); - } - } - - public function getInvalidGeoIpUrlsToTest() - { - return array(array("http://localhost/tests/resources/geoip.tar"), - array("http://localhost/tests/resources/geoip.tar.bz2"), - array("http://localhost/tests/resources/geoip.dat")); - } - - public function setUp() - { - // empty - } - - public function tearDown() - { - $geoIpDirPath = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files'; - $filesToRemove = array('GeoIPISP.dat.broken', 'GeoIPOrg.dat.broken', 'GeoIPISP.dat', 'GeoIPOrg.dat'); - - foreach ($filesToRemove as $name) { - $path = $geoIpDirPath . '/' . $name; - if (file_exists($path)) { - @unlink($path); - } - } - } - - private function createEmptyISPOrgFiles() - { - $geoIpDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files'; - - $fd = fopen($geoIpDir . '/GeoIPISP.dat', 'w'); - fclose($fd); - - $fd = fopen($geoIpDir . '/GeoIPOrg.dat', 'w'); - fclose($fd); - } - - private function checkBrokenGeoIPState() - { - $geoIpDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files'; - - $this->assertFalse(file_exists($geoIpDir . '/GeoIPCity.dat.broken')); - - $this->assertFalse(file_exists($geoIpDir . '/GeoIPISP.dat')); - $this->assertTrue(file_exists($geoIpDir . '/GeoIPISP.dat.broken')); - - $this->assertFalse(file_exists($geoIpDir . '/GeoIPOrg.dat')); - $this->assertTrue(file_exists($geoIpDir . '/GeoIPOrg.dat.broken')); - } -} - -class Piwik_UserCountry_GeoIPAutoUpdater_publictest extends GeoIPAutoUpdater -{ - public function __construct() - { - // empty - } - - // during tests do not call the Log::error or they will be displayed in the output - public function performRedundantDbChecks($logErrors = false) - { - parent::performRedundantDbChecks($logErrors); - } - - public function downloadFile($type, $url) - { - parent::downloadFile($type, $url); - } -} +}
\ No newline at end of file |