Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         Url::setHost('localhost');
     }
     $fixture = $this->createFixture($input);
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
 }
Beispiel #2
0
 public function setUp()
 {
     parent::setup();
     File::reset();
     Url::setHost(false);
     $this->output = new Output('myid');
 }
Beispiel #3
0
 /**
  * @param InputInterface $input
  */
 protected function initHostAndQueryString(InputInterface $input)
 {
     $_GET = array();
     $hostname = $input->getOption('piwik-domain');
     Url::setHost($hostname);
     $query = $input->getArgument('url-query');
     $query = UrlHelper::getArrayFromQueryString($query);
     foreach ($query as $name => $value) {
         $_GET[$name] = $value;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!defined('PIWIK_TEST_MODE')) {
         define('PIWIK_TEST_MODE', true);
     }
     Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables()));
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     if (Config::getInstance()->database_tests['tables_prefix'] !== '') {
         throw new \Exception("To generate OmniFixture for the UI tests, you must set an empty tables_prefix in [database_tests]");
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         $host = 'localhost';
         Url::setHost('localhost');
     }
     $configDomainToSave = $input->getOption('save-config');
     if (!empty($configDomainToSave)) {
         $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php';
         if (!file_exists($pathToDomainConfig)) {
             link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig);
         }
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $fixture = $this->createFixture($input, $allowSave = !empty($configDomainToSave));
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
     if (!empty($configDomainToSave)) {
         Config::getInstance()->forceSave();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles($input);
     $this->setIncludePathAsInTestBootstrap();
     $host = Url::getHost();
     if (empty($host)) {
         $host = 'localhost';
         Url::setHost('localhost');
     }
     $configDomainToSave = $input->getOption('save-config');
     if (!empty($configDomainToSave)) {
         $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php';
         if (!file_exists($pathToDomainConfig)) {
             link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig);
         }
     }
     $fixture = $this->createFixture($input);
     $this->setupDatabaseOverrides($input, $fixture);
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $fixture->getTestEnvironment()->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         $this->createSymbolicLinksForUITests();
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
     $sqlDumpPath = $input->getOption('sqldump');
     if ($sqlDumpPath) {
         $this->createSqlDump($sqlDumpPath, $output);
     }
     if (!empty($configDomainToSave)) {
         Config::getInstance()->forceSave();
     }
 }
 public function beforeContainerCreated()
 {
     $this->vars->reload();
     if ($this->vars->queryParamOverride) {
         foreach ($this->vars->queryParamOverride as $key => $value) {
             $_GET[$key] = $value;
         }
     }
     if ($this->vars->globalsOverride) {
         foreach ($this->vars->globalsOverride as $key => $value) {
             $GLOBALS[$key] = $value;
         }
     }
     if ($this->vars->hostOverride) {
         \Piwik\Url::setHost($this->vars->hostOverride);
     }
     if ($this->vars->useXhprof) {
         \Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
     }
     \Piwik\Cache\Backend\File::$invalidateOpCacheBeforeRead = true;
 }
Beispiel #7
0
 protected function initPiwikHost(InputInterface $input)
 {
     $piwikHostname = $input->getParameterOption('--piwik-domain');
     if (empty($piwikHostname)) {
         $piwikHostname = $input->getParameterOption('--url');
     }
     $piwikHostname = UrlHelper::getHostFromUrl($piwikHostname);
     Url::setHost($piwikHostname);
 }
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "/index.php";
if (!Common::isPhpCliMode()) {
    return;
}
$testmode = in_array('--testmode', $_SERVER['argv']);
if ($testmode) {
    define('PIWIK_TEST_MODE', true);
    Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables()));
}
function getPiwikDomain()
{
    foreach ($_SERVER['argv'] as $param) {
        $pattern = '--piwik-domain=';
        if (false !== strpos($param, $pattern)) {
            return substr($param, strlen($pattern));
        }
    }
    return null;
}
$environment = new Environment('cli');
$environment->init();
$piwikDomain = getPiwikDomain();
if ($piwikDomain) {
    Url::setHost($piwikDomain);
}
$token = Db::get()->fetchOne("SELECT token_auth\n                              FROM " . Common::prefixTable("user") . "\n                              WHERE superuser_access = 1\n                              ORDER BY date_registered ASC");
$filename = $environment->getContainer()->get('path.tmp') . '/cache/token.php';
$content = "<?php exit; //\t" . $token;
file_put_contents($filename, $content);
echo $filename;
Beispiel #9
0
 /**
  * Checks the config file is found.
  *
  * @param $piwikUrl
  * @throws Exception
  */
 protected function initConfigObject($piwikUrl)
 {
     // HOST is required for the Config object
     $parsed = parse_url($piwikUrl);
     Url::setHost($parsed['host']);
     Config::getInstance()->clear();
     try {
         Config::getInstance()->checkLocalConfigFound();
     } catch (Exception $e) {
         throw new Exception("The configuration file for Piwik could not be found. " . "Please check that config/config.ini.php is readable by the user " . get_current_user());
     }
 }
