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_MultipleContactSubTypes extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testIndividualAdd() { | |
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(); | |
47 | ||
48 | $selection1 = 'Student'; | |
49 | $selection2 = 'Parent'; | |
50 | $selection3 = 'Staff'; | |
51 | ||
52 | //Create custom group for contact sub-types | |
53 | list($groupTitleForStudent, $customGroupIdForStudent) = $this->_addCustomData($selection1); | |
54 | list($groupTitleForParent, $customGroupIdForParent) = $this->_addCustomData($selection2); | |
55 | list($groupTitleForStaff, $customGroupIdForStaff) = $this->_addCustomData($selection3); | |
56 | ||
57 | // Go directly to the URL of the screen that you will be testing (New Individual). | |
58 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); | |
59 | ||
60 | //contact details section | |
61 | //select prefix | |
62 | $this->click("prefix_id"); | |
63 | $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix')); | |
64 | ||
65 | $this->addSelection('contact_sub_type', "value={$selection1}"); | |
66 | $this->addSelection('contact_sub_type', "value={$selection2}"); | |
67 | ||
68 | //fill in first name | |
69 | $this->type("first_name", substr(sha1(rand()), 0, 7) . "John"); | |
70 | ||
71 | //fill in middle name | |
72 | $this->type("middle_name", "Bruce"); | |
73 | ||
74 | //fill in last name | |
75 | $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith"); | |
76 | ||
77 | //select suffix | |
78 | $this->select("suffix_id", "value=3"); | |
79 | ||
80 | //fill in nick name | |
81 | $this->type("nick_name", "jsmith"); | |
82 | ||
83 | //fill in email | |
84 | $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com"); | |
85 | ||
86 | //fill in phone | |
87 | $this->type("phone_1_phone", "2222-4444"); | |
88 | ||
89 | //fill in IM | |
90 | $this->type("im_1_name", "testYahoo"); | |
91 | ||
92 | //fill in openID | |
93 | $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com"); | |
94 | ||
95 | //fill in website | |
96 | $this->type("website_1_url", "http://www.john.com"); | |
97 | ||
98 | //fill in source | |
99 | $this->type("contact_source", "johnSource"); | |
100 | ||
101 | //fill in external identifier | |
102 | $indExternalId = substr(sha1(rand()), 0, 4); | |
103 | $this->type("external_identifier", $indExternalId); | |
104 | ||
105 | //checking for presence of contact data specific custom data | |
106 | if ($this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForStudent}']") && $this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForParent}']") && !$this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForStaff}']")) { | |
107 | $assertCheckForCustomGroup = TRUE; | |
108 | } | |
109 | else { | |
110 | $assertCheckForCustomGroup = FALSE; | |
111 | } | |
112 | ||
113 | $this->assertTrue($assertCheckForCustomGroup, "The Check for contact sub-type specific custom group failed"); | |
114 | ||
115 | if ($assertCheckForCustomGroup) { | |
116 | ||
117 | $this->type("xpath=//div[@id='customData{$customGroupIdForStudent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForStudent}"); | |
118 | $this->type("xpath=//div[@id='customData{$customGroupIdForParent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForParent}"); | |
119 | } | |
120 | ||
121 | //address section | |
122 | $this->click("addressBlock"); | |
123 | $this->waitForElementPresent("address_1_street_address"); | |
124 | //fill in address 1 | |
125 | $this->type("address_1_street_address", "902C El Camino Way SW"); | |
126 | $this->type("address_1_city", "Dumfries"); | |
127 | $this->type("address_1_postal_code", "1234"); | |
128 | ||
129 | $this->click("address_1_country_id"); | |
130 | $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID()); | |
131 | ||
132 | if ($this->isTextPresent("Latitude")) { | |
133 | $this->type("address_1_geo_code_1", "1234"); | |
134 | $this->type("address_1_geo_code_2", "5678"); | |
135 | } | |
136 | ||
137 | //fill in address 2 | |
138 | $this->click("//div[@id='addMoreAddress1']/a/span"); | |
139 | $this->waitForElementPresent("address_2_street_address"); | |
140 | $this->type("address_2_street_address", "2782Y Dowlen Path W"); | |
141 | $this->type("address_2_city", "Birmingham"); | |
142 | $this->type("address_2_postal_code", "3456"); | |
143 | ||
144 | $this->click("address_2_country_id"); | |
145 | $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID()); | |
146 | ||
147 | if ($this->isTextPresent("Latitude")) { | |
148 | $this->type("address_2_geo_code_1", "1234"); | |
149 | $this->type("address_2_geo_code_2", "5678"); | |
150 | } | |
151 | ||
152 | //Communication Preferences section | |
153 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Communication Preferences')]"); | |
154 | ||
155 | //select greeting/addressee options | |
156 | $this->waitForElementPresent("email_greeting_id"); | |
157 | $this->select("email_greeting_id", "value=2"); | |
158 | $this->select("postal_greeting_id", "value=3"); | |
159 | ||
160 | //Select preferred method for Privacy | |
161 | $this->click("privacy[do_not_trade]"); | |
162 | $this->click("privacy[do_not_sms]"); | |
163 | ||
164 | //Select preferred method(s) of communication | |
165 | $this->click("preferred_communication_method[1]"); | |
166 | $this->click("preferred_communication_method[2]"); | |
167 | ||
168 | //select preferred language | |
169 | $this->waitForElementPresent("preferred_language"); | |
170 | $this->select("preferred_language", "value=en_US"); | |
171 | ||
172 | //Demographics section | |
173 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]"); | |
174 | $this->waitForElementPresent("birth_date"); | |
175 | ||
176 | $this->webtestFillDate('birth_date', "-1 year"); | |
177 | ||
178 | //Tags and Groups section | |
179 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Tags and Groups')]"); | |
180 | ||
181 | $this->click("group[{$this->webtestGetValidEntityID('Group')}]"); | |
182 | $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]"); | |
183 | ||
184 | // Clicking save. | |
185 | $this->click("_qf_Contact_upload_view"); | |
186 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
187 | ||
188 | //checking the contact sub-type of newly created individual | |
189 | $this->assertElementContainsText('crm-notification-container', "Contact Saved"); | |
190 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='contact-summary']/div[@id='contactTopBar']/table/tbody/tr/td[@class='crm-contact_type_label'][text()='{$selection1}, {$selection2}']")); | |
191 | ||
192 | //custom data check | |
193 | if ($this->isElementPresent("{$groupTitleForStudent}_0")) { | |
194 | $groupidSt = "{$groupTitleForStudent}_0"; | |
195 | } | |
196 | else { | |
197 | $groupidSt = "{$groupTitleForStudent}_1"; | |
198 | } | |
199 | ||
200 | //custom data check | |
201 | if ($this->isElementPresent("{$groupTitleForParent}_0")) { | |
202 | $groupidPa = "{$groupTitleForParent}_0"; | |
203 | } | |
204 | else { | |
205 | $groupidPa = "{$groupTitleForParent}_1"; | |
206 | } | |
207 | ||
208 | $this->click($groupidSt); | |
209 | $this->click($groupidPa); | |
210 | ||
211 | $this->assertTrue($this->isTextPresent("dummy text for customData{$customGroupIdForParent}")); | |
212 | $this->assertTrue($this->isTextPresent("dummy text for customData{$customGroupIdForStudent}")); | |
213 | ||
214 | //editing contact sub-type | |
215 | $this->click("xpath=//ul[@id='actions']/li[2]/a"); | |
216 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
217 | ||
218 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); | |
219 | $selectedValues = $this->getSelectedValues("contact_sub_type"); | |
220 | if (in_array($selection1, $selectedValues) && in_array($selection2, $selectedValues)) { | |
221 | $checkSelection = TRUE; | |
222 | } | |
223 | else { | |
224 | $checkSelection = FALSE; | |
225 | } | |
226 | ||
227 | $this->assertTrue($checkSelection, 'Assertion failed for multiple selection of contact sub-type'); | |
228 | ||
229 | //edit contact sub-type | |
230 | $this->removeSelection("contact_sub_type", "value={$selection1}"); | |
231 | $this->addSelection('contact_sub_type', "value={$selection3}"); | |
232 | ||
233 | //checking for presence of contact data specific custom data | |
234 | if (!$this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForStudent}']") && $this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForParent}']") && $this->isElementPresent("xpath=//div[@id='customData{$customGroupIdForStaff}']")) { | |
235 | $assertCheckForCustomGroup = TRUE; | |
236 | } | |
237 | else { | |
238 | $assertCheckForCustomGroup = FALSE; | |
239 | } | |
240 | ||
241 | $this->assertTrue($assertCheckForCustomGroup, "The Check for contact sub-type specific custom group failed after de-selecting Student and selecting staff"); | |
242 | ||
243 | if ($assertCheckForCustomGroup) { | |
244 | ||
245 | $this->type("xpath=//div[@id='customData{$customGroupIdForParent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForParent}"); | |
246 | $this->type("xpath=//div[@id='customData{$customGroupIdForStaff}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForStaff}"); | |
247 | } | |
248 | ||
249 | $this->click("_qf_Contact_upload_view-bottom"); | |
250 | sleep(5); | |
251 | ||
252 | // Check confirmation alert. | |
253 | $this->assertTrue((bool)preg_match("/One or more contact subtypes have been de-selected from the list for this contact. Any custom data associated with de-selected subtype will be removed. Click OK to proceed, or Cancel to review your changes before saving./", $this->getConfirmation())); | |
254 | $this->chooseOkOnNextConfirmation(); | |
255 | sleep(10); | |
256 | ||
257 | $this->waitForElementPresent("xpath=//div[@id='contact-summary']/div[@id='contactTopBar']"); | |
258 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='contact-summary']/div[@id='contactTopBar']/table/tbody/tr/td[@class='crm-contact_type_label'][text()='{$selection2}, {$selection3}']")); | |
259 | ||
260 | //custom data check | |
261 | if ($this->isElementPresent("{$groupTitleForParent}_0")) { | |
262 | $groupidPa = "{$groupTitleForParent}_0"; | |
263 | } | |
264 | else { | |
265 | $groupidPa = "{$groupTitleForParent}_1"; | |
266 | } | |
267 | ||
268 | //custom data check | |
269 | if ($this->isElementPresent("{$groupTitleForStaff}_0")) { | |
270 | $groupidSta = "{$groupTitleForStaff}_0"; | |
271 | } | |
272 | else { | |
273 | $groupidSta = "{$groupTitleForStaff}_1"; | |
274 | } | |
275 | ||
276 | $this->click($groupidSta); | |
277 | $this->click($groupidPa); | |
278 | ||
279 | $this->assertTrue($this->isTextPresent("dummy text for customData{$customGroupIdForParent}")); | |
280 | $this->assertTrue($this->isTextPresent("dummy text for customData{$customGroupIdForStaff}")); | |
281 | } | |
282 | ||
283 | function _addCustomData($contactSubType) { | |
284 | // Go directly to the URL of the screen that you will be testing (New Custom Group). | |
285 | $this->open($this->sboxPath . "civicrm/admin/custom/group?reset=1"); | |
286 | ||
287 | //add new custom data | |
288 | $customGroupTitle = "Custom group For {$contactSubType}" . substr(sha1(rand()), 0, 4); | |
289 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
290 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
291 | ||
292 | //fill custom group title | |
293 | $this->click("title"); | |
294 | $this->type("title", $customGroupTitle); | |
295 | ||
296 | //custom group extends | |
297 | $this->click("extends[0]"); | |
298 | $this->select("extends[0]", "value=Individual"); | |
299 | $this->addSelection("extends[1]", "label={$contactSubType}"); | |
300 | $this->click('_qf_Group_next-bottom'); | |
301 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
302 | ||
303 | //Is custom group created? | |
304 | $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added.")); | |
305 | $url = explode('gid=', $this->getLocation()); | |
306 | $gid = $url[1]; | |
307 | ||
308 | $fieldLabel = "custom_field_for_{$contactSubType}" . substr(sha1(rand()), 0, 4); | |
309 | $this->type('label', $fieldLabel); | |
310 | $this->click('_qf_Field_next-bottom'); | |
311 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
312 | $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); | |
313 | return array($customGroupTitle, $gid); | |
314 | } | |
315 | } | |
316 | ||
317 | ||
318 |