示例#1
0
 /**
  * @group Core
  */
 public function testGetOption()
 {
     // empty table, expect false (i.e., not found)
     $this->assertFalse(Option::get('anonymous_defaultReport'));
     // populate table, expect '1' (i.e., found)
     Db::query("INSERT INTO `" . Common::prefixTable('option') . "` VALUES ('anonymous_defaultReport', '1',true)");
     $this->assertSame('1', Option::get('anonymous_defaultReport'));
     // delete row (bypassing API), expect '1' (i.e., from cache)
     Db::query("DELETE FROM `" . Common::prefixTable('option') . "` WHERE option_name = ?", array('anonymous_defaultReport'));
     $this->assertSame('1', Option::get('anonymous_defaultReport'));
     // force cache reload, expect false (i.e., not found)
     Option::clearCache();
     $this->assertFalse(Option::get('anonymous_defaultReport'));
 }
示例#2
0
文件: piwik.php 项目: a4tunado/piwik
<?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();
示例#3
0
 public static function updateDatabase($force = false)
 {
     Cache::deleteTrackerCache();
     Option::clearCache();
     if ($force) {
         // remove version options to force update
         Option::deleteLike('version%');
         Option::set('version_core', '0.0');
     }
     $updater = new Updater();
     $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
     if (empty($componentsWithUpdateFile)) {
         return false;
     }
     $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile);
     if (!empty($result['coreError']) || !empty($result['warnings']) || !empty($result['errors'])) {
         throw new \Exception("Failed to update database (errors or warnings found): " . print_r($result, true));
     }
     return $result;
 }
示例#4
0
 public function tearDown()
 {
     parent::tearDown();
     Manager::getInstance()->deleteAll();
     Option::clearCache();
     Site::clearCache();
     Cache::deleteTrackerCache();
     ArchiveTableCreator::clear();
     $tempTableName = Common::prefixTable(LogDataPurger::TEMP_TABLE_NAME);
     Db::query("DROP TABLE IF EXISTS " . $tempTableName);
 }
 private function resetDatabase()
 {
     Option::clearCache();
     Db::destroyDatabaseObject();
 }
示例#6
0
 public function performTearDown()
 {
     // Note: avoid run SQL in the *tearDown() metohds because it randomly fails on Travis CI
     // with error Error while sending QUERY packet. PID=XX
     $this->tearDown();
     self::unloadAllPlugins();
     if ($this->dropDatabaseInTearDown) {
         $this->dropDatabase();
     }
     DataTableManager::getInstance()->deleteAll();
     Option::clearCache();
     Site::clearCache();
     Cache::deleteTrackerCache();
     Config::getInstance()->clear();
     ArchiveTableCreator::clear();
     \Piwik\Plugins\ScheduledReports\API::$cache = array();
     \Piwik\Registry::unsetInstance();
     \Piwik\EventDispatcher::getInstance()->clearAllObservers();
     $_GET = $_REQUEST = array();
     Translate::unloadEnglishTranslation();
 }