Skip to content
This repository
Browse code

Fix working directory & table prefix assumptions in tests

- Make paths to init.tests.php relative to __FILE__ so they don't make
  assumptions about the working directory
- Fix tests that assume the prefix is tu_
- Fix a few places that assume a trailing slash after directories
- Restore the configuration file if it's moved out of the way during
  testing and an exception occurs before it's moved back
- Minor updates to tests/README.md
- Remove /tests from THINKUP_BASE_URL
THINKUP_BASE_URL was set to /tests when tests were run from the root
directory.

Make sure there's a slash between root dir and tests/view

Accept "Access Denied" as a correct failure on bad database

When trying to install to a bad database name, the test assumed that
access would be granted, and an "Unknown database" error would result.
If access is denied, accept that as a correct failure as well.

Use loopback for testing bad database host

When using a "helpful" DNS resolver that returns an IP address for
unresolvable hosts (see e.g. http://dns-opt-out.comcast.net/), using an
unresolvable hostname like "localcheese" causes the test to hang while
attempting to connect to port 3306 on an IP address that's dropping
packets.

Instead, we try to connect to a loopback address, 127.0.0.2, which
(hopefully) isn't accessible so the connection is refused immediately.

Fix case of MySQL in class names

More fixes for working directory & table prefix assumptions in tests

- Make paths relative to __FILE__ so they don't make assumptions about the
  working directory
- Fix tests that assume the prefix is tu_
- Fix a few places that assume a trailing slash after directories

Fix for non-standard prefix that contains "tu_"

Use #prefix# in query passed to newMigrationFiles

Closes #187, closes #1089
  • Loading branch information...
commit 8e8414bea985e23ac4ca430500d8b979c8c6646d 1 parent eca2a8b
Christian G. Warden cwarden authored committed

Showing 65 changed files with 366 additions and 294 deletions. Show diff stats Hide diff stats

  1. +2 2 tests/README.md
  2. +4 4 tests/TestOfAccountConfigurationController.php
  3. +10 8 tests/TestOfBackupController.php
  4. +20 22 tests/TestOfBackupMySQLDAO.php
  5. +5 2 tests/TestOfDAOFactory.php
  6. +4 2 tests/TestOfExportMySQLDAO.php
  7. +8 8 tests/TestOfExportServiceUserDataController.php
  8. +21 2 tests/TestOfInstaller.php
  9. +51 54 tests/TestOfInstallerController.php
  10. +40 23 tests/TestOfInstallerMySQLDAO.php
  11. +4 2 tests/TestOfInstanceMySQLDAO.php
  12. +6 2 tests/TestOfLinkMySQLDAO.php
  13. +21 11 tests/TestOfPDODAO.php
  14. +6 2 tests/TestOfPostMySQLDAO.php
  15. +2 2 tests/TestOfSmartyThinkUp.php
  16. +1 1  tests/TestOfThinkUpEmbedController.php
  17. +1 1  tests/TestOfThreadJSController.php
  18. +41 35 tests/TestOfUpgradeController.php
  19. +5 4 tests/TestOfUtils.php
  20. +1 1  tests/WebTestOfCrawlerRun.php
  21. +7 4 tests/WebTestOfInstallation.php
  22. +14 10 tests/WebTestOfUpgradeDatabase.php
  23. +2 2 tests/all_model_tests.php
  24. +1 1  tests/all_tests.php
  25. +1 1  tests/classes/class.TestFauxDAO.php
  26. +3 0  tests/classes/class.ThinkUpTestDatabaseHelper.php
  27. +5 4 tests/classes/class.ThinkUpUnitTestCase.php
  28. +1 1  tests/classes/class.ThinkUpWebTestCase.php
  29. +23 33 webapp/_lib/model/class.ExportMySQLDAO.php
  30. +4 4 webapp/_lib/model/class.Installer.php
  31. +1 0  webapp/_lib/model/class.InstallerMySQLDAO.php
  32. +1 1  webapp/_lib/model/class.Utils.php
  33. +1 1  webapp/plugins/expandurls/tests/TestOfExpandURLsPlugin.php
  34. +1 1  webapp/plugins/expandurls/tests/TestOfExpandURLsPluginConfigurationController.php
  35. +2 2 webapp/plugins/expandurls/tests/TestOfFlickrAPIAccessor.php
  36. +1 1  webapp/plugins/facebook/tests/TestOfFacebookCrawler.php
  37. +1 1  webapp/plugins/facebook/tests/TestOfFacebookPlugin.php
  38. +1 1  webapp/plugins/facebook/tests/TestOfFacebookPluginConfigurationController.php
  39. +2 2 webapp/plugins/geoencoder/tests/TestOfGeoEncoderPlugin.php
  40. +2 2 webapp/plugins/geoencoder/tests/TestOfGeoEncoderPluginConfigurationController.php
  41. +2 2 webapp/plugins/geoencoder/tests/TestOfMapController.php
  42. +1 1  webapp/plugins/googleplus/tests/TestOfGooglePlusCrawler.php
  43. +1 1  webapp/plugins/googleplus/tests/TestOfGooglePlusPlugin.php
  44. +1 1  webapp/plugins/googleplus/tests/TestOfGooglePlusPluginConfigurationController.php
  45. +1 0  ...authorization_code-code=test-code1-redirect_uri=http%3A%2F%2Fdev.thinkup.com%2Faccount%2F%3Fp%3Dgoogle%252B
  46. +1 0  ...uthorization_code-code=test-code1-redirect_uri=https%3A%2F%2Fdev.thinkup.com%2Faccount%2F%3Fp%3Dgoogle%252B
  47. +2 2 webapp/plugins/hellothinkup/tests/TestOfHelloThinkUpPlugin.php
  48. +2 2 webapp/plugins/hellothinkup/tests/TestOfHelloThinkUpPluginConfigurationController.php
  49. +2 2 webapp/plugins/twitter/tests/TestOfCrawlerTwitterAPIAccessorOAuth.php
  50. +2 2 webapp/plugins/twitter/tests/TestOfRetweetDetector.php
  51. +2 2 webapp/plugins/twitter/tests/TestOfTwitterAPIAccessorOAuth.php
  52. +1 1  webapp/plugins/twitter/tests/TestOfTwitterAuthController.php
  53. +1 1  webapp/plugins/twitter/tests/TestOfTwitterCrawler.php
  54. +5 3 webapp/plugins/twitter/tests/TestOfTwitterInstanceMySQLDAO.php
  55. +2 2 webapp/plugins/twitter/tests/TestOfTwitterOAuth.php
  56. +1 1  webapp/plugins/twitter/tests/TestOfTwitterPlugin.php
  57. +1 1  webapp/plugins/twitter/tests/TestOfTwitterPluginConfigurationController.php
  58. +1 1  webapp/plugins/twitterrealtime/tests/TestOfConsumerStreamProcess.php
  59. +1 1  webapp/plugins/twitterrealtime/tests/TestOfConsumerUserStream.php
  60. +1 1  webapp/plugins/twitterrealtime/tests/TestOfStreamMessageQueueFactory.php
  61. +1 1  webapp/plugins/twitterrealtime/tests/TestOfStreamMessageQueueMySQL.php
  62. +1 1  webapp/plugins/twitterrealtime/tests/TestOfStreamMessageQueueRedis.php
  63. +1 1  webapp/plugins/twitterrealtime/tests/TestOfTwitterJSONStreamParser.php
  64. +1 1  webapp/plugins/twitterrealtime/tests/TestOfTwitterRealtimePlugin.php
  65. +4 3 webapp/plugins/twitterrealtime/tests/TestOfTwitterRealtimePluginConfigurationController.php
4 tests/README.md
Source Rendered
@@ -19,7 +19,7 @@ password to access it. This database name should match the one you just set in `
19 19 In order for the tests to pass, you must:
20 20
21 21 * Have a `tests/config.tests.inc.php` file with the correct values set
22   -* Set the crawler log file in `webapp/config.inc.php` and make that file writable
  22 +* Set the crawler and stream log files in `webapp/config.inc.php` and make those files writable
23 23 * Set the test database name to an empty tests database which the tests will destroy each run in `webapp/config.inc.php`
24 24 * Set the test database user to a user with all privileges in the test database and global CREATE, DROP, and FILE privs
25 25 * Set caching to false in `webapp/config.inc.php`
@@ -28,7 +28,7 @@ In order for the tests to pass, you must:
28 28
29 29 To run a particular test suite, like the UserDAO suite, in the ThinkUp source code root folder, use this command:
30 30
31   - $ php tests/TestOfUserDAO.php
  31 + $ php tests/TestOfUserMySQLDAO.php
32 32
33 33 To run all the test suites, use:
34 34
8 tests/TestOfAccountConfigurationController.php
@@ -651,7 +651,7 @@ public function testAuthControlInviteUserNoCSRFToken() {
651 651 public function testAuthControlInviteUser() {
652 652 $this->simulateLogin('me@example.com', false, true);
653 653
654   - $_SERVER['HTTP_HOST'] = "mytestthinkup/";
  654 + $_SERVER['HTTP_HOST'] = "mytestthinkup";
655 655 $_SERVER['HTTPS'] = null;
656 656 $_POST['invite'] = 'Create Invitation' ;
657 657 $_POST['csrf_token'] = parent::CSRF_TOKEN;
@@ -663,11 +663,11 @@ public function testAuthControlInviteUser() {
663 663
664 664 $msgs_array = $v_mgr->getTemplateDataItem('success_msgs');
665 665 $this->assertPattern('/Invitation created!/', $msgs_array['invite']);
666   - $this->assertPattern('/http:\/\/mytestthinkup\/tests\/session\/register.php\?code=/', $msgs_array['invite']);
  666 + $this->assertPattern('/http:\/\/mytestthinkup\/session\/register.php\?code=/', $msgs_array['invite']);
667 667
668 668 //test HTTPS
669 669 $_SERVER['HTTPS'] = 1;
670   - $_SERVER['HTTP_HOST'] = "myotherwtestthinkup/";
  670 + $_SERVER['HTTP_HOST'] = "myotherwtestthinkup";
671 671 $_POST['invite'] = 'Create Invitation' ;
672 672
673 673 $controller = new AccountConfigurationController(true);
@@ -677,7 +677,7 @@ public function testAuthControlInviteUser() {
677 677
678 678 $msgs_array = $v_mgr->getTemplateDataItem('success_msgs');
679 679 $this->assertPattern('/Invitation created!/', $msgs_array['invite']);
680   - $this->assertPattern('/https:\/\/myotherwtestthinkup\/tests\/session\/register.php\?code=/',
  680 + $this->assertPattern('/https:\/\/myotherwtestthinkup\/session\/register.php\?code=/',
681 681 $msgs_array['invite']);
682 682 }
683 683
18 tests/TestOfBackupController.php
@@ -154,7 +154,7 @@ public function testBackup() {
154 154 $zip_files[$zfile['name']] = $zfile['name'];
155 155 }
156 156 //verify we have create table file
157   - $this->assertTrue($zip_files["create_tables.sql"]);
  157 + $this->assertTrue(isset($zip_files["create_tables.sql"]));
158 158 $za->close();
159 159 $q = "show tables";
160 160 $q2 = "show create table ";
@@ -164,7 +164,7 @@ public function testBackup() {
164 164 while($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
165 165 foreach($data as $key => $value) {
166 166 $zfile = '/' . $value .'.txt';
167   - $this->assertTrue($zip_files[$zfile]);
  167 + $this->assertTrue(isset($zip_files[$zfile]));
168 168 }
169 169 }
170 170 }
@@ -199,14 +199,14 @@ public function testBadRestore() {
199 199 $this->assertPattern("/Backup file upload failed./", $results);
200 200
201 201 // upload bad archive file
202   - $zipfile = 'tests/data/backup/bad-zip-archive.zip';
  202 + $zipfile = dirname(__FILE__) . '/data/backup/bad-zip-archive.zip';
203 203 $_FILES["backup_file"]["tmp_name"] = $zipfile;
204 204 $_FILES['backup_file']["error"] = 0;
205 205 $results = $controller->go();
206 206 $this->assertPattern("/Unable to open import file, corrupted zip file/is", $results);
207 207
208 208 // upload bad archive file,, valid zip file, but not the right data
209   - $zipfile = 'tests/data/backup/bad-zip-archive2.zip';
  209 + $zipfile = dirname(__FILE__) . '/data/backup/bad-zip-archive2.zip';
210 210 $_FILES["backup_file"]["tmp_name"] = $zipfile;
211 211 $_FILES['backup_file']["error"] = 0;
212 212 $results = $controller->go();
@@ -217,8 +217,10 @@ public function testRestore() {
217 217 // create export
218 218 $dao = new BackupMySQLDAO();
219 219 $export_file = $dao->export();
  220 + $config = Config::getInstance();
  221 + $table_prefix = $config->getValue('table_prefix');
220 222
221   - $this->pdo->query("drop table tu_plugins");
  223 + $this->pdo->query("drop table " . $table_prefix . "plugins");
222 224
223 225 $this->simulateLogin('me@example.com', true);
224 226 $controller = new BackupController(true);
@@ -230,12 +232,12 @@ public function testRestore() {
230 232 $results = $controller->go();
231 233 $this->assertPattern("/Data Import Successfull/is", $results);
232 234
233   - $stmt = $this->pdo->query("show create table tu_plugins");
  235 + $stmt = $this->pdo->query("show create table " . $table_prefix . "plugins");
234 236 $data = $stmt->fetch();
235 237 $stmt->closeCursor();
236   - $this->assertEqual($data['Table'], 'tu_plugins');
  238 + $this->assertEqual($data['Table'], $table_prefix . 'plugins');
237 239
238   - $stmt = $this->pdo->query("select * from tu_plugins");
  240 + $stmt = $this->pdo->query("select * from " . $table_prefix . "plugins");
239 241
240 242 $data = $stmt->fetch();
241 243 $this->assertEqual($data['id'], 1);
42 tests/TestOfBackupMySQLDAO.php
@@ -128,17 +128,16 @@ public function testImportData() {
128 128 $data = $stmt->fetchAll();
129 129 $pre_import = count($data);
130 130
131   -
132 131 $export_file = $dao->export();
133 132
134   - $this->pdo->query("drop table tu_plugins");
  133 + $this->pdo->query("drop table " . $this->table_prefix . "plugins");
135 134 $this->assertTrue( $dao->import($export_file) );
136   - $stmt = $this->pdo->query("show create table tu_plugins");
  135 + $stmt = $this->pdo->query("show create table " . $this->table_prefix . "plugins");
137 136 $data = $stmt->fetch();
138 137 $stmt->closeCursor();
139   - $this->assertEqual($data['Table'], 'tu_plugins');
  138 + $this->assertEqual($data['Table'], $this->table_prefix . 'plugins');
140 139
141   - $stmt = $this->pdo->query("select * from tu_plugins");
  140 + $stmt = $this->pdo->query("select * from " . $this->table_prefix . "plugins");
142 141
143 142 $data = $stmt->fetch();
144 143 $this->assertEqual($data['id'], 1);
@@ -160,15 +159,14 @@ public function testImportDataDropNewTables() {
160 159 $data = $stmt->fetchAll();
161 160 $pre_import = count($data);
162 161
163   -
164 162 $export_file = $dao->export();
165   - $this->pdo->query("drop table tu_plugins");
  163 + $this->pdo->query("drop table " . $this->table_prefix . "plugins");
166 164 $this->pdo->query("create table tu_dropme (`value` int(11) NOT NULL)");
167 165 $this->assertTrue( $dao->import($export_file) );
168   - $stmt = $this->pdo->query("show create table tu_plugins");
  166 + $stmt = $this->pdo->query("show create table " . $this->table_prefix . "plugins");
169 167 $data = $stmt->fetch();
170 168 $stmt->closeCursor();
171   - $this->assertEqual($data['Table'], 'tu_plugins');
  169 + $this->assertEqual($data['Table'], $this->table_prefix . 'plugins');
172 170
173 171 $stmt = $this->pdo->query("show tables like '%dropme'");
174 172 $data = $stmt->fetch();
@@ -180,20 +178,20 @@ public function testImportDataDropNewTables() {
180 178 $this->assertEqual($pre_import, $post_import);
181 179 }
182 180
183   -public function recursiveDelete($str){
184   - if (is_file($str)){
185   - if (! preg_match("MAKETHISDIRWRITABLE", $str)) {
186   - return @unlink($str);
187   - } else {
188   - return true;
  181 + public function recursiveDelete($str){
  182 + if (is_file($str)){
  183 + if (! preg_match("MAKETHISDIRWRITABLE", $str)) {
  184 + return @unlink($str);
  185 + } else {
  186 + return true;
  187 + }
189 188 }
190   - }
191   - elseif (is_dir($str)){
192   - $scan = glob(rtrim($str,'/').'/*');
193   - foreach($scan as $index=>$path){
194   - $this->recursiveDelete($path);
  189 + elseif (is_dir($str)){
  190 + $scan = glob(rtrim($str,'/').'/*');
  191 + foreach($scan as $index=>$path){
  192 + $this->recursiveDelete($path);
  193 + }
  194 + return @rmdir($str);
195 195 }
196   - return @rmdir($str);
197 196 }
198   -}
199 197 }
7 tests/TestOfDAOFactory.php
@@ -51,6 +51,9 @@ protected function buildData() {
51 51 'test_id int(11),' .
52 52 'unique key test_id_idx (test_id)' .
53 53 ')';
  54 + if ($this->testdb_helper->prefix != 'tu_') {
  55 + $test_table_sql = str_replace('tu_', $this->testdb_helper->prefix, $test_table_sql);
  56 + }
54 57 $this->testdb_helper->runSQL($test_table_sql);
55 58
56 59 //some test data as well
@@ -187,7 +190,7 @@ public function testGetOwnerDAO(){
187 190 public function testGetOwnerDAONoConfigFile(){
188 191 $this->removeConfigFile();
189 192 Config::destroyInstance();
190   - $cfg_values = array("table_prefix"=>"tu_", "db_host"=>"localhost");
  193 + $cfg_values = array("table_prefix"=>$this->testdb_helper->prefix, "db_host"=>"localhost");
191 194 $config = Config::getInstance($cfg_values);
192 195 $dao = DAOFactory::getDAO('OwnerDAO', $cfg_values);
193 196 $this->assertTrue(isset($dao));
@@ -375,7 +378,7 @@ public function testGetTableStatsDAO() {
375 378 public function testGetInstallerDAONoConfigFile(){
376 379 $this->removeConfigFile();
377 380 Config::destroyInstance();
378   - $cfg_values = array("table_prefix"=>"tu_", "db_host"=>"localhost");
  381 + $cfg_values = array("table_prefix"=>$this->testdb_helper->prefix, "db_host"=>"localhost");
379 382 $config = Config::getInstance($cfg_values);
380 383 $dao = DAOFactory::getDAO('InstallerDAO', $cfg_values);
381 384 $this->assertTrue(isset($dao));
6 tests/TestOfExportMySQLDAO.php
@@ -290,7 +290,9 @@ public function testExportToFile() {
290 290 }
291 291
292 292 public function testGetExportFields() {
293   - $test_table_sql = 'CREATE TABLE tu_test_table(' .
  293 + $config = Config::getInstance();
  294 + $config_array = $config->getValuesArray();
  295 + $test_table_sql = 'CREATE TABLE ' . $config_array['table_prefix'] . 'test_table(' .
294 296 'id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,' .
295 297 'test_name varchar(20),' .
296 298 'test_id int(11),' .
@@ -306,4 +308,4 @@ public function testGetExportFields() {
306 308 $result = $post_export_dao->getExportFields('test_table', 't');
307 309 $this->assertEqual($result, 't.test_name, t.test_id');
308 310 }
309   -}
  311 +}
16 tests/TestOfExportServiceUserDataController.php
@@ -145,13 +145,13 @@ public function testExport() {
145 145 }
146 146
147 147 //verify we have create table file
148   - $this->assertTrue($zip_files["/README.txt"]);
149   - $this->assertTrue($zip_files["/posts.tmp"]);
150   - $this->assertTrue($zip_files["/links.tmp"]);
151   - $this->assertTrue($zip_files["/users_from_posts.tmp"]);
152   - $this->assertTrue($zip_files["/follows.tmp"]);
153   - $this->assertTrue($zip_files["/encoded_locations.tmp"]);
154   - $this->assertTrue($zip_files["/favorites.tmp"]);
  148 + $this->assertTrue(isset($zip_files["/README.txt"]));
  149 + $this->assertTrue(isset($zip_files["/posts.tmp"]));
  150 + $this->assertTrue(isset($zip_files["/links.tmp"]));
  151 + $this->assertTrue(isset($zip_files["/users_from_posts.tmp"]));
  152 + $this->assertTrue(isset($zip_files["/follows.tmp"]));
  153 + $this->assertTrue(isset($zip_files["/encoded_locations.tmp"]));
  154 + $this->assertTrue(isset($zip_files["/favorites.tmp"]));
155 155 $za->close();
156 156 }
157 157
@@ -194,4 +194,4 @@ class TestExportDAOGrantFail {
194 194 public function dropExportedPostsTable($backup_file = null) {
195 195 throw new Exception("MySQL does not have GRANT FILE ON permissions to write to: /bla");
196 196 }
197   -}
  197 +}
23 tests/TestOfInstaller.php
@@ -45,7 +45,7 @@ public function __construct() {
45 45 // Define base URL, the same as $THINKUP_CFG['site_root_path']
46 46 $current_script_path = explode('/', $_SERVER['PHP_SELF']);
47 47 array_pop($current_script_path);
48   - if ( in_array($current_script_path[count($current_script_path)-1],
  48 + if (!empty($current_script_path) && in_array($current_script_path[count($current_script_path)-1],
49 49 array('account', 'post', 'session', 'user', 'install')) ) {
50 50 array_pop($current_script_path);
51 51 }
@@ -371,6 +371,25 @@ public function testInstallerIsThinkUpInstalled() {
371 371 }
372 372 }
373 373
  374 + public function testInstallerPopulateTablesWithNonStandardPrefix() {
  375 + $config = Config::getInstance();
  376 + $non_standard_prefix = 'non_standard_tu_';
  377 + $config->setValue('table_prefix', $non_standard_prefix);
  378 + $config_array = $config->getValuesArray();
  379 +
  380 + $expected_table = $non_standard_prefix . 'instances_twitter';
  381 +
  382 + $installer = Installer::getInstance();
  383 + $db = $installer->setDb($config_array);
  384 + $log_verbose = $installer->populateTables($config_array);
  385 + $this->assertTrue(isset($log_verbose[$expected_table]));
  386 +
  387 + $q = sprintf("SHOW TABLES LIKE '%s'", $expected_table);
  388 + $stmt = PDODAO::$PDO->query($q);
  389 + $table = $stmt->fetch(PDO::FETCH_NUM);
  390 + $this->assertEqual($table[0], $expected_table);
  391 + }
  392 +
374 393 public function testInstallerPopulateTables() {
375 394 $config = Config::getInstance();
376 395 $config_array = $config->getValuesArray();
@@ -545,4 +564,4 @@ public function testGetTablesToInstall(){
545 564 'plugins', 'post_errors', 'posts', 'stream_data', 'stream_procs', 'user_errors', 'users');
546 565 $this->assertIdentical($tables, $expected_tables);
547 566 }
548   -}
  567 +}
105 tests/TestOfInstallerController.php
@@ -415,8 +415,7 @@ public function testFreshInstallStep3InvalidDatabaseCredentials() {
415 415 $result = $controller->go();
416 416 $this->debug($result);
417 417 $this->assertPattern('/ThinkUp couldn\'t connect to your database. The error message is:/', $result);
418   - //echo $result;
419   - $this->assertPattern('/Access denied for user 'username'@'localhost'/', $result);
  418 + $this->assertPattern('/(Unknown database|Access denied).*\'mythinkupdb `lol\'/', $result);
