public function testCreateDatabase() {
        $config = Config::getInstance();
        $config_array = $config->getValuesArray();
        $dao = new InstallerMySQLDAO($config_array);

        $config_array['db_name'] = 'thinkup_db_creation_test_db-yes';

        //Check that the database exists before trying to create it.
        $before = $this->testdb_helper->databaseExists($config_array['db_name']);
        $this->assertFalse($before);

        //Create the database. True on success, false on fail.
        //Destroy the current correct config array, replaced with the test db
        //name array in the createInstallDatabase function
        Config::destroyInstance();
        $create_db = $dao->createInstallDatabase($config_array);
        //Check the database exists after creation.
        Config::destroyInstance();
        $after = $this->testdb_helper->databaseExists($config_array['db_name']);
        $this->assertTrue($create_db && $after);

        //Delete the database. True on success, false on fail.
        $deleted = $this->testdb_helper->deleteDatabase($config_array['db_name']);

        //Assert that the testing database for this function was cleaned up
        $this->assertTrue($deleted);
    }
 /**
  * Destroy Config, Webapp, $_SESSION, $_POST, $_GET, $_REQUEST
  */
 public function tearDown()
 {
     Config::destroyInstance();
     PluginRegistrarWebapp::destroyInstance();
     PluginRegistrarCrawler::destroyInstance();
     if (isset($_SESSION)) {
         $this->unsetArray($_SESSION);
     }
     $this->unsetArray($_POST);
     $this->unsetArray($_GET);
     $this->unsetArray($_REQUEST);
     $this->unsetArray($_SERVER);
     $this->unsetArray($_FILES);
     Loader::unregister();
     $backup_dir = FileDataManager::getBackupPath();
     if (file_exists($backup_dir)) {
         try {
             @exec('cd ' . $backup_dir . '; rm -rf *');
             rmdir($backup_dir);
             // won't delete if has files
         } catch (Exception $e) {
         }
     }
     $data_dir = FileDataManager::getDataPath();
     if (file_exists($data_dir . 'compiled_view')) {
         try {
             @exec('cd ' . $data_dir . '; rm -rf compiled_view');
         } catch (Exception $e) {
         }
     }
     parent::tearDown();
 }
 public function testCreateDatabase()
 {
     $config = Config::getInstance();
     $config_array = $config->getValuesArray();
     $dao = new InstallerMySQLDAO($config_array);
     //test a hairy database name with dashes to assert escaping is happening correctly
     $config_array['db_name'] = 'thinkup_db_creation-test_db-yes';
     //Check that the database exists before trying to create it.
     $before = $this->testdb_helper->databaseExists($config_array['db_name']);
     $this->assertFalse($before);
     //Create the database. True on success, false on fail.
     //Destroy the current correct config, replace with the test db name array in the createInstallDatabase function
     Config::destroyInstance();
     $create_db = $dao->createInstallDatabase($config_array);
     //Check the database exists after creation.
     Config::destroyInstance();
     $after = $this->testdb_helper->databaseExists($config_array['db_name']);
     $this->assertTrue($create_db);
     $this->assertTrue($after);
     //Delete the database
     $this->testdb_helper->deleteDatabase($config_array['db_name']);
     //Assert it no longer exists
     $after = $this->testdb_helper->databaseExists($config_array['db_name']);
     $this->assertFalse($after);
 }
 /**
  * Gets the db_type for our configured ThinkUp instance, defaults to mysql,
  * db_type can optionally be defined in webapp/config.inc as:
  *
  *<code>
  *     $THINKUP_CFG['db_type'] = 'somedb';
  *</code>
  *
  * @param array $cfg_vals Optionally override config.inc.php vals; needs 'table_prefix', 'db_type',
  * 'db_socket', 'db_name', 'db_host', 'db_user', 'db_password'
  * @return string db_type, will default to 'mysql' if not defined
  */
 public static function getDBType($cfg_vals = null)
 {
     if ($cfg_vals != null) {
         Config::destroyInstance();
     }
     $type = Config::getInstance($cfg_vals)->getValue('db_type');
     $type = is_null($type) ? 'mysql' : $type;
     return $type;
 }
 /**
  * Tear down
  * Destroys Config, Webapp, and Session objects
  * @TODO Destroy all SESSION variables
  * @TODO Destroy all REQUEST/GET/POST variables
  */
 function tearDown()
 {
     Config::destroyInstance();
     Webapp::destroyInstance();
     Crawler::destroyInstance();
     if (isset($_SESSION['user'])) {
         $_SESSION['user'] = null;
     }
     parent::tearDown();
 }