Beispiel #10
0
 public function setUp()
 {
     \Piwik\Url::setHost(false);
     $this->output = new Output('myid');
 }
Beispiel #11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $serverGlobal = $input->getOption('server-global');
     if ($serverGlobal) {
         $_SERVER = json_decode($serverGlobal, true);
     }
     $this->requireFixtureFiles();
     $this->setIncludePathAsInTestBootstrap();
     $file = $input->getOption('file');
     if ($file) {
         if (is_file($file)) {
             require_once $file;
         } else {
             if (is_file(PIWIK_INCLUDE_PATH . '/' . $file)) {
                 require_once PIWIK_INCLUDE_PATH . '/' . $file;
             } else {
                 throw new \Exception("Cannot find --file option file '{$file}'.");
             }
         }
     }
     $host = Url::getHost();
     if (empty($host)) {
         Url::setHost('localhost');
     }
     // get the fixture class
     $fixtureClass = $input->getArgument('fixture');
     if (class_exists("Piwik\\Tests\\Fixtures\\" . $fixtureClass)) {
         $fixtureClass = "Piwik\\Tests\\Fixtures\\" . $fixtureClass;
     }
     if (!class_exists($fixtureClass)) {
         throw new \Exception("Cannot find fixture class '{$fixtureClass}'.");
     }
     // create the fixture
     $fixture = new $fixtureClass();
     $fixture->printToScreen = true;
     $dbName = $input->getOption('db-name');
     if ($dbName) {
         $fixture->dbName = $dbName;
     }
     if ($input->getOption('persist-fixture-data')) {
         $fixture->persistFixtureData = true;
     }
     if ($input->getOption('drop')) {
         $fixture->resetPersistedFixture = true;
     }
     $extraPluginsToLoad = $input->getOption('plugins');
     if ($extraPluginsToLoad) {
         $fixture->extraPluginsToLoad = explode(',', $extraPluginsToLoad);
     }
     if ($fixture->createConfig) {
         Config::getInstance()->setTestEnvironment();
     }
     $fixture->createConfig = false;
     // setup database overrides
     $testingEnvironment = $fixture->getTestEnvironment();
     $optionsToOverride = array('dbname' => $fixture->getDbName(), 'host' => $input->getOption('db-host'), 'user' => $input->getOption('db-user'), 'password' => $input->getOption('db-pass'));
     foreach ($optionsToOverride as $configOption => $value) {
         if ($value) {
             $configOverride = $testingEnvironment->configOverride;
             $configOverride['database_tests'][$configOption] = $configOverride['database'][$configOption] = $value;
             $testingEnvironment->configOverride = $configOverride;
             Config::getInstance()->database[$configOption] = $value;
         }
     }
     // perform setup and/or teardown
     if ($input->getOption('teardown')) {
         $testingEnvironment->save();
         $fixture->performTearDown();
     } else {
         $fixture->performSetUp();
     }
     if ($input->getOption('set-phantomjs-symlinks')) {
         // make sure symbolic links exist (phantomjs doesn't support symlink-ing yet)
         foreach (array('libs', 'plugins', 'tests', 'piwik.js') as $linkName) {
             $linkPath = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/' . $linkName;
             if (!file_exists($linkPath)) {
                 symlink(PIWIK_INCLUDE_PATH . '/' . $linkName, $linkPath);
             }
         }
     }
     $this->writeSuccessMessage($output, array("Fixture successfully setup!"));
 }