420 419 $this->restoreConfigFile();
421 420 }
422 421
@@ -469,57 +468,55 @@ public function testFreshInstallStep3InvalidDatabaseName() {
469 468 * This test can take an unreasonablely long time to complete (over an hour) due to connection timeouts on some
470 469 * server setups. Commenting out for faster runs on the build server.
471 470 */
472   - /*
473   - public function testFreshInstallStep3InvalidDatabaseHost() {
474   - self::time(__METHOD__);
475   - //get valid connection information
476   - $config = Config::getInstance();
477   - $valid_db_socket = $config->getValue('db_socket');
478   - $valid_db_user = $config->getValue('db_user');
479   - $valid_db_password = $config->getvalue('db_password');
480   - $valid_db_port = $config->getValue('db_port');
481   -
482   - //drop DB
483   - $this->testdb_helper->drop($this->test_database_name);
484   - //remove config file
485   - Config::destroyInstance();
486   - //unset PDO so it must be recreated
487   - InstallerMySQLDAO::$PDO = null;
488   - $this->removeConfigFile();
489   -
490   - ini_set("error_reporting", E_ERROR);
491   -
492   - //set param for step 2
493   - $_GET['step'] = '3';
494   - //set post values from form
495   - $_POST['site_email'] = "you@example.com";
496   - $_POST['db_user'] = $valid_db_user;
497   - $_POST['db_passwd'] = $valid_db_password;
498   - $_POST['db_name'] = "mythinkupdb";
499   - $_POST['db_type'] = "mysql";
500   - $_POST['db_host'] = "localcheese";
501   - $_POST['db_socket'] = $valid_db_socket;
502   - $_POST['db_port'] = $valid_db_port;
503   - $_POST['db_prefix'] = "tu_";
504   - $_POST['password'] = "asdfads123f";
505   - $_POST['confirm_password'] = "asdfads123f";
506   - $_POST['full_name'] = "My Full Name";
507   - $_POST['timezone'] = "America/Los_Angeles";
508   -
509   - $_SERVER['HTTP_HOST'] = "http://example.com";
510   -
511   - $controller = new InstallerController(true);
512   - $this->assertTrue(isset($controller));
513   - $result = $controller->go();
514   -
515   - $this->assertPattern('/ThinkUp couldn\'t connect to your database./', $result);
516   - //Different systems get different errors
517   - //$this->assertPattern('/Unknown MySQL server host \'localcheese\'/', $result);
518   - //$this->assertPattern('/php_network_getaddresses: getaddrinfo failed', $result);
519   - $this->restoreConfigFile();
520   - ini_set("error_reporting", E_ALL);
521   - }
522   - */
  471 + public function testFreshInstallStep3InvalidDatabaseHost() {
  472 + self::time(__METHOD__);
  473 + //get valid connection information
  474 + $config = Config::getInstance();
  475 + $valid_db_socket = $config->getValue('db_socket');
  476 + $valid_db_user = $config->getValue('db_user');
  477 + $valid_db_password = $config->getvalue('db_password');
  478 + $valid_db_port = $config->getValue('db_port');
  479 +
  480 + //drop DB
  481 + $this->testdb_helper->drop($this->test_database_name);
  482 + //remove config file
  483 + Config::destroyInstance();
  484 + //unset PDO so it must be recreated
  485 + InstallerMySQLDAO::$PDO = null;
  486 + $this->removeConfigFile();
  487 +
  488 + ini_set("error_reporting", E_ERROR);
  489 +
  490 + //set param for step 2
  491 + $_GET['step'] = '3';
  492 + //set post values from form
  493 + $_POST['site_email'] = "you@example.com";
  494 + $_POST['db_user'] = $valid_db_user;
  495 + $_POST['db_passwd'] = $valid_db_password;
  496 + $_POST['db_name'] = "mythinkupdb";
  497 + $_POST['db_type'] = "mysql";
  498 + $_POST['db_host'] = "127.0.0.2";
  499 + $_POST['db_socket'] = $valid_db_socket;
  500 + $_POST['db_port'] = $valid_db_port;
  501 + $_POST['db_prefix'] = "tu_";
  502 + $_POST['password'] = "asdfads123f";
  503 + $_POST['confirm_password'] = "asdfads123f";
  504 + $_POST['full_name'] = "My Full Name";
  505 + $_POST['timezone'] = "America/Los_Angeles";
  506 +
  507 + $_SERVER['HTTP_HOST'] = "http://example.com";
  508 +
  509 + $controller = new InstallerController(true);
  510 + $this->assertTrue(isset($controller));
  511 + $result = $controller->go();
  512 +
  513 + $this->assertPattern('/ThinkUp couldn\'t connect to your database./', $result);
  514 + //Different systems get different errors
  515 + //$this->assertPattern('/Unknown MySQL server host \'localcheese\'/', $result);
  516 + //$this->assertPattern('/php_network_getaddresses: getaddrinfo failed', $result);
  517 + $this->restoreConfigFile();
  518 + ini_set("error_reporting", E_ALL);
  519 + }
523 520
524 521 public function testFreshInstallStep3SuccessfulInstall() {
525 522 self::time(__METHOD__);
@@ -598,6 +595,6 @@ public function testRepairProcess() {
598 595 $_POST["repair"] = "yespls";
599 596 $controller = new InstallerController(true);
600 597 $result = $controller->go();
601   - $this->assertPattern("/Created table tu_encoded_locations/", $result);
  598 + $this->assertPattern("/Created table " . $config->getValue('table_prefix') . "encoded_locations/", $result);
602 599 }
603 600 }
63 tests/TestOfInstallerMySQLDAO.php
@@ -134,6 +134,9 @@ public function testExamineQueries() {
134 134 // test on complete table set; this should return just the INSERT query into plugins table
135 135 $config = Config::getInstance();
136 136 $config_array = $config->getValuesArray();
  137 + if ($config_array['table_prefix'] != 'tu_') {
  138 + $install_queries = str_replace('tu_', $config_array['table_prefix'], $install_queries);
  139 + }
137 140 $dao = new InstallerMySQLDAO($config_array);
138 141 $output = $dao->diffDataStructure($install_queries, $dao->getTables());
139 142
@@ -179,11 +182,13 @@ public function testExamineQueries() {
179 182 public function testNeedsSnowflakeUpgrade() {
180 183 $dao = new InstallerMySQLDAO();
181 184 $this->assertFalse($dao->needsSnowflakeUpgrade());
182   - $this->testdb_helper->runSQL('ALTER TABLE tu_posts CHANGE post_id post_id bigint(11) NOT NULL;');
  185 + $this->testdb_helper->runSQL('ALTER TABLE #prefix#posts CHANGE post_id post_id bigint(11) NOT NULL;');
183 186 $this->assertTrue($dao->needsSnowflakeUpgrade());
184 187 }
185 188
186 189 public function testRunMigration() {
  190 + $config = Config::getInstance();
  191 + $config_array = $config->getValuesArray();
187 192 $dao = new InstallerMySQLDAO();
188 193 $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)');
189 194
@@ -192,18 +197,18 @@ public function testRunMigration() {
192 197 $dao->runMigrationSQL('bad sql');
193 198 $this->fail('should throw exception');
194 199 } catch (Exception $e) {
195   - $this->assertTrue(true, 'should thow exception');
  200 + $this->assertTrue(true, 'should throw exception');
196 201 }
197 202 try {
198 203 $dao->runMigrationSQL('insert into tu_test2 (valuee) VALUES ("a")');
199 204 $this->fail('should throw exception');
200 205 } catch (Exception $e) {
201   - $this->assertTrue(true, 'should thow exception');
  206 + $this->assertTrue(true, 'should throw exception');
202 207 }
203 208
204 209 // old migration
205   - $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (1)");
206   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_test2");
  210 + $dao->runMigrationSQL('insert into tu_test2 (value) VALUES (1)');
  211 + $stmt = InstallerMySQLDAO::$PDO->query('select * from tu_test2');
207 212 $data = $stmt->fetchAll();
208 213 $this->assertEqual(1, $data[0]['value']);
209 214
@@ -212,25 +217,27 @@ public function testRunMigration() {
212 217 "insert into tu_test2 (value) VALUES (2);" .
213 218 "insert into tu_test2 (value) VALUES (3)");
214 219
215   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_test2");
  220 + $stmt = InstallerMySQLDAO::$PDO->query('select * from tu_test2');
216 221 $data = $stmt->fetchAll();
217 222 $this->assertEqual(2, $data[0]['value']);
218 223 $this->assertEqual(3, $data[1]['value']);
219   -
220 224 }
221 225
222 226 public function testRunNewMigrationNoTable() {
  227 + $config = Config::getInstance();
  228 + $config_array = $config->getValuesArray();
223 229 $dao = new InstallerMySQLDAO();
224 230 $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)');
225   - $this->testdb_helper->runSQL('DROP TABLE IF EXISTS tu_completed_migrations');
  231 + $this->testdb_helper->runSQL('DROP TABLE IF EXISTS #prefix#completed_migrations');
226 232
227 233 $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);", true, $filename = 'a_file');
228 234
229 235 // tu_completed_migrations table should now exists
230   - $stmt = InstallerMySQLDAO::$PDO->query("SHOW TABLES LIKE 'tu_completed_migrations'");
  236 + $stmt = InstallerMySQLDAO::$PDO->query("SHOW TABLES LIKE '" . $config_array['table_prefix'] .
  237 + "completed_migrations'");
231 238 $data = $stmt->fetchAll();
232 239 $this->assertEqual(1, count($data));
233   - $this->assertEqual($data[0][0], "tu_completed_migrations");
  240 + $this->assertEqual($data[0][0], $config_array['table_prefix'] . "completed_migrations");
234 241
235 242 // migration should have run
236 243 $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_test2");
@@ -238,16 +245,18 @@ public function testRunNewMigrationNoTable() {
238 245 $this->assertEqual(2, $data[0]['value']);
239 246
240 247 // tu_completed_migrations table should contan a record for our latest migration
241   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations");
  248 + $stmt = InstallerMySQLDAO::$PDO->query("select * from " . $config_array['table_prefix'] .
  249 + "completed_migrations");
242 250 $data = $stmt->fetchAll();
243 251 $this->assertEqual($data[0]['migration'], 'a_file-0');
244   -
245 252 }
246 253
247 254 public function testRunNewMigrationsTwice() {
  255 + $config = Config::getInstance();
  256 + $config_array = $config->getValuesArray();
248 257 $dao = new InstallerMySQLDAO();
249 258 $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)');
250   - $this->testdb_helper->runSQL('DROP TABLE IF EXISTS tu_completed_migrations');
  259 + $this->testdb_helper->runSQL('DROP TABLE IF EXISTS #prefix#completed_migrations');
251 260
252 261 $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);", true, $filename = 'a_file');
253 262
@@ -258,14 +267,15 @@ public function testRunNewMigrationsTwice() {
258 267 $this->assertEqual(2, $data[0]['value']);
259 268
260 269 // tu_completed_migrations table should contain a record for our latest migration
261   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations");
  270 + $stmt = InstallerMySQLDAO::$PDO->query("select * from " . $config_array['table_prefix'] .
  271 + "completed_migrations");
262 272 $data = $stmt->fetchAll();
263 273 $this->assertEqual(count($data), 1);
264 274 $this->assertEqual($data[0]['migration'], 'a_file-0');
265 275
266 276 $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);" .
267 277 "insert into tu_test2 (value) VALUES (3);" .
268   - "insert into tu_test2 (value) VALUES (4);",
  278 + "insert into tu_test2 (value) VALUES (4);",
