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; }
public function testNeedsSnowflakeUpgrade() { $dao = new InstallerMySQLDAO(); $this->assertFalse($dao->needsSnowflakeUpgrade()); $this->db->exec('ALTER TABLE tu_posts CHANGE post_id post_id bigint(11) NOT NULL;'); $this->assertTrue($dao->needsSnowflakeUpgrade()); }
public function testRunNewMigrationStripsVersionForStorage() { $dao = new InstallerMySQLDAO(); $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)'); $this->testdb_helper->runSQL('DROP TABLE IF EXISTS tu_completed_migrations'); $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);" . "insert into tu_test2 (value) VALUES (3);" . "DROP TABLE IF EXISTS tu_users_b16;" . "insert into tu_test2 (value) VALUES (4);" . "insert into tu_test2 (value) VALUES (5);", true, $filename = 'a_file_v0.13.sql'); // migration should have run $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_test2"); $data = $stmt->fetchAll(); $this->assertEqual(count($data), 4); $this->assertEqual(2, $data[0]['value']); $this->assertEqual(3, $data[1]['value']); $this->assertEqual(4, $data[2]['value']); $this->assertEqual(5, $data[3]['value']); // tu_completed_migrations table should contain a record for our latest migration $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations"); $data = $stmt->fetchAll(); $this->assertEqual(count($data), 4); $this->assertEqual($data[0]['migration'], 'a_file-0'); $this->assertEqual($data[1]['migration'], 'a_file-1'); $this->assertEqual($data[2]['migration'], 'a_file-2'); $this->assertEqual($data[3]['migration'], 'a_file-3'); }
public function testExamineQueries() { // test on fully installed tables $install_queries = file_get_contents(THINKUP_ROOT_PATH . "webapp/install/sql/build-db_mysql.sql"); //clean SQL: diffDataStructure requires two spaces after PRIMARY KEY, and a space between key name and (field) $install_queries = str_replace('PRIMARY KEY ', 'PRIMARY KEY ', $install_queries); // test on complete table set; this should return just the INSERT query into plugins table $config = Config::getInstance(); $config_array = $config->getValuesArray(); $dao = new InstallerMySQLDAO($config_array); $output = $dao->diffDataStructure($install_queries, $dao->getTables()); $this->assertEqual(sizeof($output['for_update']), 0); //var_dump($output); $expected = "/INSERT INTO " . $config_array["table_prefix"] . "plugins/i"; $this->assertPattern($expected, $output['queries'][0]); // test on missing tables InstallerMySQLDAO::$PDO->exec("DROP TABLE " . $config_array["table_prefix"] . "owners"); $output = $dao->diffDataStructure($install_queries, $dao->getTables()); $expected = "/Created table {$config_array["table_prefix"]}owners/i"; $this->assertPattern($expected, $output['for_update'][$config_array["table_prefix"] . 'owners']); $expected = "/CREATE TABLE {$config_array["table_prefix"]}owners /i"; $this->assertPattern($expected, $output['queries'][$config_array["table_prefix"] . 'owners']); // test on missing PRIMARY KEY InstallerMySQLDAO::$PDO->exec("ALTER TABLE " . $config_array["table_prefix"] . "follows DROP KEY user_id"); $tables = $dao->getTables(); //var_dump($tables); $output = $dao->diffDataStructure($install_queries, $tables); $add_pk = "ALTER TABLE " . $config_array["table_prefix"] . "follows ADD UNIQUE KEY user_id (user_id,follower_id,network)"; $this->assertTrue(in_array($add_pk, $output['queries'])); // test on missing index InstallerMySQLDAO::$PDO->exec("ALTER TABLE " . $config_array["table_prefix"] . "follows DROP INDEX active"); $output = $dao->diffDataStructure($install_queries, $dao->getTables(false)); $add_idx = "ALTER TABLE " . $config_array["table_prefix"] . "follows ADD KEY active (active)"; $this->assertTrue(in_array($add_idx, $output['queries'])); // test on missing column InstallerMySQLDAO::$PDO->exec("ALTER TABLE " . $config_array["table_prefix"] . "posts DROP place"); $output = $dao->diffDataStructure($install_queries, $dao->getTables(false)); $add_idx = "ALTER TABLE " . $config_array["table_prefix"] . "posts ADD COLUMN place varchar(255) DEFAULT NULL"; $this->assertTrue(in_array($add_idx, $output['queries'])); }