3 class SilentUpgradeSessionVarsTest extends Sugar_PHPUnit_Framework_TestCase
5 private $externalTestFileName = 'test_silent_upgrade_vars.php';
7 public function setUp()
9 $this->writeExternalTestFile();
12 public function tearDown()
14 $this->removeExternalTestFile();
17 public function testSilentUpgradeSessionVars()
20 require_once('modules/UpgradeWizard/uw_utils.php');
22 $varsCacheFileName = "{$GLOBALS['sugar_config']['cache_dir']}/silentUpgrader/silentUpgradeCache.php";
24 $loaded = loadSilentUpgradeVars();
25 $this->assertTrue($loaded, "Could not load the silent upgrade vars");
26 global $silent_upgrade_vars_loaded;
27 $this->assertTrue(!empty($silent_upgrade_vars_loaded), "\$silent_upgrade_vars_loaded array should not be empty");
29 $set = setSilentUpgradeVar('SDizzle', 'BSnizzle');
30 $this->assertTrue($set, "Could not set a silent upgrade var");
32 $get = getSilentUpgradeVar('SDizzle');
33 $this->assertEquals('BSnizzle', $get, "Unexpected value when getting silent upgrade var before resetting");
35 $write = writeSilentUpgradeVars();
36 $this->assertTrue($write, "Could not write the silent upgrade vars to the cache file. Function returned false");
37 $this->assertFileExists($varsCacheFileName, "Cache file doesn't exist after call to writeSilentUpgradeVars()");
39 $output = shell_exec("php {$this->externalTestFileName}");
41 $this->assertEquals('BSnizzle', $output, "Running custom script didn't successfully retrieve the value");
43 $remove = removeSilentUpgradeVarsCache();
44 $this->assertTrue(empty($silent_upgrade_vars_loaded), "Silent upgrade vars variable should have been unset in removeSilentUpgradeVarsCache() call");
45 $this->assertFileNotExists($varsCacheFileName, "Cache file exists after call to removeSilentUpgradeVarsCache()");
47 $get = getSilentUpgradeVar('SDizzle');
48 $this->assertNotEquals('BSnizzle', $get, "Unexpected value when getting silent upgrade var after resetting");
51 private function writeExternalTestFile()
53 $externalTestFileContents = <<<EOQ
56 define('sugarEntry', true);
57 require_once('include/entryPoint.php');
58 require_once('modules/UpgradeWizard/uw_utils.php');
60 \$get = getSilentUpgradeVar('SDizzle');
65 file_put_contents($this->externalTestFileName, $externalTestFileContents);
68 private function removeExternalTestFile()
70 if(file_exists($this->externalTestFileName))
72 unlink($this->externalTestFileName);