]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Trackers/Bug40019_Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Trackers / Bug40019_Test.php
1 <?php
2 /**
3  * Bug40019_Test.php
4  * This test verifies the fixes to properly store the items in the BreadCrumbStack class
5  * 
6  */
7
8 require_once 'SugarTestUserUtilities.php';
9 require_once 'SugarTestAccountUtilities.php';
10 require_once 'SugarTestContactUtilities.php';
11 require_once 'modules/Trackers/TrackerManager.php';
12
13 class Bug40019_Test extends Sugar_PHPUnit_Framework_TestCase 
14 {
15     private $anonymous_user;
16     private $saved_current_user;
17         
18     public function setUp()
19     {
20         $this->anonymous_user = SugarTestUserUtilities::createAnonymousUser();
21         if(!empty($GLOBALS['current_user']))
22         {
23                 $this->saved_current_user = $GLOBALS['current_user'];
24         }
25         $GLOBALS['current_user'] = $this->anonymous_user;
26         
27         $i = 0;
28                 while($i++ < 10)
29                 {
30                         $account = SugarTestAccountUtilities::createAccount();
31                         $contact = SugarTestContactUtilities::createContact();
32                         
33                     $trackerManager = TrackerManager::getInstance();
34                     $trackerManager->unPause();
35                 if($monitor = $trackerManager->getMonitor('tracker')) {
36                         $monitor->setEnabled(true);
37                         
38                     $monitor->setValue('date_modified', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
39                     $monitor->setValue('user_id', $GLOBALS['current_user']->id);
40                     $monitor->setValue('module_name', $account->module_dir);
41                     $monitor->setValue('action', 'detailview');
42                     $monitor->setValue('item_id', $account->id);
43                     $monitor->setValue('item_summary', $account->name);
44                     $monitor->setValue('visible',1);
45                     $trackerManager->saveMonitor($monitor, true, true);
46                     
47                     $monitor = $trackerManager->getMonitor('tracker');
48                     $monitor->setValue('date_modified', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
49                     $monitor->setValue('user_id', $GLOBALS['current_user']->id);
50                     $monitor->setValue('module_name', $contact->module_dir);
51                     $monitor->setValue('action', 'detailview');
52                     $monitor->setValue('item_id', $contact->id);
53                     $monitor->setValue('item_summary', $contact->name);
54                     $monitor->setValue('visible',1);
55                     $trackerManager->saveMonitor($monitor, true, true);             
56                 }       
57                 }
58     } 
59
60     public function tearDown()
61     {
62         $GLOBALS['db']->query("DELETE FROM tracker WHERE user_id = '{$this->anonymous_user->id}'");
63         SugarTestAccountUtilities::removeAllCreatedAccounts();
64         SugarTestContactUtilities::removeAllCreatedContacts();
65         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
66         if(!empty($this->saved_current_user))
67         {
68            $GLOBALS['current_user'] = $this->saved_current_user;
69         }
70         
71         
72     }
73     
74     public function testBreadCrumbStack()
75     {
76         $GLOBALS['sugar_config']['history_max_viewed'] = 50;
77         $breadCrumbStack = new BreadCrumbStack($GLOBALS['current_user']->id);
78         $list = $breadCrumbStack->getBreadCrumbList('Accounts');
79         $this->assertEquals(count($list), 10, 'Assert that there are 10 entries for Accounts module');
80
81         $list = $breadCrumbStack->getBreadCrumbList('Contacts');
82         $this->assertEquals(count($list), 10, 'Assert that there are 10 entries for Contacts module');          
83         
84         /*
85         $GLOBALS['sugar_config']['history_max_viewed'] = 10;
86         $breadCrumbStack = new BreadCrumbStack($GLOBALS['current_user']->id);
87         $list = $breadCrumbStack->getBreadCrumbList(array('Accounts', 'Contacts'));
88         $contacts = 0;
89         $accounts = 0;
90         foreach($list as $list_entry)
91         {
92                 switch ($list_entry['module_name'])
93                 {
94                         case 'Contacts': 
95                                  $contacts++;
96                              break;
97                         case 'Accounts': 
98                                  $accounts++;
99                              break;
100                 }
101         }
102         
103         $this->assertEquals($contacts, 5, 'Assert there are 5 entries found for Contacts using array filter of Contacts & Accounts');
104         $this->assertEquals($accounts, 5, 'Assert there are 5 entries found for Accounts using array filter of Contacts & Accounts');
105         */
106     }
107     
108 }
109
110 ?>