269 279 true, $filename = 'a_file');
270 280
271 281 // migration should have run
@@ -277,7 +287,8 @@ public function testRunNewMigrationsTwice() {
277 287 $this->assertEqual(4, $data[2]['value']);
278 288
279 289 // tu_completed_migrations table should contain a record for our latest migration
280   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations");
  290 + $stmt = InstallerMySQLDAO::$PDO->query("select * from " . $config_array['table_prefix'] .
  291 + "completed_migrations");
281 292 $data = $stmt->fetchAll();
282 293 $this->assertEqual(count($data), 3);
283 294 $this->assertEqual($data[0]['migration'], 'a_file-0');
@@ -286,15 +297,17 @@ public function testRunNewMigrationsTwice() {
286 297 }
287 298
288 299 public function testRunNewMigrationsSkipIfExists() {
  300 + $config = Config::getInstance();
  301 + $config_array = $config->getValuesArray();
289 302 $dao = new InstallerMySQLDAO();
290 303 $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)');
291   - $this->testdb_helper->runSQL('DROP TABLE IF EXISTS tu_completed_migrations');
  304 + $this->testdb_helper->runSQL('DROP TABLE IF EXISTS #prefix#completed_migrations');
292 305
293 306 $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);" .
294 307 "insert into tu_test2 (value) VALUES (3);" .
295 308 "DROP TABLE IF EXISTS tu_users_b16;" .
296 309 "insert into tu_test2 (value) VALUES (4);" .
297   - "insert into tu_test2 (value) VALUES (5);",
  310 + "insert into tu_test2 (value) VALUES (5);",
