]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/javascript/JSAlertsTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / include / javascript / JSAlertsTest.php
1 <?php
2 require_once 'include/javascript/jsAlerts.php';
3
4 class JSAlertsTest extends Sugar_PHPUnit_Framework_TestCase
5 {
6     var $beans;
7
8     public function setUp()
9     {
10         global $current_user;
11         $this->beans = array();
12         $this->old_user = $current_user;
13         $current_user = $this->_user = SugarTestUserUtilities::createAnonymousUser();
14         $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
15         $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
16     }
17     
18     public function tearDown()
19     {
20         foreach($this->beans as $bean) {
21             $bean->mark_deleted($bean->id);
22         }
23         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
24         unset($GLOBALS['app_list_strings']);
25         unset($GLOBALS['current_user']);
26         unset($GLOBALS['app_strings']);
27     }
28
29     protected function createNewMeeting()
30     {
31         $m = new Meeting();
32         $m->name = "40541TestMeeting";
33         $m->date_start = gmdate($GLOBALS['timedate']->get_db_date_time_format(), time() + 3000);
34         $m->duration_hours = 0;
35         $m->duration_minutes = 15;
36         $m->reminder_time = 60;
37         $m->reminder_checked = true;
38         $m->save();
39         $m->load_relationship("users");
40         $m->users->add($this->_user->id);
41         $this->beans[] = $m;
42         return $m;
43     }
44
45     public function testGetAlertsForUser()
46     {
47
48         global $app_list_strings;
49             $app_list_strings['reminder_max_time'] = 5000;
50         $m = $this->createNewMeeting();
51         $alerts = new jsAlerts();
52         $script = $alerts->getScript();
53         $this->assertRegExp("/addAlert.*\"{$m->name}\"/", $script);
54     }
55
56     public function testGetDeclinedAlertsForUser()
57     {
58
59         global $app_list_strings;
60             $app_list_strings['reminder_max_time'] = 5000;
61         $m = $this->createNewMeeting();
62         //Decline the meeting
63         $query = "UPDATE meetings_users SET deleted = 0, accept_status = 'decline' " .
64                          "WHERE meeting_id = '$m->id' AND user_id = '{$this->_user->id}'";
65         $m->db->query($query);
66         $alerts = new jsAlerts();
67         $script = $alerts->getScript();
68         $this->assertNotRegExp("/addAlert.*\"{$m->name}\"/", $script);
69     }
70 }