]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/SilentUpgradeSessionVarsTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / SilentUpgradeSessionVarsTest.php
1 <?php
2
3 class SilentUpgradeSessionVarsTest extends Sugar_PHPUnit_Framework_TestCase 
4 {
5     private $externalTestFileName = 'test_silent_upgrade_vars.php';
6     
7     public function setUp() 
8     {
9         $this->writeExternalTestFile();
10     }
11
12     public function tearDown() 
13     {
14         $this->removeExternalTestFile();
15     }
16
17     public function testSilentUpgradeSessionVars()
18     {
19         
20         require_once('modules/UpgradeWizard/uw_utils.php');
21         
22         $varsCacheFileName = "{$GLOBALS['sugar_config']['cache_dir']}/silentUpgrader/silentUpgradeCache.php";
23         
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");
28         
29         $set = setSilentUpgradeVar('SDizzle', 'BSnizzle');
30         $this->assertTrue($set, "Could not set a silent upgrade var");
31         
32         $get = getSilentUpgradeVar('SDizzle');
33         $this->assertEquals('BSnizzle', $get, "Unexpected value when getting silent upgrade var before resetting");
34         
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()");
38         
39         $output = shell_exec("php {$this->externalTestFileName}");
40         
41         $this->assertEquals('BSnizzle', $output, "Running custom script didn't successfully retrieve the value");
42         
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()");
46         
47         $get = getSilentUpgradeVar('SDizzle');
48         $this->assertNotEquals('BSnizzle', $get, "Unexpected value when getting silent upgrade var after resetting");
49     }
50     
51     private function writeExternalTestFile()
52     {
53         $externalTestFileContents = <<<EOQ
54 <?php
55         
56         define('sugarEntry', true);
57         require_once('include/entryPoint.php');
58         require_once('modules/UpgradeWizard/uw_utils.php');
59         
60         \$get = getSilentUpgradeVar('SDizzle');
61         
62         echo \$get;
63 EOQ;
64         
65         file_put_contents($this->externalTestFileName, $externalTestFileContents);
66     }
67     
68     private function removeExternalTestFile()
69     {
70         if(file_exists($this->externalTestFileName))
71         {
72             unlink($this->externalTestFileName);
73         }
74     }
75 }
76 ?>