]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/tests/SugarTestUserUtilitiesTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / tests / SugarTestUserUtilitiesTest.php
1 <?php
2 require_once 'SugarTestUserUtilities.php';
3
4 class SugarTestUserUtilitiesTest extends Sugar_PHPUnit_Framework_TestCase
5 {
6     private $_before_snapshot = array();
7     
8     public function setUp() 
9     {
10         $this->_before_snapshot = $this->_takeUserDBSnapshot();
11     }
12
13     public function tearDown() 
14     {
15         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
16     }
17
18     public function _takeUserDBSnapshot() 
19     {
20         $snapshot = array();
21         $query = 'SELECT * FROM users';
22         $result = $GLOBALS['db']->query($query);
23         while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
24             $snapshot[] = $row;
25         }
26         return $snapshot;
27     }
28     
29
30     public function testCanCreateAnAnonymousUser() 
31     {
32         $user = SugarTestUserUtilities::createAnonymousUser();
33
34         $this->assertType('User', $user);
35
36         $after_snapshot = $this->_takeUserDBSnapshot();
37         $this->assertNotEquals($this->_before_snapshot, $after_snapshot, 
38             "Simply insure that something was added");
39     }
40
41     public function testAnonymousUserHasARandomUserName() 
42     {
43         $first_user = SugarTestUserUtilities::createAnonymousUser();
44         $this->assertTrue(!empty($first_user->user_name), 'team name should not be empty');
45
46         $second_user = SugarTestUserUtilities::createAnonymousUser();
47         $this->assertNotEquals($first_user->user_name, $second_user->user_name,
48             'each user should have a unique name property');
49     }
50
51     public function testCanTearDownAllCreatedAnonymousUsers() 
52     {
53         for ($i = 0; $i < 5; $i++) {
54             SugarTestUserUtilities::createAnonymousUser();
55         }
56         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
57         
58         $this->assertEquals($this->_before_snapshot, $this->_takeUserDBSnapshot(),
59             'SugarTest_UserUtilities::removeAllCreatedAnonymousUsers() should have removed the users it added');
60     }
61 }
62