Exemple #6
0
 public function testNoConfigFileNoArray()
 {
     Config::destroyInstance();
     $this->removeConfigFile();
     try {
         $config = Config::getInstance();
         $this->assertNull($config->getValue('table_prefix'));
     } catch (Exception $e) {
         $this->assertPattern("/ThinkUp's configuration file does not exist!/", $e->getMessage());
     }
     $this->restoreConfigFile();
 }
 /**
  * Test constructor
  */
 public function testNewViewManagerWithoutConfigFile()
 {
     $orig_tz = date_default_timezone_get();
     $this->removeConfigFile();
     Config::destroyInstance();
     $cfg_array = array('site_root_path' => Utils::getSiteRootPathFromFileSystem(), 'source_root_path' => THINKUP_ROOT_PATH, 'datadir_path' => THINKUP_WEBAPP_PATH . 'data/', 'debug' => false, 'app_title_prefix' => "", 'cache_pages' => false);
     $v_mgr = new ViewManager($cfg_array);
     $tz = date_default_timezone_get();
     $this->assertEqual($tz, 'UTC');
     $this->assertTrue(isset($v_mgr));
     $this->restoreConfigFile();
     date_default_timezone_set($orig_tz);
 }
 public function testGetDataPathConfigExistsWithoutDataDirValue()
 {
     Config::destroyInstance();
     $this->removeConfigFile();
     $cfg_values = array("table_prefix" => "thinkupyo", "db_host" => "myserver.com");
     $config = Config::getInstance($cfg_values);
     //test just path
     $path = FileDataManager::getDataPath();
     $this->assertEqual($path, THINKUP_WEBAPP_PATH . 'data/');
     //test path with file
     $path = FileDataManager::getDataPath('myfile.txt');
     $this->assertEqual($path, THINKUP_WEBAPP_PATH . 'data/myfile.txt');
     $this->restoreConfigFile();
 }
 /**
  * Tear down
  * Destroys Config, Webapp, $_SESSION, $_POST, $_GET, $_REQUEST
  */
 public function tearDown()
 {
     Config::destroyInstance();
     Webapp::destroyInstance();
     Crawler::destroyInstance();
     if (isset($_SESSION)) {
         $this->unsetArray($_SESSION);
     }
     $this->unsetArray($_POST);
     $this->unsetArray($_GET);
     $this->unsetArray($_REQUEST);
     $this->unsetArray($_SERVER);
     Loader::unregister();
     parent::tearDown();
 }
 public function testGetUnsetDefaultValue()
 {
     Config::destroyInstance();
     $this->removeConfigFile();
     $config = Config::getInstance(array('timezone' => 'America/Los_Angeles'));
     $this->assertEqual($config->getValue('app_title_prefix'), '');
     $this->assertNotNull($config->getValue('app_title_prefix'));
     $this->restoreConfigFile();
 }
