]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarFolders/Bug33404Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / include / SugarFolders / Bug33404Test.php
1 <?php 
2 require_once('include/SugarFolders/SugarFolders.php');
3
4 /**
5  * @group bug33404
6  */
7 class Bug33404Test extends Sugar_PHPUnit_Framework_TestCase
8 {
9         var $folder = null;
10     var $_user = null;
11     
12     
13         public function setUp()
14     {
15         global $current_user, $currentModule;
16
17         $this->_user = SugarTestUserUtilities::createAnonymousUser();
18                 $this->folder = new SugarFolder(); 
19         }
20
21     public function tearDown()
22     {
23         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
24         unset($GLOBALS['current_user']);
25         
26         $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
27         
28         unset($this->folder);
29     }
30     
31         function testInsertFolderSubscription(){
32             global $current_user;
33            
34             $id1 = create_guid();
35             $id2 = create_guid();
36             
37             $this->folder->insertFolderSubscription($id1,$this->_user->id);
38             $this->folder->insertFolderSubscription($id2,$this->_user->id);
39             
40             $result = $GLOBALS['db']->query("SELECT count(*) as cnt FROM folders_subscriptions where assigned_user_id='{$this->_user->id}'");
41                 $rs = $GLOBALS['db']->fetchByAssoc($result);
42                 
43                 $this->assertEquals(2, $rs['cnt'], "Could not insert folder subscriptions properly" );
44     }
45     
46     
47     
48     function testClearSubscriptionsForFolder()
49     {
50         global $current_user;
51            
52         $random_user_id1 = create_guid();
53         $random_user_id2 = create_guid();
54         $random_user_id3 = create_guid();
55         
56             $folderID = create_guid();
57             
58             $this->folder->insertFolderSubscription($folderID,$random_user_id1);
59         $this->folder->insertFolderSubscription($folderID,$random_user_id2);
60         $this->folder->insertFolderSubscription($folderID,$random_user_id3);
61             
62         $result1 = $GLOBALS['db']->query("SELECT count(*) as cnt FROM folders_subscriptions where folder_id='{$folderID}' ");
63                 $rs1 = $GLOBALS['db']->fetchByAssoc($result1);
64         $this->assertEquals(3, $rs1['cnt'], "Could not clear folder subscriptions, test setup failed while inserting folder subscriptionss");
65         
66         //Test deletion of subscriptions.
67         $this->folder->clearSubscriptionsForFolder($folderID);
68             $result = $GLOBALS['db']->query("SELECT count(*) as cnt FROM folders_subscriptions where folder_id='{$folderID}' ");
69                 $rs = $GLOBALS['db']->fetchByAssoc($result);
70          
71                 $this->assertEquals(0, $rs['cnt'], "Could not clear folder subscriptions");
72     }
73 }
74 ?>