298 311 true, $filename = 'a_file');
299 312
300 313 // migration should have run
@@ -307,7 +320,8 @@ public function testRunNewMigrationsSkipIfExists() {
307 320 $this->assertEqual(5, $data[3]['value']);
308 321
309 322 // tu_completed_migrations table should contain a record for our latest migration
310   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations");
  323 + $stmt = InstallerMySQLDAO::$PDO->query("select * from " . $config_array['table_prefix'] .
  324 + "completed_migrations");
311 325 $data = $stmt->fetchAll();
312 326 $this->assertEqual(count($data), 4);
313 327 $this->assertEqual($data[0]['migration'], 'a_file-0');
@@ -317,15 +331,17 @@ public function testRunNewMigrationsSkipIfExists() {
317 331 }
318 332
319 333 public function testRunNewMigrationStripsVersionForStorage() {
  334 + $config = Config::getInstance();
  335 + $config_array = $config->getValuesArray();
320 336 $dao = new InstallerMySQLDAO();
321 337 $this->testdb_helper->runSQL('CREATE TABLE `tu_test2` (`value` int(11) NOT NULL)');
322   - $this->testdb_helper->runSQL('DROP TABLE IF EXISTS tu_completed_migrations');
  338 + $this->testdb_helper->runSQL('DROP TABLE IF EXISTS #prefix#completed_migrations');
323 339
324 340 $dao->runMigrationSQL("insert into tu_test2 (value) VALUES (2);" .
325 341 "insert into tu_test2 (value) VALUES (3);" .
326 342 "DROP TABLE IF EXISTS tu_users_b16;" .
327 343 "insert into tu_test2 (value) VALUES (4);" .
328   - "insert into tu_test2 (value) VALUES (5);",
  344 + "insert into tu_test2 (value) VALUES (5);",
329 345 true, $filename = 'a_file_v0.13.sql');
330 346
331 347 // migration should have run
@@ -338,7 +354,8 @@ public function testRunNewMigrationStripsVersionForStorage() {
338 354 $this->assertEqual(5, $data[3]['value']);
339 355
340 356 // tu_completed_migrations table should contain a record for our latest migration
341   - $stmt = InstallerMySQLDAO::$PDO->query("select * from tu_completed_migrations");
  357 + $stmt = InstallerMySQLDAO::$PDO->query("select * from " . $config_array['table_prefix'] .
  358 + "completed_migrations");
342 359 $data = $stmt->fetchAll();
343 360 $this->assertEqual(count($data), 4);
344 361 $this->assertEqual($data[0]['migration'], 'a_file-0');
@@ -346,4 +363,4 @@ public function testRunNewMigrationStripsVersionForStorage() {
346 363 $this->assertEqual($data[2]['migration'], 'a_file-2');
347 364 $this->assertEqual($data[3]['migration'], 'a_file-3');
348 365 }
349   -}
  366 +}
6 tests/TestOfInstanceMySQLDAO.php
@@ -182,7 +182,9 @@ public function testGetInstanceOneByLastRun(){
182 182 $this->assertEqual($result->network_user_id, 10);
183 183 $this->assertEqual($result->network_viewer_id, 10);
184 184
185   - $q = "TRUNCATE TABLE tu_instances ";
  185 + $config = Config::getInstance();
  186 + $config_array = $config->getValuesArray();
  187 + $q = "TRUNCATE TABLE " . $config_array['table_prefix'] . "instances ";
186 188 PDODAO::$PDO->exec($q);
187 189
188 190 //Try empty
@@ -742,4 +744,4 @@ public function testUpdateInstanceUsername() {
742 744 $instance = $this->DAO->getByUsername('johndoe2');
743 745 $this->assertEqual($instance->network_username, "johndoe2" );
744 746 }
745   -}
  747 +}
