2 require_once('include/SugarFolders/SugarFolders.php');
7 class Bug33404Test extends Sugar_PHPUnit_Framework_TestCase
13 public function setUp()
15 global $current_user, $currentModule;
17 $this->_user = SugarTestUserUtilities::createAnonymousUser();
18 $this->folder = new SugarFolder();
21 public function tearDown()
23 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
24 unset($GLOBALS['current_user']);
26 $GLOBALS['db']->query("DELETE FROM folders_subscriptions WHERE assigned_user_id='{$this->_user->id}'");
31 function testInsertFolderSubscription(){
37 $this->folder->insertFolderSubscription($id1,$this->_user->id);
38 $this->folder->insertFolderSubscription($id2,$this->_user->id);
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);
43 $this->assertEquals(2, $rs['cnt'], "Could not insert folder subscriptions properly" );
48 function testClearSubscriptionsForFolder()
52 $random_user_id1 = create_guid();
53 $random_user_id2 = create_guid();
54 $random_user_id3 = create_guid();
56 $folderID = create_guid();
58 $this->folder->insertFolderSubscription($folderID,$random_user_id1);
59 $this->folder->insertFolderSubscription($folderID,$random_user_id2);
60 $this->folder->insertFolderSubscription($folderID,$random_user_id3);
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");
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);
71 $this->assertEquals(0, $rs['cnt'], "Could not clear folder subscriptions");