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