Exemple #11
0
    public function testGetConnectString() {
        $this->removeConfigFile();
        Config::destroyInstance();
        $cfg_values = array("db_host"=>"localhost");
        $config = Config::getInstance($cfg_values);
        $this->assertEqual(PDODAO::getConnectString($config), "mysql:dbname=;host=localhost");

        $this->removeConfigFile();
        Config::destroyInstance();
        $cfg_values = array("db_type" => "mysql", "db_host"=>"localhost", "db_name" => "thinkup");
        $config = Config::getInstance($cfg_values);
        $this->assertEqual(PDODAO::getConnectString($config), "mysql:dbname=thinkup;host=localhost");

        $this->removeConfigFile();
        Config::destroyInstance();
        $cfg_values = array("db_host"=>"localhost", "db_name" => "thinkup", "db_port" => "3306");
        $config = Config::getInstance($cfg_values);
        $this->assertEqual(PDODAO::getConnectString($config), "mysql:dbname=thinkup;host=localhost;port=3306");

        $this->removeConfigFile();
        Config::destroyInstance();
        $cfg_values = array("db_host"=>"localhost", "db_name" => "thinkup", "db_socket" => "/var/mysql");
        $config = Config::getInstance($cfg_values);
        $this->assertEqual(PDODAO::getConnectString($config),
        "mysql:dbname=thinkup;host=localhost;unix_socket=/var/mysql");
        $this->restoreConfigFile();
    }
 public function tearDown()
 {
     Config::destroyInstance();
     parent::tearDown();
 }
 public function testFreshInstallStep3SuccessfulInstall()
 {
     self::time(__METHOD__);
     //get valid credentials
     $config = Config::getInstance();
     $valid_db_username = $config->getValue('db_user');
     $valid_db_pwd = $config->getValue('db_password');
     $valid_db_name = $config->getValue('db_name');
     $valid_db_host = $config->getValue('db_host');
     $valid_db_socket = $config->getValue('db_socket');
     //drop DB
     $this->testdb_helper->drop($this->test_database_name);
     //remove config file
     $config = null;
     Config::destroyInstance();
     //unset PDO so it must be recreated
     InstallerMySQLDAO::$PDO = null;
     //remove config file
     $this->removeConfigFile();
     //force a refresh of getTables
     Installer::$show_tables = null;
     //set param for step 3
     $_GET['step'] = '3';
     //set post values from form
     $_POST['site_email'] = "*****@*****.**";
     $_POST['password'] = "******";
     $_POST['confirm_password'] = "******";
     $_POST['db_user'] = $valid_db_username;
     $_POST['db_passwd'] = $valid_db_pwd;
     $_POST['db_name'] = $valid_db_name;
     //$_POST['db_name'] = 'thinkup_install';
     $_POST['db_type'] = "mysql";
     $_POST['db_host'] = $valid_db_host;
     $_POST['db_socket'] = $valid_db_socket;
     $_POST['db_port'] = "";
     $_POST['db_prefix'] = "tu_";
     $_POST['full_name'] = "My Full Name";
     $_POST['timezone'] = "America/Los_Angeles";
     $_SERVER['HTTP_HOST'] = "example.com";
     $controller = new InstallerController(true);
     $this->assertTrue(isset($controller));
     $result = $controller->go();
     $this->debug($result);
     $this->assertPattern('/ThinkUp has been successfully installed./', $result);
     $option_dao = DAOFactory::getDAO('OptionDAO');
     $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
     $this->assertNotNull($current_stored_server_name);
     $this->assertEqual($current_stored_server_name->option_value, 'example.com');
     $this->assertEqual($current_stored_server_name->option_name, 'server_name');
     $install_email = Mailer::getLastMail();
     $this->debug($install_email);
     $this->assertPattern("/http:\\/\\/example.com\\/session\\/activate.php\\?usr=you\\%40example.com\\&code\\=/", $install_email);
     $this->restoreConfigFile();
     //echo $result;
 }
 public function testFreshInstallStep3SuccessfulInstall()
 {
     //get valid credentials
     $config = Config::getInstance();
     $valid_db_username = $config->getValue('db_user');
     $valid_db_pwd = $config->getValue('db_password');
     $valid_db_name = $config->getValue('db_name');
     $valid_db_host = $config->getValue('db_host');
     $valid_db_socket = $config->getValue('db_socket');
     //drop DB
     $this->testdb_helper->drop($this->test_database_name);
     //remove config file
     $config = null;
     Config::destroyInstance();
     //unset PDO so it must be recreated
     InstallerMySQLDAO::$PDO = null;
     //remove config file
     $this->removeConfigFile();
     //force a refresh of getTables
     Installer::$show_tables = null;
     //set param for step 3
     $_GET['step'] = '3';
     //set post values from form
     $_POST['site_email'] = "*****@*****.**";
     $_POST['password'] = "******";
     $_POST['confirm_password'] = "******";
     $_POST['db_user'] = $valid_db_username;
     $_POST['db_passwd'] = $valid_db_pwd;
     $_POST['db_name'] = $valid_db_name;
     //$_POST['db_name'] = 'thinkup_install';
     $_POST['db_type'] = "mysql";
     $_POST['db_host'] = $valid_db_host;
     $_POST['db_socket'] = $valid_db_socket;
     $_POST['db_port'] = "";
     $_POST['db_prefix'] = "tu_";
     $_POST['full_name'] = "My Full Name";
     $_POST['timezone'] = "America/Los_Angeles";
     $_SERVER['HTTP_HOST'] = "http://example.com";
     $controller = new InstallerController(true);
     $this->assertTrue(isset($controller));
     $result = $controller->go();
     $this->assertPattern('/ThinkUp has been installed successfully./', $result);
     $this->restoreConfigFile();
     //echo $result;
 }
 /**
  * Test get InstallerDAO without a config file, override with array of config values
  */
 public function testGetInstallerDAONoConfigFile()
 {
     $this->removeConfigFile();
     Config::destroyInstance();
     $cfg_values = array("table_prefix" => ThinkUpTestDatabaseHelper::$prefix, "db_host" => "localhost");
     $config = Config::getInstance($cfg_values);
     $dao = DAOFactory::getDAO('InstallerDAO', $cfg_values);
     $this->assertTrue(isset($dao));
     $this->assertIsA($dao, 'InstallerMySQLDAO');
     $result = $dao->getTables();
     $this->assertEqual(sizeof($result), 38);
     $this->assertEqual($result[0], $cfg_values["table_prefix"] . 'cookies');
     $this->assertEqual($result[1], $cfg_values["table_prefix"] . 'count_history');
     $this->restoreConfigFile();
 }
