Exemplo n.º 1
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();
}
Exemplo n.º 2
0
 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();
     }
 }
Exemplo n.º 3
0
    define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
}
if (!defined('PIWIK_USER_PATH')) {
    define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
}
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
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) {
Exemplo n.º 4
0
 *  - Allows to overwrite the Visitor IP, and Server datetime
 *
 */
use Piwik\Application\Environment;
use Piwik\DataTable\Manager;
use Piwik\Option;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp;
use Piwik\Site;
use Piwik\Tests\Framework\TestingEnvironmentManipulator;
use Piwik\Tests\Framework\TestingEnvironmentVariables;
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 {
    $globalObservers = array(array('Environment.bootstrapped', function () {
        Tracker::setTestEnvironment();
        Manager::getInstance()->deleteAll();
        Option::clearCache();
        Site::clearCache();
    }));
    Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers));
    GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
    include PIWIK_INCLUDE_PATH . '/piwik.php';
} catch (Exception $ex) {
    echo "Unexpected error during tracking: " . $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n";
}
if (ob_get_level() > 1) {
    ob_end_flush();
}