8 tests/TestOfLinkMySQLDAO.php
@@ -415,15 +415,19 @@ public function testGetLinksToExpandByURL() {
415 415 * Set counter higher to avoid clashes w/ prev inserts.
416 416 */
417 417 public function testUniqueConstraint1() {
  418 + $config = Config::getInstance();
  419 + $config_array = $config->getValuesArray();
418 420 $counter = 2000;
419 421 $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
420 422 $source = '<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>';
421   - $q = "INSERT IGNORE INTO tu_links (url, title, clicks, post_key, image_src) ";
  423 + $q = "INSERT IGNORE INTO " . $config_array['table_prefix'] .
  424 + "links (url, title, clicks, post_key, image_src) ";
422 425 $q .= " VALUES ('http://example.com/".$counter."', 'Link $counter', 0, $counter, '');";
423 426 $res = PDODAO::$PDO->exec($q);
424 427 $this->assertEqual($res, 1);
425 428
426   - $q = "INSERT IGNORE INTO tu_links (url, title, clicks, post_key, image_src) ";
  429 + $q = "INSERT IGNORE INTO " . $config_array['table_prefix'] .
  430 + "links (url, title, clicks, post_key, image_src) ";
427 431 $q .= " VALUES ('http://example.com/".$counter."', 'Link $counter', 0, $counter, '');";
428 432 $res = PDODAO::$PDO->exec($q);
429 433 $this->assertEqual($res, 0);
32 tests/TestOfPDODAO.php
@@ -39,9 +39,11 @@ public function setUp() {
39 39 }
40 40
41 41 protected function buildData() {
  42 + $config = Config::getInstance();
  43 + $config_array = $config->getValuesArray();
42 44 $builders = array();
43 45
44   - $test_table_sql = 'CREATE TABLE tu_test_table(' .
  46 + $test_table_sql = 'CREATE TABLE ' . $config_array['table_prefix'] . 'test_table(' .
45 47 'id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,' .
46 48 'test_name varchar(20),' .
47 49 'test_id int(11),' .
@@ -285,17 +287,25 @@ public function testIsPattern() {
285 287 }
286 288
287 289 public function testInstantiateDaoWithoutConfigFile() {
  290 + $config = Config::getInstance();
  291 + $config_array = $config->getValuesArray();
288 292 $this->builders = self::buildData();
289   - $this->removeConfigFile();
290   - Config::destroyInstance();
291   - $cfg_values = array("table_prefix"=>"tu_", "db_host"=>"localhost");
292   - $config = Config::getInstance($cfg_values);
293   - $test_dao = new TestMySQLDAO($cfg_values);
294   - $users = $test_dao->getUserCount(0, 'mary');
295   - $this->assertIsA($users, "array");
296   - $this->assertEqual(count($users), 2);
297   - $this->assertEqual($users[0]['user_name'], 'mary');
298   - $this->assertEqual($users[1]['user_name'], 'sweetmary');
  293 + try {
  294 + $this->removeConfigFile();
  295 + Config::destroyInstance();
  296 + $cfg_values = array("table_prefix"=> $config_array['table_prefix'], "db_host"=>"localhost");
  297 + $config = Config::getInstance($cfg_values);
  298 + $test_dao = new TestMySQLDAO($cfg_values);
  299 + $users = $test_dao->getUserCount(0, 'mary');
  300 + $this->assertIsA($users, "array");
  301 + $this->assertEqual(count($users), 2);
  302 + $this->assertEqual($users[0]['user_name'], 'mary');
  303 + $this->assertEqual($users[1]['user_name'], 'sweetmary');
  304 + } catch (Exception $e) {
  305 + // restore config file if something goes wrong
  306 + $this->restoreConfigFile();
  307 + throw $e;
  308 + }
299 309 $this->restoreConfigFile();
300 310 }
301 311
8 tests/TestOfPostMySQLDAO.php
@@ -2140,17 +2140,21 @@ public function testGetClientsUsedByUserOnNetwork() {
2140 2140 * Set counter higher to avoid clashes w/ prev post inserts.
2141 2141 */
2142 2142 public function testUniqueConstraint1() {
  2143 + $config = Config::getInstance();
  2144 + $config_array = $config->getValuesArray();
2143 2145 $counter = 1000;
2144 2146 $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
2145 2147 $source = '<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>';
2146   - $q = "INSERT IGNORE INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
  2148 + $q = "INSERT IGNORE INTO " . $config_array['table_prefix'] .
  2149 + "posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
2147 2150 post_text, source, pub_date, reply_count_cache, retweet_count_cache, network) VALUES
2148 2151 ($counter, 13, 'ev', 'Ev Williams', 'avatar.jpg',
2149 2152 'This is post $counter', '$source', '2006-01-01 00:$pseudo_minute:00', ".rand(0, 4).", 5, 'twitter');";
2150 2153 $res = PDODAO::$PDO->exec($q);
2151 2154 $this->assertEqual($res, 1);
2152 2155
2153   - $q = "INSERT IGNORE INTO tu_posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
  2156 + $q = "INSERT IGNORE INTO " . $config_array['table_prefix'] .
  2157 + "posts (post_id, author_user_id, author_username, author_fullname, author_avatar,
2154 2158 post_text, source, pub_date, reply_count_cache, retweet_count_cache, network) VALUES
2155 2159 ($counter, 13, 'ev', 'Ev Williams', 'avatar.jpg',
2156 2160 'This is post $counter', '$source', '2006-01-01 00:$pseudo_minute:00', ".rand(0, 4).", 5, 'twitter');";
4 tests/TestOfSmartyThinkUp.php
@@ -45,7 +45,7 @@ public function testNewSmartyThinkUp() {
45 45 */
46 46 public function testSmartyThinkUpDefaultValues() {
47 47 $cfg = Config::getInstance();
48   - $cfg->setValue('source_root_path', '/path/to/thinkup/');
  48 + $cfg->setValue('source_root_path', '/path/to/thinkup');
49 49 $cfg->setValue('cache_pages', true);
50 50 $cfg->setValue('cache_lifetime', 600);
51 51 $v_mgr = new SmartyThinkUp();
@@ -168,4 +168,4 @@ public function testAddSuccessMessage() {
168 168 $this->assertEqual($debug_arr['fieldname2'], 'Field level info 2');
169 169 $this->debug(Utils::varDumpToString($debug_arr));
170 170 }
171   -}
  171 +}
2  tests/TestOfThinkUpEmbedController.php
@@ -24,7 +24,7 @@
24 24 * @license http://www.gnu.org/licenses/gpl.html
25 25 * @copyright 2009-2012 Gina Trapani
26 26 */
27   -require_once 'tests/init.tests.php';
  27 +require_once dirname(__FILE__) . '/init.tests.php';
28 28 require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
29 29 require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';
30 30
2  tests/TestOfThreadJSController.php
@@ -24,7 +24,7 @@
24 24 * @license http://www.gnu.org/licenses/gpl.html
25 25 * @copyright 2009-2012 Gina Trapani
26 26 */
27   -require_once 'tests/init.tests.php';
  27 +require_once dirname(__FILE__) . '/init.tests.php';
28 28 require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
29 29 require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';
30 30
76 tests/TestOfUpgradeController.php
@@ -104,7 +104,8 @@ public function testDatabaseMigrationNeeded() {
104 104 $v_mgr = $controller->getViewManager();
105 105 $queries = $v_mgr->getTemplateDataItem('migrations');
106 106 $this->assertEqual(1, count($queries), 'one migration query');
107   - $this->assertEqual(file_get_contents($this->test_migrations[0]), $queries[0]['sql']);
  107 + $this->assertEqual(str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0])),
  108 + $queries[0]['sql']);
108 109
109 110 $this->test_migrations = array(); //clear out old data
110 111 $this->migrationFiles(2);
@@ -114,8 +115,10 @@ public function testDatabaseMigrationNeeded() {
114 115 $v_mgr = $controller->getViewManager();
115 116 $queries = $v_mgr->getTemplateDataItem('migrations');
116 117 $this->assertEqual(2, count($queries), 'two migration query');
117   - $this->assertEqual(file_get_contents($this->test_migrations[0]), $queries[1]['sql']);
118   - $this->assertEqual(file_get_contents($this->test_migrations[1]), $queries[0]['sql']);
  118 + $this->assertEqual(str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0])),
  119 + $queries[1]['sql']);
  120 + $this->assertEqual(str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[1])),
  121 + $queries[0]['sql']);
