示例#1
0
 private function setTrackerConfig($trackerConfig)
 {
     $testingEnvironment = new TestingEnvironmentVariables();
     $testingEnvironment->overrideConfig('Tracker', $trackerConfig);
     $testingEnvironment->overrideConfig('log', 'log_writers', array('screen'));
     $testingEnvironment->save();
 }
示例#2
0
function setupRootContainer()
{
    // before running tests, delete the TestingEnvironmentVariables file, since it can indirectly mess w/
    // phpunit's class loading (if a test class is loaded in bootstrap.php, phpunit can't load it from a file,
    // so executing the tests in a file will fail)
    $vars = new TestingEnvironmentVariables();
    $vars->delete();
    Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator($vars));
    $rootTestEnvironment = new \Piwik\Application\Environment(null);
    $rootTestEnvironment->init();
}
示例#3
0
 public function setUp()
 {
     // drop all tables
     Db::dropAllTables();
     // download data dump if url supplied
     if (is_file($this->dumpUrl)) {
         $dumpPath = $this->dumpUrl;
     } else {
         $dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz';
         $bytesRead = $this->downloadDumpInPath($dumpPath);
         // sanity check
         if ($bytesRead <= 40 * 1024 * 1024) {
             $str = "Could not download sql dump! You can manually download %s into %s";
             throw new Exception(sprintf($str, $this->dumpUrl, $dumpPath));
         }
     }
     // unzip the dump
     if (substr($dumpPath, -3) === ".gz") {
         $deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql';
         // TODO: should depend on name of URL
         exec("gunzip -c \"" . $dumpPath . "\" > \"{$deflatedDumpPath}\"", $output, $return);
         if ($return !== 0) {
             throw new Exception("gunzip failed: " . implode("\n", $output));
         }
     } else {
         $deflatedDumpPath = $dumpPath;
     }
     // load the data into the correct database
     $user = Config::getInstance()->database['username'];
     $password = Config::getInstance()->database['password'];
     $host = Config::getInstance()->database['host'];
     Config::getInstance()->database['tables_prefix'] = $this->tablesPrefix;
     $cmd = "mysql -h \"{$host}\" -u \"{$user}\" \"--password={$password}\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1";
     exec($cmd, $output, $return);
     if ($return !== 0) {
         throw new Exception("Failed to load sql dump: " . implode("\n", $output));
     }
     // make sure archiving will be called
     Rules::setBrowserTriggerArchiving(true);
     // reload access
     Access::getInstance()->reloadAccess();
     $testVars = new TestingEnvironmentVariables();
     $testVars->configOverride = array('database' => array('tables_prefix' => $this->tablesPrefix));
     $testVars->save();
 }
 private function getPluginsToLoadDuringTest()
 {
     $plugins = $this->vars->getCoreAndSupportedPlugins();
     // make sure the plugin that executed this method is included in the plugins to load
     $extraPlugins = array_merge(self::$extraPluginsToLoad, $this->vars->pluginsToLoad ?: array(), array(Plugin::getPluginNameFromBacktrace(debug_backtrace()), Plugin::getPluginNameFromNamespace($this->vars->testCaseClass), Plugin::getPluginNameFromNamespace($this->vars->fixtureClass), Plugin::getPluginNameFromNamespace(get_called_class())));
     foreach ($extraPlugins as $pluginName) {
         if (empty($pluginName)) {
             continue;
         }
         if (in_array($pluginName, $plugins)) {
             continue;
         }
         $plugins[] = $pluginName;
     }
     return $plugins;
 }
 private function simulateInvalidTrackerRequest()
 {
     $testEnvironment = new TestingEnvironmentVariables();
     $testEnvironment->_triggerInvalidRequests = true;
     $testEnvironment->save();
 }
示例#6
0
 protected static function rememberCurrentlyInstalledPluginsAcrossRequests(TestingEnvironmentVariables $testEnvironment)
 {
     $plugins = self::getPluginManager()->getInstalledPluginsName();
     $testEnvironment->overrideConfig('PluginsInstalled', 'PluginsInstalled', $plugins);
     $testEnvironment->save();
 }
 private function resetTestingEnvironmentChanges()
 {
     $testingEnvironment = new TestingEnvironmentVariables();
     $testingEnvironment->_triggerTrackerFailure = null;
     $testingEnvironment->save();
 }
 private function setPiwikEnvironmentOverrides()
 {
     $env = new TestingEnvironmentVariables();
     $env->overrideConfig('Tracker', 'create_new_visit_when_website_referrer_changes', 1);
     $env->save();
 }