Merge pull request #4004 from civicrm/4.4
[civicrm-core.git] / tests / phpunit / WebTest / Contact / RelationshipAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_RelationshipAddTest
31 */
6a488035
TO
32class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testRelationshipAddTest() {
6a488035
TO
39 $this->webtestLogin();
40
41 //create a relationship type between different contact types
42 $params = array(
43 'label_a_b' => 'Owner of ' . rand(),
44 'label_b_a' => 'Belongs to ' . rand(),
45 'contact_type_a' => 'Individual',
46 'contact_type_b' => 'Household',
47 'description' => 'The company belongs to this individual',
48 );
49
50 $this->webtestAddRelationshipType($params);
51
52 //create a New Individual
53 $firstName = substr(sha1(rand()), 0, 7);
54 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
55 $sortName = "Anderson, $firstName";
56
42daf119 57 $this->openCiviPage("contact/add", "reset=1&ct=Household");
6a488035
TO
58
59 //fill in Household name
60 $this->click("household_name");
61 $name = "Fraddie Grant's home " . substr(sha1(rand()), 0, 7);
62 $this->type("household_name", $name);
63
64 // Clicking save.
65 $this->click("_qf_Contact_upload_view");
66 $this->waitForElementPresent("css=.crm-contact-tabs-list");
67
68 // visit relationship tab of the household
69 $this->click("css=li#tab_rel a");
70
71 // wait for add Relationship link
72 $this->waitForElementPresent('link=Add Relationship');
73 $this->click('link=Add Relationship');
74
75 //choose the created relationship type
76 $this->waitForElementPresent("relationship_type_id");
77 $this->select('relationship_type_id', "label={$params['label_b_a']}");
78
79 //fill in the individual
6acc185a 80 $this->select2('related_contact_id', $sortName, TRUE);
6a488035 81
6a488035
TO
82
83 //fill in the relationship start date
84 $this->webtestFillDate('start_date', '-2 year');
85 $this->webtestFillDate('end_date', '+1 year');
86
87 $description = "Well here is some description !!!!";
88 $this->type("description", $description);
89
90 //save the relationship
91 //$this->click("_qf_Relationship_upload");
0e32ba2d 92 $this->click('_qf_Relationship_upload-bottom');
93 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
6a488035
TO
94
95 //check the status message
0e32ba2d 96 $this->waitForText('crm-notification-container', 'Relationship created.');
6a488035 97
0e32ba2d 98 $this->waitForElementPresent("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
99 $this->click("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
6a488035 100
6a488035
TO
101 $this->webtestVerifyTabularData(
102 array(
103 'Description' => $description,
104 'Status' => 'Enabled',
105 )
106 );
107
108 $this->assertTrue($this->isTextPresent($params['label_b_a']));
109
110 //create a New Individual subtype
42daf119 111 $this->openCiviPage('admin/options/subtype', "action=add&reset=1");
6a488035
TO
112 $label = "IndividualSubtype" . substr(sha1(rand()), 0, 4);
113 $this->type("label", $label);
114 $this->type("description", "here is individual subtype");
115 $this->click("_qf_ContactType_next-bottom");
116 $this->waitForPageToLoad($this->getTimeoutMsec());
117
118 //create a new contact of individual subtype
42daf119 119 $this->openCiviPage('contact/add', "ct=Individual&cst={$label}&reset=1", '_qf_Contact_upload_view');
6a488035
TO
120 $firstName = substr(sha1(rand()), 0, 7);
121 $lastName = 'And' . substr(sha1(rand()), 0, 7);
122 $this->click("first_name");
123 $this->type("first_name", $firstName);
124 $this->click("last_name");
125 $this->type("last_name", $lastName);
126 $sortName = "$lastName, $firstName";
127
128 // Clicking save.
129 $this->click("_qf_Contact_upload_view");
130 $this->waitForElementPresent("css=.crm-contact-tabs-list");
131
132 //create a New household subtype
42daf119 133 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
6a488035
TO
134
135 $label = "HouseholdSubtype" . substr(sha1(rand()), 0, 4);
136 $householdSubtypeName = $label;
137 $this->click("label");
138 $this->type("label", $label);
139 $this->select("parent_id", "label=Household");
140 $this->type("description", "here is household subtype");
141 $this->click("_qf_ContactType_next-bottom");
142 $this->waitForPageToLoad($this->getTimeoutMsec());
143
144 //create a new contact of household subtype
42daf119 145 $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view');
6a488035
TO
146
147 //fill in Household name
148 $householdName = substr(sha1(rand()), 0, 4) . 'home';
149 $this->click("household_name");
150 $this->type("household_name", $householdName);
151
152 // Clicking save.
153 $this->click("_qf_Contact_upload_view");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
155
156 //choose the created relationship type
157 $this->click('css=li#tab_rel a');
158
159 // wait for add Relationship link
160 $this->waitForElementPresent('link=Add Relationship');
161 $this->click('link=Add Relationship');
162 $this->waitForElementPresent("relationship_type_id");
163 $this->select('relationship_type_id', "label={$params['label_b_a']}");
164
165 //fill in the individual
6acc185a 166 $this->select2('related_contact_id', $sortName, TRUE);
6a488035 167
6a488035
TO
168
169 //fill in the relationship start date
170 $this->webtestFillDate('start_date', '-2 year');
171 $this->webtestFillDate('end_date', '+1 year');
172
173 $description = "Well here is some description !!!!";
174 $this->type("description", $description);
175
176 //save the relationship
0e32ba2d 177 $this->click('_qf_Relationship_upload-bottom');
178 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
6a488035 179
0e32ba2d 180 $this->waitForElementPresent("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
181 $this->click("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
6a488035 182
6a488035
TO
183 $this->webtestVerifyTabularData(
184 array(
185 'Description' => $description,
186 'Status' => 'Enabled',
187 )
188 );
189
190 $this->assertTrue($this->isTextPresent($params['label_b_a']));
191
192 //test for individual contact and household subtype contact
193 //relationship
1d4d99e9 194 $typeb = "Household__". $householdSubtypeName;
6a488035
TO
195
196 //create a relationship type between different contact types
197 $params = array(
198 'label_a_b' => 'Owner of ' . rand(),
199 'label_b_a' => 'Belongs to ' . rand(),
200 'contact_type_a' => 'Individual',
201 'contact_type_b' => $typeb,
202 'description' => 'The company belongs to this individual',
203 );
204
205 //create relationship type
42daf119 206 $this->openCiviPage('admin/reltype', 'reset=1&action=add');
6a488035
TO
207 $this->type('label_a_b', $params['label_a_b']);
208 $this->type('label_b_a', $params['label_b_a']);
209 $this->select('contact_types_a', "value={$params['contact_type_a']}");
210 $this->select('contact_types_b', "value={$params['contact_type_b']}");
211 $this->type('description', $params['description']);
212
1d4d99e9 213 $params['contact_type_b'] = preg_replace('/__/', ' - ', $params['contact_type_b']);
6a488035
TO
214
215 //save the data.
216 $this->click('_qf_RelationshipType_next-bottom');
217 $this->waitForPageToLoad($this->getTimeoutMsec());
218
219 //does data saved.
220 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
221 "Status message didn't show up after saving!"
222 );
223
071a6d2e 224 $this->openCiviPage("admin/reltype", "reset=1");
6a488035
TO
225
226 //validate data on selector.
227 $data = $params;
228 if (isset($data['description'])) {
229 unset($data['description']);
230 }
231 $this->assertStringsPresent($data);
232
233 //create a New Individual
234 $firstName = substr(sha1(rand()), 0, 7);
235 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
236 $sortName = "Anderson, $firstName";
237
238 //create a new contact of household subtype
42daf119 239 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
6a488035
TO
240
241 //fill in Household name
242 $householdName = substr(sha1(rand()), 0, 4) . 'home';
243 $this->click("household_name");
244 $this->type("household_name", $householdName);
245
246 // Clicking save.
247 $this->click("_qf_Contact_upload_view");
248 $this->waitForPageToLoad($this->getTimeoutMsec());
249
250 //choose the created relationship type
251 $this->click('css=li#tab_rel a');
252
253 // wait for add Relationship link
254 $this->waitForElementPresent('link=Add Relationship');
255 $this->click('link=Add Relationship');
256 $this->waitForElementPresent("relationship_type_id");
257 $this->select('relationship_type_id', "label={$params['label_b_a']}");
258
259 //fill in the individual
6a488035 260
6acc185a 261 $this->select2('related_contact_id', $sortName, TRUE);
6a488035
TO
262
263 //fill in the relationship start date
264 $this->webtestFillDate('start_date', '-2 year');
265 $this->webtestFillDate('end_date', '+1 year');
266 $description = "Well here is some description !!!!";
267 $this->type("description", $description);
268
269 //save the relationship
0e32ba2d 270 $this->click('_qf_Relationship_upload-bottom');
271 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
6a488035 272
0e32ba2d 273 $this->waitForElementPresent("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
274 $this->click("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
6a488035 275
6a488035
TO
276 $this->webtestVerifyTabularData(
277 array(
278 'Description' => $description,
279 'Status' => 'Enabled',
280 )
281 );
282
283 $this->assertTrue($this->isTextPresent($params['label_b_a']));
284 }
285
286 function testRelationshipAddNewIndividualTest() {
287 $this->webtestLogin();
288
289 //create a relationship type between different contact types
290 $params = array(
291 'label_a_b' => 'Board Member of ' . rand(),
292 'label_b_a' => 'Board Member is' . rand(),
293 'contact_type_a' => 'Individual',
294 'contact_type_b' => 'Organization',
295 'description' => 'Board members of organizations.',
296 );
297
298 $this->webtestAddRelationshipType($params);
299
300 //create a New Individual
301 $firstName = substr(sha1(rand()), 0, 7);
302 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
303
304 // visit relationship tab of the Individual
305 $this->click("css=li#tab_rel a");
306
307 // wait for add Relationship link
308 $this->waitForElementPresent('link=Add Relationship');
309 $this->click('link=Add Relationship');
310
311 //choose the created relationship type
312 $this->waitForElementPresent("relationship_type_id");
313 $this->select('relationship_type_id', "label={$params['label_a_b']}");
314
efb29358
CW
315 // Because it tends to cause problems, all uses of sleep() must be justified in comments
316 // Sleep should never be used for wait for anything to load from the server
317 // Justification for this instance: wait until new contact dialog select is built
6a488035
TO
318 sleep(2);
319
320 // create a new organization
321 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
6a488035 322
0e32ba2d 323 $this->click("//*[@id='related_contact_id']/../div/ul/li/input");
324 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
325 $this->waitForElementPresent('_qf_Edit_next');
326 $this->type('organization_name', $orgName);
327 $this->type('email-Primary', "info@" . $orgName . ".com");
328 $this->click('_qf_Edit_next');
329 $this->waitForText("xpath=//div[@id='s2id_related_contact_id']","$orgName");
6a488035
TO
330
331 //fill in the relationship start date
332 $this->webtestFillDate('start_date', '-2 year');
333 $this->webtestFillDate('end_date', '+1 year');
334
335 $description = "Long-standing board member.";
336 $this->type("description", $description);
337
338 //save the relationship
339 //$this->click("_qf_Relationship_upload");
0e32ba2d 340 $this->click("_qf_Relationship_upload-bottom");
341 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
6a488035
TO
342
343 //check the status message
0e32ba2d 344 $this->waitForText('crm-notification-container', 'Relationship created.');
6a488035 345
0e32ba2d 346 $this->waitForElementPresent("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
347 $this->click("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
6a488035 348
6a488035
TO
349 $this->webtestVerifyTabularData(
350 array(
351 'Description' => $description,
352 'Status' => 'Enabled',
353 )
354 );
355 $this->assertTrue($this->isTextPresent($params['label_a_b']));
356 }
6a488035 357
c4e6d4e8
PJ
358 function testAjaxCustomGroupLoad() {
359 $this->webtestLogin();
360
361 //create a New Individual
362 $firstName = substr(sha1(rand()), 0, 7);
363 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
364 $contactId = explode('cid=', $this->getLocation());
365
366 $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select');
367 $customSets = array(
368 array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement),
369 array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement)
370 );
371
372 $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
373 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
374 }
e9479dcf 375
a131ae6d
DG
376 function testRelationshipAddCurrentEmployerTest() {
377 $this->webtestLogin();
378
379 //create a New Individual
380 $firstName = substr(sha1(rand()), 0, 7);
381 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
382
383 // visit relationship tab of the Individual
384 $this->click("css=li#tab_rel a");
385
386 // wait for add Relationship link
387 $this->waitForElementPresent('link=Add Relationship');
388 $this->click('link=Add Relationship');
389
390 //choose the created relationship type
391 $this->waitForElementPresent("relationship_type_id");
392 $this->select('relationship_type_id', "label=Employee of");
393
394 // Because it tends to cause problems, all uses of sleep() must be justified in comments
395 // Sleep should never be used for wait for anything to load from the server
396 // Justification for this instance: wait until new contact dialog select is built
397 sleep(2);
398
399 // create a new organization
a131ae6d 400
0e32ba2d 401 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
402 $this->click("//*[@id='related_contact_id']/../div/ul/li/input");
403 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
404 $this->waitForElementPresent('_qf_Edit_next');
405 $this->type('organization_name', $orgName);
406 $this->type('email-Primary', "info@" . $orgName . ".com");
407 $this->click('_qf_Edit_next');
408 $this->waitForText("xpath=//div[@id='s2id_related_contact_id']","$orgName");
a131ae6d
DG
409
410 //fill in the relationship start date
411 $this->webtestFillDate('start_date', '-2 year');
412 $this->webtestFillDate('end_date', '+1 year');
413
414 $description = "Current employee test.";
415 $this->type("description", $description);
416
a131ae6d
DG
417
418 //save the relationship
419 //$this->click("_qf_Relationship_upload");
0e32ba2d 420 $this->click('_qf_Relationship_upload-bottom');
421 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
a131ae6d
DG
422
423 //check the status message
0e32ba2d 424 $this->waitForText('crm-notification-container', 'Relationship created.');
a131ae6d 425
0e32ba2d 426 $this->waitForElementPresent("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
427 $this->click("xpath=//div[@id='crm-contact-relationship-selector-current_wrapper']//table/tbody//tr/td[9]/span/a[text()='View']");
a131ae6d 428
a131ae6d
DG
429 $this->webtestVerifyTabularData(
430 array(
431 'Description' => $description,
432 'Current Employee?' => 'Yes',
433 'Status' => 'Enabled',
434 )
435 );
436 $this->assertTrue($this->isTextPresent("Employee of"),"Employee of relationship type not visible on View Relationship page.");
437 }
232624b1 438}