]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/SugarTestHelper.php
Added unit tests.
[Github/sugarcrm.git] / tests / SugarTestHelper.php
1 <?php
2 if(!defined('sugarEntry')) define('sugarEntry', true);
3
4 set_include_path(
5     dirname(__FILE__) . PATH_SEPARATOR .
6     dirname(__FILE__) . '/..' . PATH_SEPARATOR .
7     get_include_path()
8 );
9
10 // constant to indicate that we are running tests
11 if (!defined('SUGAR_PHPUNIT_RUNNER'))
12     define('SUGAR_PHPUNIT_RUNNER', true);
13
14 // initialize the various globals we use
15 global $sugar_config, $db, $fileName, $current_user, $locale, $current_language;
16
17 if ( !isset($_SERVER['HTTP_USER_AGENT']) )
18     // we are probably running tests from the command line
19     $_SERVER['HTTP_USER_AGENT'] = 'cli';
20
21 // move current working directory
22 chdir(dirname(__FILE__) . '/..');
23
24 require_once('include/entryPoint.php');
25
26 $GLOBALS['db'] = DBManagerFactory::getInstance();
27
28 $current_language = $sugar_config['default_language'];
29 // disable the SugarLogger
30 $sugar_config['logger']['level'] = 'off';
31
32 $GLOBALS['sugar_config']['default_permissions'] = array (
33                 'dir_mode' => 02770,
34                 'file_mode' => 0777,
35                 'chown' => '',
36                 'chgrp' => '',
37         );
38
39 $GLOBALS['js_version_key'] = 'testrunner';
40
41 if ( !isset($_SERVER['SERVER_SOFTWARE']) )
42     $_SERVER["SERVER_SOFTWARE"] = 'PHPUnit';
43
44 // helps silence the license checking when running unit tests.
45 $_SESSION['VALIDATION_EXPIRES_IN'] = 'valid';
46
47 $GLOBALS['startTime'] = microtime(true);
48
49 // clean out the cache directory
50 require_once('modules/Administration/QuickRepairAndRebuild.php');
51 $repair = new RepairAndClear();
52 $repair->module_list = array();
53 $repair->show_output = false;
54 $repair->clearJsLangFiles();                    
55 $repair->clearJsFiles();
56
57 // mark that we got by the admin wizard already
58 $focus = new Administration();
59 $focus->retrieveSettings();
60 $focus->saveSetting('system','adminwizard',1);
61
62 // include the other test tools
63 require_once 'SugarTestUserUtilities.php';
64 require_once 'SugarTestLangPackCreator.php';
65 require_once 'SugarTestThemeUtilities.php';
66 require_once 'SugarTestContactUtilities.php';
67 require_once 'SugarTestEmailUtilities.php';
68 require_once 'SugarTestCampaignUtilities.php';
69 require_once 'SugarTestLeadUtilities.php';
70 require_once 'SugarTestStudioUtilities.php';
71 require_once 'SugarTestMeetingUtilities.php';
72 require_once 'SugarTestAccountUtilities.php';
73 require_once 'SugarTestTrackerUtility.php';
74 require_once 'SugarTestImportUtilities.php';
75 require_once 'SugarTestMergeUtilities.php';
76
77 // define our testcase subclass
78 class Sugar_PHPUnit_Framework_TestCase extends PHPUnit_Framework_TestCase
79 {
80     protected $backupGlobals = FALSE;
81 }
82
83 // define a mock logger interface; used for capturing logging messages emited
84 // the test suite
85 class SugarMockLogger
86 {
87         private $_messages = array();
88         
89         public function __call($method, $message)
90         {
91                 $this->messages[] = strtoupper($method) . ': ' . $message[0];
92         }
93         
94         public function getLastMessage()
95         {
96                 return end($this->messages);
97         }
98         
99         public function getMessageCount()
100         {
101                 return count($this->messages);
102         }
103 }