119 122 }
120 123
121 124 public function testDatabaseMigrationNeededHighTableCount() {
@@ -190,7 +193,7 @@ public function testGetMigrationListWithNewSQL() {
190 193 $sql = preg_replace('/\-\-.*/','', $migration['sql']);
191 194 $install_dao->runMigrationSQL($sql, $migration['new_migration'], $migration['filename']);
192 195 }
193   - $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
  196 + $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
194 197 $data = $stmt->fetchAll();
195 198 $this->assertEqual(count($data), 5);
196 199 $this->assertEqual($data[0]['migration'], '2011-09-21_some_stuff2-0');
@@ -202,11 +205,11 @@ public function testGetMigrationListWithNewSQL() {
202 205 // run same migration file now as a versioned file with one new sql line
203 206 $migration = $clean_list[0];
204 207 $filename = $migration['filename'] = '2011-09-21_some_stuff2_v1.1.sql';
205   - $migration['sql'] .= "\nINSERT INTO " . $this->table_prefix . "test1 (value) VALUES (5);";
  208 + $migration['sql'] .= "\nINSERT INTO " . $this->table_prefix . "test1 (value) VALUES (5);";
206 209 $sql = preg_replace('/\-\-.*/','', $migration['sql']);
207 210 $install_dao->runMigrationSQL($sql, $migration['new_migration'], $filename);
208 211
209   - $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
  212 + $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
210 213 $data2 = $stmt->fetchAll();
211 214 $this->assertEqual(count($data2), 6);
212 215 $this->assertEqual($data2[0]['migration'], '2011-09-21_some_stuff2-0');
@@ -232,15 +235,15 @@ public function testRunNewMigration() {
232 235 $results = $controller->go();
233 236 $obj = json_decode($results);
234 237 $this->assertTrue($obj->processed);
235   - $sql = file_get_contents($this->test_migrations[0]);
  238 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
236 239 $sql = preg_replace('/\-\-.*/','', $sql);
237 240 $this->assertEqual($obj->sql, $sql);
238 241
239   - $sql = "show tables like '" . $this->table_prefix . "test1'";
  242 + $sql = "show tables like '" . $this->table_prefix . "test1'";
240 243 $stmt = $this->pdo->query($sql);
241 244 $data = $stmt->fetch();
242   - $this->assertEqual($data[0], $this->table_prefix . "test1");
243   - $sql = 'select * from ' . $this->table_prefix . "test1";
  245 + $this->assertEqual($data[0], $this->table_prefix . 'test1');
  246 + $sql = 'select * from ' . $this->table_prefix . 'test1';
244 247 $stmt = $this->pdo->query($sql);
245 248 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
246 249 $this->assertEqual(count($data), 3);
@@ -248,7 +251,7 @@ public function testRunNewMigration() {
248 251 $this->assertEqual($data[1]['value'], 2);
249 252 $this->assertEqual($data[2]['value'], 3);
250 253 // tu_completed_migrations table should contain a record for our latest migration
251   - $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
  254 + $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
252 255 $data = $stmt->fetchAll();
253 256 $this->assertEqual(count($data), 3);
254 257 $this->assertEqual($data[0]['migration'], '2011-09-21_some_stuff-0');
@@ -256,16 +259,16 @@ public function testRunNewMigration() {
256 259 $this->assertEqual($data[2]['migration'], '2011-09-21_some_stuff-2');
257 260
258 261 // run it againto veriy it skips alrready run migrations, but add a new one as well
259   - $new_sql = "INSERT INTO " . $this->table_prefix . "test1 (value) VALUES (4),(5),(6);";
  262 + $new_sql = "INSERT INTO " . $this->table_prefix . "test1 (value) VALUES (4),(5),(6);";
260 263 $this->newMigrationFiles('some_stuff', false, $new_sql);
261 264 $_GET['migration_index'] = 1;
262 265 $results = $controller->go();
263 266 $obj = json_decode($results);
264 267 $this->assertTrue($obj->processed);
265   - $sql = file_get_contents($this->test_migrations[0]);
  268 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
266 269 $sql = preg_replace('/\-\-.*/','', $sql);
267 270 $this->assertEqual($obj->sql, $sql);
268   - $sql = 'select * from ' . $this->table_prefix . 'test1';
  271 + $sql = 'select * from ' . $this->table_prefix . 'test1';
269 272 $stmt = $this->pdo->query($sql);
270 273 $data2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
271 274 $this->assertEqual(count($data2), 6);
@@ -276,7 +279,7 @@ public function testRunNewMigration() {
276 279 $this->assertEqual($data2[4]['value'], 5);
277 280 $this->assertEqual($data2[5]['value'], 6);
278 281
279   - $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
  282 + $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
280 283 $data2 = $stmt->fetchAll();
281 284 $this->assertEqual(count($data2), 4);
282 285 $this->assertEqual($data2[0]['migration'], '2011-09-21_some_stuff-0');
@@ -357,6 +360,7 @@ public function testRunNewMigrationUpdateCompletedTable() {
357 360 $com_sql_file = THINKUP_ROOT_PATH.'webapp/install/sql/completed_migrations.sql';
358 361 //echo $com_sql_file;
359 362 $com_sql = file_get_contents($com_sql_file);
  363 + $com_sql = str_replace('tu_', $this->table_prefix, $com_sql);
360 364 $this->pdo->query($com_sql);
361 365 $this->pdo->query("alter table " . $this->table_prefix . "completed_migrations DROP column sql_ran");
362 366
@@ -366,6 +370,7 @@ public function testRunNewMigrationUpdateCompletedTable() {
366 370 $this->assertTrue($obj->processed);
367 371 $sql = file_get_contents($this->test_migrations[0]);
368 372 $sql = preg_replace('/\-\-.*/','', $sql);
  373 + $sql = str_replace('tu_', $this->table_prefix, $sql);
369 374 $this->assertEqual($obj->sql, $sql);
370 375 $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations");
371 376 $data2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -542,15 +547,15 @@ public function testProcessOneMigrations() {
542 547 $results = $controller->go();
543 548 $obj = json_decode($results);
544 549 $this->assertTrue($obj->processed);
545   - $sql_file = file_get_contents($this->test_migrations[0]);
  550 + $sql_file = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
546 551 $sql_file = preg_replace('/\-\-.*/','', $sql_file);
547 552 $this->assertEqual($obj->sql, $sql_file);
548 553
549   - $sql = "show tables like '" . $this->table_prefix . "test1'";
  554 + $sql = "show tables like '" . $this->table_prefix . "test1'";
550 555 $stmt = $this->pdo->query($sql);
551 556 $data = $stmt->fetch();
552   - $this->assertEqual($data[0], $this->table_prefix . 'test1');
553   - $sql = 'select * from ' . $this->table_prefix . 'test1';
  557 + $this->assertEqual($data[0], $this->table_prefix . 'test1');
  558 + $sql = 'select * from ' . $this->table_prefix . 'test1';
554 559 $stmt = $this->pdo->query($sql);
555 560 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
556 561 $this->assertEqual(count($data), 3);
@@ -568,15 +573,15 @@ public function testProcessMinorVersionMigration() {
568 573 $results = $controller->go();
569 574 $obj = json_decode($results);
570 575 $this->assertTrue($obj->processed);
571   - $sql = file_get_contents($this->test_migrations[0]);
  576 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
572 577 $sql = preg_replace('/\-\-.*/','', $sql);
573 578 $this->assertEqual($obj->sql, $sql);
574 579
575   - $sql = "show tables like '" . $this->table_prefix . "test1'";
  580 + $sql = "show tables like '" . $this->table_prefix . "test1'";
576 581 $stmt = $this->pdo->query($sql);
577 582 $data = $stmt->fetch();
578   - $this->assertEqual($data[0], $this->table_prefix . 'test1');
579   - $sql = 'select * from ' . $this->table_prefix . 'test1';
  583 + $this->assertEqual($data[0], $this->table_prefix . 'test1');
  584 + $sql = 'select * from ' . $this->table_prefix . 'test1';
580 585 $stmt = $this->pdo->query($sql);
581 586 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
582 587 $this->assertEqual(count($data), 3);
@@ -594,15 +599,15 @@ public function testProcessMinorBetaVersionMigration() {
594 599 $results = $controller->go();
595 600 $obj = json_decode($results);
596 601 $this->assertTrue($obj->processed);
597   - $sql = file_get_contents($this->test_migrations[0]);
  602 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
598 603 $sql = preg_replace('/\-\-.*/','', $sql);
599 604 $this->assertEqual($obj->sql, $sql);
600 605
601   - $sql = "show tables like '" . $this->table_prefix . "test1'";
  606 + $sql = "show tables like '" . $this->table_prefix . "test1'";
602 607 $stmt = $this->pdo->query($sql);
603 608 $data = $stmt->fetch();
604   - $this->assertEqual($data[0], $this->table_prefix . 'test1');
605   - $sql = 'select * from ' . $this->table_prefix . 'test1';
  609 + $this->assertEqual($data[0], $this->table_prefix . 'test1');
  610 + $sql = 'select * from ' . $this->table_prefix . 'test1';
606 611 $stmt = $this->pdo->query($sql);
607 612 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
608 613 $this->assertEqual(count($data), 3);
@@ -679,15 +684,15 @@ public function testProcessTwoMigrations() {
679 684 $results = $controller->go();
680 685 $obj = json_decode($results);
681 686 $this->assertTrue($obj->processed);
682   - $sql = file_get_contents($this->test_migrations[1]);
  687 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[1]));
683 688 $sql = preg_replace('/\-\-.*/','', $sql);
684 689 $this->assertEqual($obj->sql, $sql);
685 690
686   - $sql = "show tables like '" . $this->table_prefix . "test2'";
  691 + $sql = "show tables like '" . $this->table_prefix . "test2'";
687 692 $stmt = $this->pdo->query($sql);
688 693 $data = $stmt->fetch();
689 694 $this->assertEqual($data[0], $this->table_prefix . 'test2');
690   - $sql = 'select * from ' . $this->table_prefix . 'test2';
  695 + $sql = 'select * from ' . $this->table_prefix . 'test2';
691 696 $stmt = $this->pdo->query($sql);
692 697 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
693 698 $this->assertEqual(count($data), 1);
@@ -696,15 +701,15 @@ public function testProcessTwoMigrations() {
696 701 $results = $controller->go();
697 702 $obj = json_decode($results);
698 703 $this->assertTrue($obj->processed);
699   - $sql = file_get_contents($this->test_migrations[0]);
  704 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
700 705 $sql = preg_replace('/\-\-.*/','', $sql);
701 706 $this->assertEqual($obj->sql, $sql);
702 707
703   - $sql = "show tables like '" . $this->table_prefix . "test1'";
  708 + $sql = "show tables like '" . $this->table_prefix . "test1'";
704 709 $stmt = $this->pdo->query($sql);
705 710 $data = $stmt->fetch();
706 711 $this->assertEqual($data[0], $this->table_prefix . 'test1');
707   - $sql = 'select * from ' . $this->table_prefix . 'test1';
  712 + $sql = 'select * from ' . $this->table_prefix . 'test1';
708 713 $stmt = $this->pdo->query($sql);
709 714 $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
710 715 $this->assertEqual(count($data), 3);
@@ -727,7 +732,7 @@ public function testProcessMigrationWithAToken() {
727 732 $results = $controller->go();
728 733 $obj = json_decode($results);
729 734 $this->assertTrue($obj->processed);
730   - $sql = file_get_contents($this->test_migrations[0]);
  735 + $sql = str_replace('tu_', $this->table_prefix, file_get_contents($this->test_migrations[0]));
731 736 $sql = preg_replace('/\-\-.*/','', $sql);
732 737 $this->assertEqual($obj->sql, $sql);
733 738 }
@@ -783,6 +788,7 @@ public function testMigrationDoneWithToken() {
783 788 public function testProcessMigrationsDifferentPrefix() {
784 789
785 790 $config = Config::getInstance();
  791 + $old_table_prefix = $config->getValue('table_prefix');
786 792 $config->setValue('table_prefix', 'new_prefix_');
787 793
788 794 $stmt = $this->pdo->query("show tables");
@@ -791,7 +797,7 @@ public function testProcessMigrationsDifferentPrefix() {
791 797 //var_dump($data);
792 798 foreach($data as $table) {
793 799 foreach($table as $key=> $value) {
794   - $new_value = preg_replace("/tu_/", " new_prefix_", $value);
  800 + $new_value = preg_replace("/^" . $old_table_prefix . "/", " new_prefix_", $value);
795 801 $sql = "RENAME TABLE $value TO $new_value";
796 802 $this->pdo->query($sql);
797 803 }
9 tests/TestOfUtils.php
@@ -55,10 +55,12 @@ public function testBaseUrlConstant() {
55 55 public function testgetPluginViewDirectory() {
56 56 $config = Config::getInstance();
57 57 $path = Utils::getPluginViewDirectory('twitter');
58   - $this->assertEqual($path, $config->getValue('source_root_path').'webapp/plugins/twitter/view/');
  58 + $this->assertEqual(realpath($path), realpath($config->getValue('source_root_path').
  59 + '/webapp/plugins/twitter/view/'));
59 60
60 61 $path = Utils::getPluginViewDirectory('sweetmaryjane');
61   - $this->assertEqual($path, $config->getValue('source_root_path').'webapp/plugins/sweetmaryjane/view/');
  62 + $this->assertEqual(realpath($path), realpath($config->getValue('source_root_path').
  63 + '/webapp/plugins/sweetmaryjane/view/'));
62 64 }
63 65
64 66 public function testGetPercentage(){
@@ -220,7 +222,6 @@ public function testPredictNextMilestoneDate() {
220 222 $expected = array('next_milestone'=>100, 'will_take'=>5);
221 223 $this->assertEqual(Utils::predictNextMilestoneDate(75, 5), $expected);
222 224 }
223   -
224 225 public function testGetLastSaturday() {
225 226 $last_saturday = Utils::getLastSaturday('11/11/2011');
226 227 $this->assertEqual('11/5', $last_saturday);
@@ -228,4 +229,4 @@ public function testGetLastSaturday() {
228 229 $last_saturday = Utils::getLastSaturday('11/6/2011');
229 230 $this->assertEqual('11/5', $last_saturday);
230 231 }