Exemple #16
0
 public function testCompareTimezoneOffsets()
 {
     $config = Config::getInstance();
     $config->setValue('timezone', 'Europe/London');
     $timezone = $config->getValue('timezone');
     $time = new DateTime("now", new DateTimeZone($timezone));
     $tz_config = $time->format('P');
     //destroy the existing PDO connection which gets established in setUp to start with a clean slate
     TestMySQLDAO::destroyPDO();
     // this should return the same timezone offset as the config value
     $test_dao = new TestMySQLDAO();
     $tz_server = $test_dao->getTimezoneOffset();
     if ($this->isTimeZoneSupported()) {
         $this->assertEqual('Europe/London', $tz_server['tz_offset']);
     } else {
         $this->assertEqual($tz_config, $tz_server['tz_offset']);
     }
     Config::destroyInstance();
 }
 /**
  * Test get InstallerDAO without a config file, override with array of config values
  */
 public function testGetInstallerDAONoConfigFile(){
     $this->removeConfigFile();
     Config::destroyInstance();
     $cfg_values = array("table_prefix"=>"tu_", "db_host"=>"localhost");
     $config = Config::getInstance($cfg_values);
     $dao = DAOFactory::getDAO('InstallerDAO', $cfg_values);
     $this->assertTrue(isset($dao));
     $this->assertIsA($dao, 'InstallerMySQLDAO');
     $result = $dao->getTables();
     $this->assertEqual(sizeof($result), 15);
     $this->assertEqual($result[0], $cfg_values["table_prefix"].'encoded_locations');
     $this->restoreConfigFile();
 }
Exemple #18
0
 public function testGetGMTOffset()
 {
     Config::destroyInstance();
     $this->removeConfigFile();
     $config = Config::getInstance(array('timezone' => 'America/Los_Angeles'));
     $this->assertEqual($config->getGMTOffset('January 1, 2010'), -8);
     $this->assertEqual($config->getGMTOffset('August 1, 2010'), -7);
     Config::destroyInstance();
     $this->removeConfigFile();
     $config = Config::getInstance(array('timezone' => 'America/New_York'));
     $this->assertEqual($config->getGMTOffset('January 1, 2010'), -5);
     $this->assertEqual($config->getGMTOffset('August 1, 2010'), -4);
     $this->restoreConfigFile();
 }