3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_ProfileChecksumTest
32 class WebTest_Contact_ProfileChecksumTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testProfileChecksum() {
39 $this->webtestLogin('admin');
43 'first_name' => array(
44 'type' => 'Individual',
45 'label' => 'First Name',
46 'default_value' => substr(sha1(rand()), 0, 7),
47 'update_value' => substr(sha1(rand()), 0, 7),
48 'element_name' => 'first_name',
51 'type' => 'Individual',
52 'label' => 'Last Name',
53 'default_value' => substr(sha1(rand()), 0, 7),
54 'update_value' => substr(sha1(rand()), 0, 7),
55 'element_name' => 'last_name',
61 'default_value' => substr(sha1(rand()), 0, 5) . '@example.com',
62 'update_value' => substr(sha1(rand()), 0, 7) . '@example.com',
63 'element_name' => 'email-Primary',
69 'default_value' => substr(sha1(rand()), 0, 7),
70 'update_value' => substr(sha1(rand()), 0, 7),
71 'element_name' => 'city-Primary',
77 'default_value' => '1228',
78 'update_value' => '1228',
79 'update_value_label' => 'UNITED STATES',
80 'element_name' => 'country-Primary',
81 'html_type' => 'select',
83 'state_province' => array(
87 'default_value' => '1004',
88 'update_value' => '1031',
89 'update_value_label' => 'NY',
90 'element_name' => 'state_province-Primary',
91 'html_type' => 'select',
96 $this->webtestAddContact($fields['first_name']['default_value'], $fields['last_name']['default_value'], $fields['email']['default_value']);
98 // Get contact id from url.
99 $contactId = $this->urlArg('cid');
101 // Create profile for contact
102 $profileName = "Profile_" . substr(sha1(rand()), 0, 7);
103 $profileId = $this->_testCreateContactProfile($fields, $profileName);
105 // Check for profile create/edit permissions.
107 'edit-1-profile-edit',
108 'edit-1-profile-create',
109 'edit-1-access-all-custom-data',
110 'edit-1-edit-all-contacts',
112 $this->changePermissions($permission);
114 // Get checksum of the newly created contact.
115 $cs = CRM_Contact_BAO_Contact_Utils
::generateChecksum($contactId);
118 $this->webtestLogout();
120 // Go to edit profile page of the created contact.
121 $this->openCiviPage("profile/edit", "id={$contactId}&gid={$profileId}&reset=1&cs={$cs}", NULL);
122 $this->waitForTextPresent($profileName);
124 // Check all profile fields, update their values.
125 foreach ($fields as $field) {
126 $this->assertTrue($this->isElementPresent($field['element_name']), "Missing Field: {$field['label']}.");
127 if (isset($field['html_type']) && $field['html_type'] == 'select') {
128 $this->waitForElementPresent($field['element_name']);
129 $this->select($field['element_name'], "value={$field['update_value']}");
132 $this->type($field['element_name'], $field['update_value']);
136 $this->click("_qf_Edit_next");
137 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
139 // Check profile view page.
140 $this->waitForTextPresent($profileName);
142 // Check updated values of all fields.
143 $checkFieldValues = array();
144 foreach ($fields as $field) {
145 $checkFieldValues[] = isset($field['update_value_label']) ?
$field['update_value_label'] : $field['update_value'];
147 $this->assertStringsPresent($checkFieldValues);
152 * @param string $profileName
156 public function _testCreateContactProfile($fields, $profileName) {
158 $this->openCiviPage("admin/uf/group", "reset=1");
159 $this->click('newCiviCRMProfile-top');
160 $this->waitForElementPresent('_qf_Group_next-top');
162 // Name of the profile.
163 $this->type('title', $profileName);
164 $this->click('uf_group_type_Profile');
165 $this->click('_qf_Group_next-top');
166 $this->waitForPageToLoad($this->getTimeoutMsec());
167 $profileId = $this->urlArg('gid');
169 // Add field to the profile.
170 foreach ($fields as $key => $values) {
171 $this->openCiviPage("admin/uf/group/field/add", "reset=1&action=add&gid=$profileId");
173 $this->select("field_name[0]", "value={$values['type']}");
174 // Because it tends to cause problems, all uses of sleep() must be justified in comments
175 // Sleep should never be used for wait for anything to load from the server
176 // Justification for this instance: FIXME
178 $this->select("field_name[1]", "value={$key}");
179 if (isset($values['location'])) {
180 // Because it tends to cause problems, all uses of sleep() must be justified in comments
181 // Sleep should never be used for wait for anything to load from the server
182 // Justification for this instance: FIXME
184 $this->select("field_name[2]", "value={$values['location']}");
186 $this->type("label", $values['label']);
187 $this->click('_qf_Field_next-top');
188 $this->waitForPageToLoad($this->getTimeoutMsec());