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