예제 #1
0
 /**
  * Setup the database and create the base tables for all tests
  */
 public function setUp()
 {
     parent::setUp();
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         $dbConfig = Piwik_Config::getInstance()->database;
         $dbName = $dbConfig['dbname'];
         $dbConfig['dbname'] = null;
         Piwik::createDatabaseObject($dbConfig);
         Piwik::dropDatabase();
         Piwik::createDatabase($dbName);
         Piwik::disconnectDatabase();
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik::createLogObject();
         Piwik_PluginsManager::getInstance()->loadPlugins(array());
     } catch (Exception $e) {
         $this->fail("TEST INITIALIZATION FAILED: " . $e->getMessage());
     }
     include "DataFiles/SearchEngines.php";
     include "DataFiles/Languages.php";
     include "DataFiles/Countries.php";
     include "DataFiles/Currencies.php";
     include "DataFiles/LanguageToCountry.php";
 }
예제 #2
0
 public static function setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true)
 {
     try {
         Piwik::$piwikUrlCache = '';
         if ($createConfig) {
             self::createTestConfig();
         }
         if ($dbName === false) {
             $dbName = Piwik_Config::getInstance()->database['dbname'];
         }
         self::connectWithoutDatabase();
         if ($createEmptyDatabase) {
             Piwik::dropDatabase();
         }
         Piwik::createDatabase($dbName);
         Piwik::disconnectDatabase();
         // reconnect once we're sure the database exists
         Piwik_Config::getInstance()->database['dbname'] = $dbName;
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik::createLogObject();
         Piwik_PluginsManager::getInstance()->loadPlugins(array());
     } catch (Exception $e) {
         self::fail("TEST INITIALIZATION FAILED: " . $e->getMessage());
     }
     include "DataFiles/SearchEngines.php";
     include "DataFiles/Languages.php";
     include "DataFiles/Countries.php";
     include "DataFiles/Currencies.php";
     include "DataFiles/LanguageToCountry.php";
     Piwik::createAccessObject();
     Piwik_PostEvent('FrontController.initAuthenticationObject');
     // We need to be SU to create websites for tests
     Piwik::setUserIsSuperUser();
     // Load and install plugins
     $pluginsManager = Piwik_PluginsManager::getInstance();
     $plugins = $pluginsManager->readPluginsDirectory();
     $pluginsManager->loadPlugins($plugins);
     if ($createEmptyDatabase) {
         $pluginsManager->installLoadedPlugins();
     }
     $_GET = $_REQUEST = array();
     $_SERVER['HTTP_REFERER'] = '';
     // Make sure translations are loaded to check messages in English
     Piwik_Translate::getInstance()->loadEnglishTranslation();
     Piwik_LanguagesManager_API::getInstance()->setLanguageForUser('superUserLogin', 'en');
     // List of Modules, or Module.Method that should not be called as part of the XML output compare
     // Usually these modules either return random changing data, or are already tested in specific unit tests.
     self::setApiNotToCall(self::$defaultApiNotToCall);
     self::setApiToCall(array());
 }
예제 #3
0
 function __construct($title = '')
 {
     parent::__construct($title);
     print "The test class extends Test_Database: the test Piwik database is created once in the constructor, and all tables are truncated at the end of EACH unit test method.<br>";
     Piwik::createConfigObject();
     Piwik::createDatabaseObject();
     Zend_Registry::get('config')->setTestEnvironment();
     Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
     Piwik::createLogObject();
     Piwik::dropDatabase();
     Piwik::createDatabase();
     Piwik::disconnectDatabase();
     Piwik::createDatabaseObject();
     Piwik::createTables();
 }
예제 #4
0
 function __construct($title = '')
 {
     parent::__construct($title);
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         Piwik::createDatabaseObject();
         Piwik::createLogObject();
         Piwik::dropDatabase();
         Piwik::createDatabase();
         Piwik::disconnectDatabase();
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik_PluginsManager::getInstance()->installLoadedPlugins();
     } catch (Exception $e) {
         echo $e->getMessage();
         echo "<br/><b>TEST INITIALIZATION FAILED!";
         throw $e;
     }
 }
예제 #5
0
 public function isTestDatabasePresent()
 {
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         Piwik::createDatabaseObject();
         Piwik::disconnectDatabase();
         return true;
     } catch (Exception $e) {
         return false;
     }
 }