Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Contact_ProfileChecksumTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testProfileChecksum() { | |
42daf119 | 36 | $this->webtestLogin('admin'); |
6a488035 TO |
37 | |
38 | // Profile fields. | |
39 | $fields = array( | |
40 | 'first_name' => array( | |
41 | 'type' => 'Individual', | |
42 | 'label' => 'First Name', | |
43 | 'default_value' => substr(sha1(rand()), 0, 7), | |
44 | 'update_value' => substr(sha1(rand()), 0, 7), | |
45 | 'element_name' => 'first_name', | |
46 | ), | |
47 | 'last_name' => array( | |
48 | 'type' => 'Individual', | |
49 | 'label' => 'Last Name', | |
50 | 'default_value' => substr(sha1(rand()), 0, 7), | |
51 | 'update_value' => substr(sha1(rand()), 0, 7), | |
52 | 'element_name' => 'last_name', | |
53 | ), | |
54 | 'email' => array( | |
55 | 'type' => 'Contact', | |
56 | 'label' => 'Email', | |
57 | 'location' => 0, | |
58 | 'default_value' => substr(sha1(rand()), 0, 5) . '@example.com', | |
59 | 'update_value' => substr(sha1(rand()), 0, 7) . '@example.com', | |
60 | 'element_name' => 'email-Primary', | |
61 | ), | |
62 | 'city' => array( | |
63 | 'type' => 'Contact', | |
64 | 'label' => 'City', | |
65 | 'location' => 0, | |
66 | 'default_value' => substr(sha1(rand()), 0, 7), | |
67 | 'update_value' => substr(sha1(rand()), 0, 7), | |
68 | 'element_name' => 'city-Primary', | |
69 | ), | |
70 | 'state_province' => array( | |
71 | 'type' => 'Contact', | |
72 | 'label' => 'State', | |
73 | 'location' => 0, | |
74 | 'default_value' => '1004', | |
75 | 'update_value' => '1031', | |
76 | 'update_value_label' => 'NY', | |
77 | 'element_name' => 'state_province-Primary', | |
78 | 'html_type' => 'select', | |
79 | ), | |
80 | 'country' => array( | |
81 | 'type' => 'Contact', | |
82 | 'label' => 'Country', | |
83 | 'location' => 0, | |
84 | 'default_value' => '1228', | |
85 | 'update_value' => '1228', | |
86 | 'update_value_label' => 'United States', | |
87 | 'element_name' => 'country-Primary', | |
88 | 'html_type' => 'select', | |
89 | ), | |
90 | ); | |
91 | ||
92 | // Create a contact. | |
93 | $this->webtestAddContact($fields['first_name']['default_value'], $fields['last_name']['default_value'], $fields['email']['default_value']); | |
94 | ||
95 | // Get contact id from url. | |
96 | $matches = array(); | |
97 | preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches); | |
98 | $contactId = $matches[1]; | |
99 | ||
100 | // Create profile for contact | |
101 | $profileName = "Profile_" . substr(sha1(rand()), 0, 7); | |
102 | $profileId = $this->_testCreateContactProfile($fields, $profileName); | |
103 | ||
104 | // Check for profile create/edit permissions. | |
105 | $permission = array('edit-1-profile-edit', 'edit-1-profile-create', 'edit-1-access-all-custom-data'); | |
106 | $this->changePermissions($permission); | |
107 | ||
108 | // Get checksum of the newly created contact. | |
6a488035 TO |
109 | $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactId); |
110 | ||
42daf119 CW |
111 | // logout. |
112 | $this->webtestLogout(); | |
6a488035 TO |
113 | |
114 | // Go to edit profile page of the created contact. | |
071a6d2e | 115 | $this->openCiviPage("profile/edit", "id={$contactId}&gid={$profileId}&reset=1&cs={$cs}"); |
6a488035 TO |
116 | $this->assertStringsPresent(array($profileName)); |
117 | ||
118 | // Check all profile fields, update their values. | |
119 | foreach ($fields as $field) { | |
120 | $this->assertTrue($this->isElementPresent($field['element_name']), "Missing Field: {$field['label']}."); | |
121 | if (isset($field['html_type']) && $field['html_type'] == 'select') { | |
122 | $this->select($field['element_name'], "value={$field['update_value']}"); | |
123 | } | |
124 | else { | |
125 | $this->type($field['element_name'], $field['update_value']); | |
126 | } | |
127 | } | |
128 | // Save profile. | |
129 | $this->click("_qf_Edit_next"); | |
130 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
131 | ||
132 | // Check profile view page. | |
133 | $this->assertStringsPresent(array($profileName)); | |
134 | ||
135 | // Check updated values of all fields. | |
136 | $checkFieldValues = array(); | |
137 | foreach ($fields as $field) { | |
138 | $checkFieldValues[] = isset($field['update_value_label']) ? $field['update_value_label'] : $field['update_value']; | |
139 | } | |
140 | $this->assertStringsPresent($checkFieldValues); | |
141 | } | |
142 | ||
143 | function _testCreateContactProfile($fields, $profileName) { | |
42daf119 | 144 | // Add new profile. |
071a6d2e | 145 | $this->openCiviPage("admin/uf/group", "reset=1"); |
6a488035 TO |
146 | $this->click('newCiviCRMProfile-top'); |
147 | $this->waitForElementPresent('_qf_Group_next-top'); | |
148 | ||
149 | // Name of the profile. | |
150 | $this->type('title', $profileName); | |
151 | $this->click('_qf_Group_next-top'); | |
152 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
153 | $elements = $this->parseURL(); | |
154 | $profileId = $elements['queryString']['gid']; | |
155 | ||
156 | // Add field to the profile. | |
157 | foreach ($fields as $key => $values) { | |
071a6d2e | 158 | $this->openCiviPage("admin/uf/group/field/add", "reset=1&action=add&gid=$profileId"); |
6a488035 TO |
159 | |
160 | $this->select("field_name[0]", "value={$values['type']}"); | |
efb29358 CW |
161 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
162 | // Sleep should never be used for wait for anything to load from the server | |
163 | // Justification for this instance: FIXME | |
6a488035 TO |
164 | sleep(1); |
165 | $this->select("field_name[1]", "value={$key}"); | |
166 | if (isset($values['location'])) { | |
efb29358 CW |
167 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
168 | // Sleep should never be used for wait for anything to load from the server | |
169 | // Justification for this instance: FIXME | |
6a488035 TO |
170 | sleep(1); |
171 | $this->select("field_name[2]", "value={$values['location']}"); | |
172 | } | |
173 | $this->type("label", $values['label']); | |
174 | $this->click('_qf_Field_next-top'); | |
175 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
176 | } | |
177 | return $profileId; | |
178 | } | |
179 | } | |
180 |