commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / WebTest / Contact / RelationshipAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
29 /**
30 * Class WebTest_Contact_RelationshipAddTest
31 */
32 class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testRelationshipAddTest() {
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
57 $this->openCiviPage("contact/add", "reset=1&ct=Household");
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
80 $this->select2('related_contact_id', $sortName, TRUE);
81
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");
91 $this->click('_qf_Relationship_upload-bottom');
92
93 //check the status message
94 $this->waitForText('crm-notification-container', 'Relationship created.');
95
96 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
97 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
98
99 $this->webtestVerifyTabularData(
100 array(
101 'Description' => $description,
102 'Status' => 'Enabled',
103 )
104 );
105
106 $this->assertTrue($this->isTextPresent($params['label_b_a']));
107
108 //create a New Individual subtype
109 $this->openCiviPage('admin/options/subtype', "action=add&reset=1");
110 $label = "IndividualSubtype" . substr(sha1(rand()), 0, 4);
111 $this->type("label", $label);
112 $this->type("description", "here is individual subtype");
113 $this->click("_qf_ContactType_next-bottom");
114 $this->waitForPageToLoad($this->getTimeoutMsec());
115
116 //create a new contact of individual subtype
117 $this->openCiviPage('contact/add', "ct=Individual&cst={$label}&reset=1", '_qf_Contact_upload_view');
118 $firstName = substr(sha1(rand()), 0, 7);
119 $lastName = 'And' . substr(sha1(rand()), 0, 7);
120 $this->click("first_name");
121 $this->type("first_name", $firstName);
122 $this->click("last_name");
123 $this->type("last_name", $lastName);
124 $sortName = "$lastName, $firstName";
125
126 // Clicking save.
127 $this->click("_qf_Contact_upload_view");
128 $this->waitForElementPresent("css=.crm-contact-tabs-list");
129
130 //create a New household subtype
131 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
132
133 $label = "HouseholdSubtype" . substr(sha1(rand()), 0, 4);
134 $householdSubtypeName = $label;
135 $this->click("label");
136 $this->type("label", $label);
137 $this->select("parent_id", "label=Household");
138 $this->type("description", "here is household subtype");
139 $this->click("_qf_ContactType_next-bottom");
140 $this->waitForPageToLoad($this->getTimeoutMsec());
141
142 //create a new contact of household subtype
143 $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view');
144
145 //fill in Household name
146 $householdName = substr(sha1(rand()), 0, 4) . 'home';
147 $this->click("household_name");
148 $this->type("household_name", $householdName);
149
150 // Clicking save.
151 $this->click("_qf_Contact_upload_view");
152 $this->waitForPageToLoad($this->getTimeoutMsec());
153
154 //choose the created relationship type
155 $this->click('css=li#tab_rel a');
156
157 // wait for add Relationship link
158 $this->waitForElementPresent('link=Add Relationship');
159 $this->click('link=Add Relationship');
160 $this->waitForElementPresent("relationship_type_id");
161 $this->select('relationship_type_id', "label={$params['label_b_a']}");
162
163 //fill in the individual
164 $this->select2('related_contact_id', $sortName, TRUE);
165
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
174 $this->click('_qf_Relationship_upload-bottom');
175
176 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
177 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
178
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
190 $typeb = "Household__" . $householdSubtypeName;
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
202 $this->openCiviPage('admin/reltype', 'reset=1&action=add');
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
209 $params['contact_type_b'] = preg_replace('/__/', ' - ', $params['contact_type_b']);
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
220 $this->openCiviPage("admin/reltype", "reset=1");
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
235 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
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
256
257 $this->select2('related_contact_id', $sortName, TRUE);
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
266 $this->click('_qf_Relationship_upload-bottom');
267
268 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
269 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
270
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
281 public function testRelationshipAddNewIndividualTest() {
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']}");
309
310 // Because it tends to cause problems, all uses of sleep() must be justified in comments
311 // Sleep should never be used for wait for anything to load from the server
312 // Justification for this instance: wait until new contact dialog select is built
313 sleep(2);
314
315 // create a new organization
316 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
317
318 $this->click("//*[@id='related_contact_id']/../div/ul/li/input");
319 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
320 $this->waitForElementPresent('_qf_Edit_next');
321 $this->type('organization_name', $orgName);
322 $this->type('email-Primary', "info@" . $orgName . ".com");
323 $this->click('_qf_Edit_next');
324 $this->waitForText("xpath=//div[@id='s2id_related_contact_id']", "$orgName");
325
326 //fill in the relationship start date
327 $this->webtestFillDate('start_date', '-2 year');
328 $this->webtestFillDate('end_date', '+1 year');
329
330 $description = "Long-standing board member.";
331 $this->type("description", $description);
332
333 //save the relationship
334 //$this->click("_qf_Relationship_upload");
335 $this->click("_qf_Relationship_upload-bottom");
336
337 //check the status message
338 $this->waitForText('crm-notification-container', 'Relationship created.');
339
340 $this->waitForElementPresent("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody/tr/td[9]/span/a[1][text()='View']");
341 $this->click("xpath=//table[@class='crm-contact-relationship-selector-current dataTable no-footer']/tbody/tr/td[9]/span/a[1][text()='View']");
342
343 $this->webtestVerifyTabularData(
344 array(
345 'Description' => $description,
346 'Status' => 'Enabled',
347 )
348 );
349 $this->assertTrue($this->isTextPresent($params['label_a_b']));
350 }
351
352 public function testAjaxCustomGroupLoad() {
353 $this->webtestLogin();
354
355 //create a New Individual
356 $firstName = substr(sha1(rand()), 0, 7);
357 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
358 $contactId = explode('cid=', $this->getLocation());
359
360 $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select');
361 $customSets = array(
362 array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement),
363 array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement),
364 );
365
366 $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
367 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
368 }
369
370 public function testRelationshipAddCurrentEmployerTest() {
371 $this->webtestLogin();
372
373 //create a New Individual
374 $firstName = substr(sha1(rand()), 0, 7);
375 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
376
377 // visit relationship tab of the Individual
378 $this->click("css=li#tab_rel a");
379
380 // wait for add Relationship link
381 $this->waitForElementPresent('link=Add Relationship');
382 $this->click('link=Add Relationship');
383
384 //choose the created relationship type
385 $this->waitForElementPresent("relationship_type_id");
386 $this->select('relationship_type_id', "label=Employee of");
387
388 // Because it tends to cause problems, all uses of sleep() must be justified in comments
389 // Sleep should never be used for wait for anything to load from the server
390 // Justification for this instance: wait until new contact dialog select is built
391 sleep(2);
392
393 // create a new organization
394
395 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
396 $this->click("//*[@id='related_contact_id']/../div/ul/li/input");
397 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
398 $this->waitForElementPresent('_qf_Edit_next');
399 $this->type('organization_name', $orgName);
400 $this->type('email-Primary', "info@" . $orgName . ".com");
401 $this->click('_qf_Edit_next');
402 $this->waitForText("xpath=//div[@id='s2id_related_contact_id']", "$orgName");
403
404 //fill in the relationship start date
405 $this->webtestFillDate('start_date', '-2 year');
406 $this->webtestFillDate('end_date', '+1 year');
407
408 $description = "Current employee test.";
409 $this->type("description", $description);
410
411 //save the relationship
412 //$this->click("_qf_Relationship_upload");
413 $this->click('_qf_Relationship_upload-bottom');
414
415 //check the status message
416 $this->waitForText('crm-notification-container', 'Relationship created.');
417
418 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
419 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]/span/a[1][text()='View']");
420
421 $this->webtestVerifyTabularData(
422 array(
423 'Description' => $description,
424 'Current Employee?' => 'Yes',
425 'Status' => 'Enabled',
426 )
427 );
428 $this->assertTrue($this->isTextPresent("Employee of"), "Employee of relationship type not visible on View Relationship page.");
429 }
430
431 }