3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_ProfileChecksumTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
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
39 $this->open($this->sboxPath
);
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);
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',
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',
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',
76 'default_value' => substr(sha1(rand()), 0, 7),
77 'update_value' => substr(sha1(rand()), 0, 7),
78 'element_name' => 'city-Primary',
80 'state_province' => array(
84 'default_value' => '1004',
85 'update_value' => '1031',
86 'update_value_label' => 'NY',
87 'element_name' => 'state_province-Primary',
88 'html_type' => 'select',
94 'default_value' => '1228',
95 'update_value' => '1228',
96 'update_value_label' => 'United States',
97 'element_name' => 'country-Primary',
98 'html_type' => 'select',
103 $this->webtestAddContact($fields['first_name']['default_value'], $fields['last_name']['default_value'], $fields['email']['default_value']);
105 // Get contact id from url.
107 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
108 $contactId = $matches[1];
110 // Create profile for contact
111 $profileName = "Profile_" . substr(sha1(rand()), 0, 7);
112 $profileId = $this->_testCreateContactProfile($fields, $profileName);
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);
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);
123 $this->open($this->sboxPath
. 'civicrm/logout?reset=1');
124 $this->waitForPageToLoad($this->getTimeoutMsec());
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));
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']}");
138 $this->type($field['element_name'], $field['update_value']);
142 $this->click("_qf_Edit_next");
143 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
145 // Check profile view page.
146 $this->assertStringsPresent(array($profileName));
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'];
153 $this->assertStringsPresent($checkFieldValues);
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');
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'];
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());
176 $this->select("field_name[0]", "value={$values['type']}");
178 $this->select("field_name[1]", "value={$key}");
179 if (isset($values['location'])) {
181 $this->select("field_name[2]", "value={$values['location']}");
183 $this->type("label", $values['label']);
184 $this->click('_qf_Field_next-top');
185 $this->waitForPageToLoad($this->getTimeoutMsec());