public function setUp() { parent::setUp(); \Piwik\Plugin\Manager::getInstance()->loadPlugin('SegmentEditor'); \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins(); // setup the access layer FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a Super User by default FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; APISitesManager::getInstance()->addSite('test', 'http://example.org'); }
public function setUp() { parent::setUp(); \Piwik\Plugin\Manager::getInstance()->loadPlugin('UsersManager'); \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins(); // setup the access layer FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a Super User by default FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; $this->api = API::getInstance(); $this->model = Factory::getModel('Piwik\\Plugins\\UsersManager'); }
public function performSetUp($setupEnvironmentOnly = false) { // TODO: don't use static var, use test env var for this TestingEnvironmentManipulator::$extraPluginsToLoad = $this->extraPluginsToLoad; $this->dbName = $this->getDbName(); if ($this->persistFixtureData) { $this->dropDatabaseInSetUp = false; $this->dropDatabaseInTearDown = false; $this->overwriteExisting = false; $this->removeExistingSuperUser = false; } $testEnv = $this->getTestEnvironment(); $testEnv->testCaseClass = $this->testCaseClass; $testEnv->fixtureClass = get_class($this); $testEnv->dbName = $this->dbName; $testEnv->extraDiEnvironments = $this->extraDiEnvironments; foreach ($this->extraTestEnvVars as $name => $value) { $testEnv->{$name} = $value; } $testEnv->save(); $this->createEnvironmentInstance(); if ($this->dbName === false) { // must be after test config is created $this->dbName = self::getConfig()->database['dbname']; } try { static::connectWithoutDatabase(); if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) { $this->dropDatabase(); } DbHelper::createDatabase($this->dbName); DbHelper::disconnectDatabase(); Tracker::disconnectCachedDbConnection(); // reconnect once we're sure the database exists self::getConfig()->database['dbname'] = $this->dbName; Db::createDatabaseObject(); Db::get()->query("SET wait_timeout=28800;"); DbHelper::createTables(); self::getPluginManager()->unloadPlugins(); } catch (Exception $e) { static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); } include "DataFiles/Providers.php"; if (!$this->isFixtureSetUp()) { DbHelper::truncateAllTables(); } // We need to be SU to create websites for tests Access::getInstance()->setSuperUserAccess(); Cache::deleteTrackerCache(); self::resetPluginsInstalledConfig(); $testEnvironment = $this->getTestEnvironment(); static::loadAllPlugins($testEnvironment, $this->testCaseClass, $this->extraPluginsToLoad); self::updateDatabase(); self::installAndActivatePlugins($testEnvironment); $_GET = $_REQUEST = array(); $_SERVER['HTTP_REFERER'] = ''; FakeAccess::$superUserLogin = '******'; File::$invalidateOpCacheBeforeRead = true; if ($this->configureComponents) { IPAnonymizer::deactivate(); $dntChecker = new DoNotTrackHeaderChecker(); $dntChecker->deactivate(); } if ($this->createSuperUser) { self::createSuperUser($this->removeExistingSuperUser); if (!Access::getInstance() instanceof FakeAccess) { $this->loginAsSuperUser(); } APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); } SettingsPiwik::overwritePiwikUrl(self::getTestRootUrl()); if ($setupEnvironmentOnly) { return; } PiwikCache::getTransientCache()->flushAll(); if ($this->overwriteExisting || !$this->isFixtureSetUp()) { $this->setUp(); $this->markFixtureSetUp(); $this->log("Database {$this->dbName} marked as successfully set up."); } else { $this->log("Using existing database {$this->dbName}."); } }
private function setSuperUser() { FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; $this->createSettings(); }
} }), 'Piwik\\Config' => DI\decorate(function ($previous, ContainerInterface $c) { $testingEnvironment = $c->get('Piwik\\Tests\\Framework\\TestingEnvironmentVariables'); $dontUseTestConfig = $c->get('test.vars.dontUseTestConfig'); if (!$dontUseTestConfig) { $settingsProvider = $c->get('Piwik\\Application\\Kernel\\GlobalSettingsProvider'); return new TestConfig($settingsProvider, $testingEnvironment, $allowSave = false, $doSetTestEnvironment = true); } else { return $previous; } }), 'Piwik\\Access' => DI\decorate(function ($previous, ContainerInterface $c) { $testUseMockAuth = $c->get('test.vars.testUseMockAuth'); if ($testUseMockAuth) { $access = new FakeAccess(); FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; return $access; } else { return $previous; } }), 'observers.global' => DI\add(array(array('AssetManager.getStylesheetFiles', function (&$stylesheets) { $useOverrideCss = \Piwik\Container\StaticContainer::get('test.vars.useOverrideCss'); if ($useOverrideCss) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; } }), array('AssetManager.getJavaScriptFiles', function (&$jsFiles) { $useOverrideJs = \Piwik\Container\StaticContainer::get('test.vars.useOverrideJs'); if ($useOverrideJs) { $jsFiles[] = 'tests/resources/screenshot-override/override.js'; } }), array('Updater.checkForUpdates', function () {