Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix file permission-related test failures
  • Loading branch information
ginatrapani committed Mar 15, 2012
1 parent 59f1d15 commit 0e93f7f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .gitignore
@@ -1,7 +1,8 @@
webapp/config.inc.php
webapp/config.inc.bak.php
webapp/data/
data/
!tests/data
!webapp/data/README.md
tests/config.tests.inc.php
.*
extras/cron/config
Expand All @@ -11,6 +12,5 @@ extras/scripts/lic_header.py
extras/scripts/test-pull-postback-conf
webapp/test_installer/*
webapp/plugins/twitterrealtime/streaming/*.pid
build/*
docs/build/*
build/
extras/dev/ramdisk/osx_make_ramdisk_db.conf
27 changes: 12 additions & 15 deletions tests/WebTestOfInstallation.php
Expand Up @@ -39,34 +39,31 @@ public function setUp() {
//Make sure test_installer directory exists
chdir(dirname(__FILE__) . '/../');
if (!file_exists($THINKUP_CFG['source_root_path'].'/webapp/test_installer/')) {
exec('mkdir webapp/test_installer/');
@exec('mkdir webapp/test_installer/');
@exec('chmod -R 777 webapp/test_installer/');
}

//Clean up files from test installation
exec('rm -rf webapp/test_installer/*');
//Generate new user distribution based on current state of the tree
exec('extras/scripts/generate-distribution');
@exec('extras/scripts/generate-distribution');
//Extract into test_installer directory and set necessary folder permissions
exec('cp build/thinkup.zip webapp/test_installer/.;'.
'cd webapp/test_installer/;'.
'unzip thinkup.zip;chmod -R 777 thinkup;'.
'cd thinkup;chmod -R 777 data;');
@exec('cp build/thinkup.zip webapp/test_installer/.;'.
'cd webapp/test_installer/;unzip thinkup.zip;'.
'mkdir thinkup/data/compiled_view/;chmod -R 777 thinkup;');
}

public function setUpCustomFolderInstallation() {
//Clean up files from test installation
exec('rm -rf webapp/test_installer/*');
exec('cp build/thinkup.zip webapp/test_installer/.;'.
'cd webapp/test_installer/;'.
'unzip thinkup.zip;mv thinkup mythinkupfolder; chmod -R 777 mythinkupfolder;'.
'cd mythinkupfolder;chmod -R 777 data;');
@exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer/*' );

@exec('cp build/thinkup.zip webapp/test_installer/.;'.
'cd webapp/test_installer/;unzip thinkup.zip;mv thinkup mythinkupfolder;'.
'mkdir mythinkupfolder/data/compiled_view;chmod -R 777 mythinkupfolder;');
}

public function tearDown() {
global $THINKUP_CFG;
//Clean up test installation files
chdir(dirname(__FILE__) . '/../');
exec('rm -rf webapp/test_installer/*');
@exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer/*' );

//Delete test database created during installation process
require THINKUP_WEBAPP_PATH.'config.inc.php';
Expand Down
41 changes: 25 additions & 16 deletions tests/WebTestOfUpgradeDatabase.php
Expand Up @@ -49,14 +49,13 @@ public function setUp() {
// Make sure test_installer and build directories exists
if (!file_exists($this->install_dir)) {
exec('mkdir ' . $this->install_dir);
exec('chmod -R 777 '.$this->install_dir);
}
if (!file_exists($this->installs_dir)) {
exec('mkdir ' . $this->installs_dir);
exec('chmod -R 777 '.$this->install_dir);
}

//Clean up files from test installation
exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer' . '/*');

$config = Config::getInstance();
$this->table_prefix = $config->getValue('table_prefix');

Expand All @@ -68,7 +67,7 @@ public function setUp() {

public function tearDown() {
//Clean up test installation files
@exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer' . '/*');
exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer/*' );

// Delete test database created during installation process
require THINKUP_WEBAPP_PATH.'config.inc.php';
Expand Down Expand Up @@ -161,12 +160,21 @@ private function setUpApp($version, $MIGRATIONS) {
require THINKUP_WEBAPP_PATH.'config.inc.php';
//install beta 1
$zipfile = $this->getInstall($zip_url, $version, $this->installs_dir);
$whoami = @exec('whoami');
//Extract into test_installer directory and set necessary folder permissions
chdir(dirname(__FILE__) . '/../');
exec('cp ' . $zipfile . ' webapp/test_installer/.;'.
'cd webapp/test_installer/;'.
'unzip ' . $zipfile . ';chown -R '.$whoami.' *; chmod -R 777 thinkup;');
'cd webapp/test_installer/;'.'unzip ' . $zipfile .';chmod -R 777 thinkup;');
if (!file_exists($this->install_dir.'/thinkup/data/compiled_view')) {
chdir(dirname(__FILE__) . '/../');
if (!file_exists($this->install_dir.'/thinkup/data')) {
exec('cd webapp/test_installer/;mkdir thinkup/data;');
}
exec('cd webapp/test_installer/;mkdir thinkup/data/compiled_view;chmod -R 777 thinkup;');
}
if (file_exists($this->install_dir.'/thinkup/_lib/view/compiled_view')) {
chdir(dirname(__FILE__) . '/../');
exec('cd webapp/test_installer/;chmod -R 777 thinkup/_lib/view/compiled_view;');
}

//Config file doesn't exist
$this->assertFalse(file_exists($THINKUP_CFG['source_root_path'].
Expand Down Expand Up @@ -287,12 +295,13 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
$this->debug("unzipping $zipfile");
chdir(dirname(__FILE__) . '/../');
//Extract into test_installer directory and set necessary folder permissions
exec('cp ' . $zipfile . ' webapp/test_installer/.;'.
'cd webapp/test_installer/;unzip -o ' . $zipfile);

// make sure new code with data directory has correct perms
if (file_exists($this->install_dir.'/thinkup/data/')) {
exec('chmod -R 777 webapp/test_installer/thinkup/data;');
exec('cp ' . $zipfile . ' webapp/test_installer/.;cd webapp/test_installer/;'.
'rm -rf thinkup/_lib/view/compiled_view;unzip -o ' . $zipfile.';');
if (!file_exists($this->install_dir.'/thinkup/data/compiled_view')) {
if (!file_exists($this->install_dir.'/thinkup/data')) {
exec('mkdir thinkup/data;');
}
exec('mkdir thinkup/data/compiled_view;chmod -R 777 thinkup');
}

// run updates and migrations
Expand Down Expand Up @@ -347,14 +356,14 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
$cnt = 0;
if (isset($json_array)) {
foreach($json_array as $json_migration) {
$this->debug("running migration: " . $json_migration->version);
$this->debug("Running migration: " . $json_migration->version);

// if there is setup_sql run it
if (isset($MIGRATIONS[$json_migration->version ]['setup_sql'])) {
$this->debug('running setup_sql scripts');
$this->debug('Running setup_sql scripts');
$install_dao = DAOFactory::getDAO('InstallerDAO');
foreach($MIGRATIONS[$json_migration->version ]['setup_sql'] as $sql) {
$this->debug('running setup_sql script: ' . substr($sql, 0, 40) . '...');
$this->debug('Running setup_sql script: ' . substr($sql, 0, 40) . '...');
$install_dao->runMigrationSQL($sql);
}
}
Expand Down
26 changes: 23 additions & 3 deletions tests/classes/class.ThinkUpBasicUnitTestCase.php
Expand Up @@ -82,11 +82,18 @@ public function tearDown() {
$backup_dir = FileDataManager::getBackupPath();
if (file_exists($backup_dir)) {
try {
exec('cd '.$backup_dir.'; rm -rf *');
@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();
}

Expand All @@ -107,7 +114,7 @@ protected function unsetArray(array &$array) {
protected function removeConfigFile() {
if (file_exists(THINKUP_WEBAPP_PATH . 'config.inc.php')) {
$cmd = 'mv '.THINKUP_WEBAPP_PATH . 'config.inc.php ' .THINKUP_WEBAPP_PATH . 'config.inc.bak.php';
exec($cmd, $output, $return_val);
@exec($cmd, $output, $return_val);
if ($return_val != 0) {
echo "Could not ".$cmd;
}
Expand All @@ -120,7 +127,7 @@ protected function removeConfigFile() {
protected function restoreConfigFile() {
if (file_exists(THINKUP_WEBAPP_PATH . 'config.inc.bak.php')) {
$cmd = 'mv '.THINKUP_WEBAPP_PATH . 'config.inc.bak.php ' .THINKUP_WEBAPP_PATH . 'config.inc.php';
exec($cmd, $output, $return_val);
@exec($cmd, $output, $return_val);
if ($return_val != 0) {
echo "Could not ".$cmd;
}
Expand Down Expand Up @@ -170,6 +177,19 @@ public static function isTestEnvironmentReady() {
if (!is_writable($datadir_path)) {
$message = "In order to test your ThinkUp installation, $datadir_path must be writable.";
}
if (!is_writable($datadir_path.'compiled_view/')) {
try {
@exec('cd '.$datadir_path.'; rm -rf compiled_view');
} catch (Exception $e) {
}
}
if (!file_exists($datadir_path.'compiled_view/')) {
mkdir($datadir_path.'compiled_view/');
@exec('chmod -R 777 '.$datadir_path.'compiled_view/');
}
if (!is_writable($datadir_path.'compiled_view/')) {
$message = "In order to test your ThinkUp installation, ".$datadir_path."compiled_view/ must be writable.";
}

if ($THINKUP_CFG['log_location'] === false) {
$message = "In order to test your ThinkUp installation, \$THINKUP_CFG['log_location'] must be set to a ".
Expand Down
14 changes: 3 additions & 11 deletions tests/classes/class.ThinkUpBasicWebTestCase.php
Expand Up @@ -45,11 +45,11 @@ public function setUp() {
putenv("MODE=TESTS");
$this->get($this->url.'/install/setmode.php?m=tests');

self::isWebTestEnvironmentReady();
ThinkUpBasicUnitTestCase::isTestEnvironmentReady();

require THINKUP_ROOT_PATH.'tests/config.tests.inc.php';
$this->test_database_name = $TEST_DATABASE;
if(ThinkUpUnitTestCase::ramDiskTestMode()) {
if (ThinkUpUnitTestCase::ramDiskTestMode()) {
putenv("RD_MODE=1");
require THINKUP_WEBAPP_PATH.'config.inc.php';
$this->test_database_name = $THINKUP_CFG['db_name'];
Expand All @@ -63,17 +63,9 @@ public function tearDown() {
}

public function debug($message) {
if($this->DEBUG) {
if ($this->DEBUG) {
$bt = debug_backtrace();
print get_class($this) . ": line " . $bt[0]['line'] . " - " . $message . "\n";
}
}

/**
* Preemptively halt test run if integration testing environment requirement isn't met.
* Prevents unnecessary/inexplicable failures and data loss.
*/
public static function isWebTestEnvironmentReady() {
ThinkUpBasicUnitTestCase::isTestEnvironmentReady();
}
}
2 changes: 1 addition & 1 deletion webapp/_lib/model/class.AppUpgraderDiskUtil.php
Expand Up @@ -263,7 +263,7 @@ private function getInadequateFilePermissionsException() {
return "<b>Oops!</b> ThinkUp can't upgrade itself because it doesn't have the right file permissions. ".
"To fix this problem, run<br><br><code>chown -R $whoami ". THINKUP_WEBAPP_PATH."</code><br><br>".
"on your server, using root (or sudo). If you don't have root access, try the following: ".
"<br><br> <code>chmod -R 777 ".THINKUP_WEBAPP_PATH."</code><br><br><br>".
"<br><br> <code>chmod -R a+rw ".THINKUP_WEBAPP_PATH."</code><br><br><br>".
'<div><a href="#" class="linkbutton emphasized">Okay, done. Try Again&rarr;</a></div><br><br>';
}
}
1 change: 1 addition & 0 deletions webapp/_lib/model/class.SmartyThinkUp.php
Expand Up @@ -107,6 +107,7 @@ public function __construct($config_array=null) {
$this->compile_dir = FileDataManager::getDataPath('compiled_view');
$this->plugins_dir = array('plugins', THINKUP_WEBAPP_PATH.'_lib/view/plugins/');
$this->cache_dir = $this->compile_dir . '/cache';
$this->compile_check = $config_array['debug'];
$this->caching = ($cache_pages)?1:0;
$this->cache_lifetime = $cache_lifetime;
$this->debug = $debug;
Expand Down
2 changes: 1 addition & 1 deletion webapp/config.sample.inc.php
Expand Up @@ -64,7 +64,7 @@
// How many seconds does a query take before it gets logged as a slow query?
$THINKUP_CFG['slow_query_log_threshold'] = 2.0;

$THINKUP_CFG['debug'] = true;
$THINKUP_CFG['debug'] = false;

$THINKUP_CFG['enable_profiler'] = false;

Expand Down

0 comments on commit 0e93f7f

Please sign in to comment.