3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('modules/Users/UserViewHelper.php');
40 require_once 'include/Sugar_Smarty.php';
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.
48 class Bug49627Test extends Sugar_PHPUnit_Framework_TestCase
55 public function setUp()
58 $current_user = SugarTestUserUtilities::createAnonymousUser();
60 $this->normalUser = SugarTestUserUtilities::createAnonymousUser();
61 $this->normalUser->user_type = 'RegularUser';
62 $this->normalUser->save();
65 $this->groupUser = SugarTestUserUtilities::createAnonymousUser();
66 $this->groupUser->is_group = 1;
67 $this->groupUser->user_type = 'GROUP';
68 $this->groupUser->save();
70 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
71 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
75 public function tearDown()
77 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
78 unset($this->normalUser);
79 unset($this->groupUser);
80 unset($this->portalUser);
83 public function testSetupUserTypeDropdownNormalUser()
85 $smarty = new Sugar_Smarty();
86 $userViewHelper = new UserViewHelperMock($smarty, $this->normalUser);
87 $userViewHelper->usertype = 'RegularUser';
88 $userViewHelper->setupUserTypeDropdown();
89 $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
90 $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
91 $this->assertRegExp('/RegularUser/', $dropdown);
92 $this->assertRegExp('/RegularUser/', $user_type_readonly);
93 $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
94 $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
95 $this->assertNotRegExp('/GROUP/', $dropdown);
96 $this->assertNotRegExp('/GROUP/', $user_type_readonly);
98 $this->normalUser->id = '';
99 $userViewHelper = new UserViewHelperMock($smarty, $this->normalUser);
100 $userViewHelper->usertype = 'RegularUser';
101 $userViewHelper->setupUserTypeDropdown();
102 $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
103 $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
104 $this->assertRegExp('/RegularUser/', $dropdown);
105 $this->assertRegExp('/RegularUser/', $user_type_readonly);
106 $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
107 $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
108 $this->assertNotRegExp('/GROUP/', $dropdown);
109 $this->assertNotRegExp('/GROUP/', $user_type_readonly);
112 public function testSetupUserTypeDropdownGroupUser()
114 $smarty = new Sugar_Smarty();
115 $userViewHelper = new UserViewHelperMock($smarty, $this->groupUser);
116 $userViewHelper->usertype = 'GROUP';
117 $userViewHelper->setupUserTypeDropdown();
118 $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
119 $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
120 $this->assertRegExp('/GROUP/', $dropdown);
121 $this->assertRegExp('/GROUP/', $user_type_readonly);
122 $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
123 $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
124 $this->assertNotRegExp('/RegularUser/', $dropdown);
125 $this->assertNotRegExp('/RegularUser/', $user_type_readonly);
127 $userViewHelper = new UserViewHelperMock($smarty, $this->groupUser);
128 $this->groupUser->id = '';
129 $userViewHelper->usertype = 'GROUP';
130 $userViewHelper->setupUserTypeDropdown();
131 $dropdown = $userViewHelper->ss->get_template_vars('USER_TYPE_DROPDOWN');
132 $user_type_readonly = $userViewHelper->ss->get_template_vars('USER_TYPE_READONLY');
133 $this->assertRegExp('/GROUP/', $dropdown);
134 $this->assertRegExp('/GROUP/', $user_type_readonly);
135 $this->assertNotRegExp('/PORTAL_ONLY/', $dropdown);
136 $this->assertNotRegExp('/PORTAL_ONLY/', $user_type_readonly);
137 $this->assertNotRegExp('/RegularUser/', $dropdown);
138 $this->assertNotRegExp('/RegularUser/', $user_type_readonly);
145 //This class turns the $ss class variable to have public access
146 class UserViewHelperMock extends UserViewHelper