]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Users/Bug49627Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / Users / Bug49627Test.php
1 <?php
2
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 require_once('modules/Users/UserViewHelper.php');
40 require_once 'include/Sugar_Smarty.php';
41
42 /**
43  * Bug49627Test.php
44  *
45  * This unit test tests the user type dropdown items created from the UserViewHelper class.
46  * It runs tests against the normal user, portal and group user types.
47  */
48 class Bug49627Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50
51 var $normalUser;
52 var $groupUser;
53
54
55 public function setUp()
56 {
57     global $current_user;
58     $current_user = SugarTestUserUtilities::createAnonymousUser();
59
60     $this->normalUser = SugarTestUserUtilities::createAnonymousUser(false);
61     $this->normalUser->id = create_guid();
62     $this->normalUser->user_type = 'RegularUser';
63
64
65     $this->groupUser = SugarTestUserUtilities::createAnonymousUser(false);
66     $this->groupUser->id = create_guid();
67     $this->groupUser->is_group = 1;
68     $this->groupUser->user_type = 'GROUP';
69
70     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
71     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
72 }
73
74 public function tearDown()
75 {
76     SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
77 }
78
79 public function testSetupUserTypeDropdownNormalUser()
80 {
81     $smarty = new Sugar_Smarty();
82     $userViewHelper = new UserViewHelperMock($smarty, $this->normalUser);
83     $userViewHelper->usertype = 'RegularUser';
84     $userViewHelper->setupUserTypeDropdown();
85     $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
86     $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
87     $this->assertRegExp('/RegularUser/', $dropdown);
88     $this->assertRegExp('/RegularUser/', $user_type_readonly);
89     $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
90     $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
91     $this->assertNotRegExp('/GROUP/', $dropdown);
92     $this->assertNotRegExp('/GROUP/', $user_type_readonly);
93
94     $this->normalUser->id = '';
95     $userViewHelper = new UserViewHelperMock($smarty, $this->normalUser);
96     $userViewHelper->usertype = 'RegularUser';
97     $userViewHelper->setupUserTypeDropdown();
98     $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
99     $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
100     $this->assertRegExp('/RegularUser/', $dropdown);
101     $this->assertRegExp('/RegularUser/', $user_type_readonly);
102     $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
103     $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
104     $this->assertNotRegExp('/GROUP/', $dropdown);
105     $this->assertNotRegExp('/GROUP/', $user_type_readonly);
106 }
107
108 public function testSetupUserTypeDropdownGroupUser()
109 {
110     $smarty = new Sugar_Smarty();
111     $userViewHelper = new UserViewHelperMock($smarty, $this->groupUser);
112     $userViewHelper->usertype = 'GROUP';
113     $userViewHelper->setupUserTypeDropdown();
114     $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
115     $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
116     $this->assertRegExp('/GROUP/', $dropdown);
117     $this->assertRegExp('/GROUP/', $user_type_readonly);
118     $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
119     $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
120     $this->assertNotRegExp('/RegularUser/', $dropdown);
121     $this->assertNotRegExp('/RegularUser/', $user_type_readonly);
122
123     $userViewHelper = new UserViewHelperMock($smarty, $this->groupUser);
124     $this->groupUser->id = '';
125     $userViewHelper->usertype = 'GROUP';
126     $userViewHelper->setupUserTypeDropdown();
127     $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
128     $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
129     $this->assertRegExp('/GROUP/', $dropdown);
130     $this->assertRegExp('/GROUP/', $user_type_readonly);
131     $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
132     $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
133     $this->assertNotRegExp('/RegularUser/', $dropdown);
134     $this->assertNotRegExp('/RegularUser/', $user_type_readonly);
135 }
136
137
138 }
139
140 //UserViewHelperMock
141 //This class turns the $ss class variable to have public access
142 class UserViewHelperMock extends UserViewHelper
143 {
144     var $ss;
145 }