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() { | |
36 | // This is the path where our testing install resides. | |
37 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
38 | // class attributes. | |
39 | $this->open($this->sboxPath); | |
40 | ||
41 | // Logging in. Remember to wait for page to load. In most cases, | |
42 | // you can rely on 30000 as the value that allows your test to pass, however, | |
43 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
44 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
45 | // page contents loaded and you can continue your test execution. | |
46 | $this->webtestLogin(TRUE); | |
47 | ||
48 | // Profile fields. | |
49 | $fields = array( | |
50 | 'first_name' => array( | |
51 | 'type' => 'Individual', | |
52 | 'label' => 'First Name', | |
53 | 'default_value' => substr(sha1(rand()), 0, 7), | |
54 | 'update_value' => substr(sha1(rand()), 0, 7), | |
55 | 'element_name' => 'first_name', | |
56 | ), | |
57 | 'last_name' => array( | |
58 | 'type' => 'Individual', | |
59 | 'label' => 'Last Name', | |
60 | 'default_value' => substr(sha1(rand()), 0, 7), | |
61 | 'update_value' => substr(sha1(rand()), 0, 7), | |
62 | 'element_name' => 'last_name', | |
63 | ), | |
64 | 'email' => array( | |
65 | 'type' => 'Contact', | |
66 | 'label' => 'Email', | |
67 | 'location' => 0, | |
68 | 'default_value' => substr(sha1(rand()), 0, 5) . '@example.com', | |
69 | 'update_value' => substr(sha1(rand()), 0, 7) . '@example.com', | |
70 | 'element_name' => 'email-Primary', | |
71 | ), | |
72 | 'city' => array( | |
73 | 'type' => 'Contact', | |
74 | 'label' => 'City', | |
75 | 'location' => 0, | |
76 | 'default_value' => substr(sha1(rand()), 0, 7), | |
77 | 'update_value' => substr(sha1(rand()), 0, 7), | |
78 | 'element_name' => 'city-Primary', | |
79 | ), | |
80 | 'state_province' => array( | |
81 | 'type' => 'Contact', | |
82 | 'label' => 'State', | |
83 | 'location' => 0, | |
84 | 'default_value' => '1004', | |
85 | 'update_value' => '1031', | |
86 | 'update_value_label' => 'NY', | |
87 | 'element_name' => 'state_province-Primary', | |
88 | 'html_type' => 'select', | |
89 | ), | |
90 | 'country' => array( | |
91 | 'type' => 'Contact', | |
92 | 'label' => 'Country', | |
93 | 'location' => 0, | |
94 | 'default_value' => '1228', | |
95 | 'update_value' => '1228', | |
96 | 'update_value_label' => 'United States', | |
97 | 'element_name' => 'country-Primary', | |
98 | 'html_type' => 'select', | |
99 | ), | |
100 | ); | |
101 | ||
102 | // Create a contact. | |
103 | $this->webtestAddContact($fields['first_name']['default_value'], $fields['last_name']['default_value'], $fields['email']['default_value']); | |
104 | ||
105 | // Get contact id from url. | |
106 | $matches = array(); | |
107 | preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches); | |
108 | $contactId = $matches[1]; | |
109 | ||
110 | // Create profile for contact | |
111 | $profileName = "Profile_" . substr(sha1(rand()), 0, 7); | |
112 | $profileId = $this->_testCreateContactProfile($fields, $profileName); | |
113 | ||
114 | // Check for profile create/edit permissions. | |
115 | $permission = array('edit-1-profile-edit', 'edit-1-profile-create', 'edit-1-access-all-custom-data'); | |
116 | $this->changePermissions($permission); | |
117 | ||
118 | // Get checksum of the newly created contact. | |
119 | require_once 'CRM/Contact/BAO/Contact/Utils.php'; | |
120 | $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactId); | |
121 | ||
122 | // Logout. | |
123 | $this->open($this->sboxPath . 'civicrm/logout?reset=1'); | |
124 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
125 | ||
126 | // Go to edit profile page of the created contact. | |
127 | $this->open($this->sboxPath . "civicrm/profile/edit?id={$contactId}&gid={$profileId}&reset=1&cs={$cs}"); | |
128 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
129 | $this->assertStringsPresent(array($profileName)); | |
130 | ||
131 | // Check all profile fields, update their values. | |
132 | foreach ($fields as $field) { | |
133 | $this->assertTrue($this->isElementPresent($field['element_name']), "Missing Field: {$field['label']}."); | |
134 | if (isset($field['html_type']) && $field['html_type'] == 'select') { | |
135 | $this->select($field['element_name'], "value={$field['update_value']}"); | |
136 | } | |
137 | else { | |
138 | $this->type($field['element_name'], $field['update_value']); | |
139 | } | |
140 | } | |
141 | // Save profile. | |
142 | $this->click("_qf_Edit_next"); | |
143 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
144 | ||
145 | // Check profile view page. | |
146 | $this->assertStringsPresent(array($profileName)); | |
147 | ||
148 | // Check updated values of all fields. | |
149 | $checkFieldValues = array(); | |
150 | foreach ($fields as $field) { | |
151 | $checkFieldValues[] = isset($field['update_value_label']) ? $field['update_value_label'] : $field['update_value']; | |
152 | } | |
153 | $this->assertStringsPresent($checkFieldValues); | |
154 | } | |
155 | ||
156 | function _testCreateContactProfile($fields, $profileName) { | |
157 | // Go directly to the URL of the screen that you will be | |
158 | // testing (Add new profile ). | |
159 | $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1'); | |
160 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
161 | $this->click('newCiviCRMProfile-top'); | |
162 | $this->waitForElementPresent('_qf_Group_next-top'); | |
163 | ||
164 | // Name of the profile. | |
165 | $this->type('title', $profileName); | |
166 | $this->click('_qf_Group_next-top'); | |
167 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
168 | $elements = $this->parseURL(); | |
169 | $profileId = $elements['queryString']['gid']; | |
170 | ||
171 | // Add field to the profile. | |
172 | foreach ($fields as $key => $values) { | |
173 | $this->open($this->sboxPath . 'civicrm/admin/uf/group/field/add?reset=1&action=add&gid=' . $profileId); | |
174 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
175 | ||
176 | $this->select("field_name[0]", "value={$values['type']}"); | |
177 | sleep(1); | |
178 | $this->select("field_name[1]", "value={$key}"); | |
179 | if (isset($values['location'])) { | |
180 | sleep(1); | |
181 | $this->select("field_name[2]", "value={$values['location']}"); | |
182 | } | |
183 | $this->type("label", $values['label']); | |
184 | $this->click('_qf_Field_next-top'); | |
185 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
186 | } | |
187 | return $profileId; | |
188 | } | |
189 | } | |
190 |