示例#1
0
 public function setUp()
 {
     parent::setUp();
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('SegmentEditor');
     \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
     // setup the access layer
     $pseudoMockAccess = new FakeAccess();
     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 = '******';
     Access::setSingletonInstance($pseudoMockAccess);
     APISitesManager::getInstance()->addSite('test', 'http://example.org');
 }
示例#2
0
 public function setUp()
 {
     parent::setUp();
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('UsersManager');
     \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
     // setup the access layer
     $pseudoMockAccess = new FakeAccess();
     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 = '******';
     Access::setSingletonInstance($pseudoMockAccess);
     $this->api = API::getInstance();
     $this->model = new Model();
 }
示例#3
0
 public function performSetUp($setupEnvironmentOnly = false)
 {
     try {
         if ($this->createConfig) {
             Config::getInstance()->setTestEnvironment();
         }
         $this->dbName = $this->getDbName();
         if ($this->persistFixtureData) {
             $this->dropDatabaseInSetUp = false;
             $this->dropDatabaseInTearDown = false;
             $this->overwriteExisting = false;
             $this->removeExistingSuperUser = false;
             Config::getInstance()->database_tests['dbname'] = Config::getInstance()->database['dbname'] = $this->dbName;
             $this->getTestEnvironment()->dbName = $this->dbName;
         }
         if ($this->dbName === false) {
             // must be after test config is created
             $this->dbName = Config::getInstance()->database['dbname'];
         }
         static::connectWithoutDatabase();
         if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) {
             $this->dropDatabase();
         }
         DbHelper::createDatabase($this->dbName);
         DbHelper::disconnectDatabase();
         // reconnect once we're sure the database exists
         Config::getInstance()->database['dbname'] = $this->dbName;
         Db::createDatabaseObject();
         DbHelper::createTables();
         \Piwik\Plugin\Manager::getInstance()->unloadPlugins();
     } catch (Exception $e) {
         static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString());
     }
     include "DataFiles/SearchEngines.php";
     include "DataFiles/Socials.php";
     include "DataFiles/Languages.php";
     include "DataFiles/Countries.php";
     include "DataFiles/Currencies.php";
     include "DataFiles/LanguageToCountry.php";
     include "DataFiles/Providers.php";
     if (!$this->isFixtureSetUp()) {
         DbHelper::truncateAllTables();
     }
     static::createAccessInstance();
     // We need to be SU to create websites for tests
     Piwik::setUserHasSuperUserAccess();
     Cache::deleteTrackerCache();
     static::loadAllPlugins();
     $_GET = $_REQUEST = array();
     $_SERVER['HTTP_REFERER'] = '';
     // Make sure translations are loaded to check messages in English
     if ($this->loadTranslations) {
         Translate::reloadLanguage('en');
         APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en');
     }
     FakeAccess::$superUserLogin = '******';
     \Piwik\SettingsPiwik::$cachedKnownSegmentsToArchive = null;
     \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true;
     if ($this->configureComponents) {
         \Piwik\Plugins\PrivacyManager\IPAnonymizer::deactivate();
         \Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker::deactivate();
     }
     if ($this->createSuperUser) {
         self::createSuperUser($this->removeExistingSuperUser);
     }
     if ($setupEnvironmentOnly) {
         return;
     }
     $this->getTestEnvironment()->save();
     $this->getTestEnvironment()->executeSetupTestEnvHook();
     Piwik_TestingEnvironment::addSendMailHook();
     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}.");
     }
 }