3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_RelationshipAddTest
32 class WebTest_Contact_RelationshipAddTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testRelationshipAddTest() {
39 $this->webtestLogin();
41 //create a relationship type between different contact types
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',
50 $this->webtestAddRelationshipType($params);
52 //create a New Individual
53 $firstName = substr(sha1(rand()), 0, 7);
54 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
55 $sortName = "Anderson, $firstName";
57 $this->openCiviPage("contact/add", "reset=1&ct=Household");
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);
65 $this->click("_qf_Contact_upload_view");
66 $this->waitForElementPresent("css=.crm-contact-tabs-list");
68 // visit relationship tab of the household
69 $this->click("css=li#tab_rel a");
71 // wait for add Relationship link
72 $this->waitForElementPresent('link=Add Relationship');
73 $this->click('link=Add Relationship');
75 //choose the created relationship type
76 $this->waitForElementPresent("relationship_type_id");
77 $this->select('relationship_type_id', "label={$params['label_b_a']}");
79 //fill in the individual
80 $this->select2('related_contact_id', $sortName, TRUE);
83 //fill in the relationship start date
84 $this->webtestFillDate('start_date', '-2 year');
85 $this->webtestFillDate('end_date', '+1 year');
87 $description = "Well here is some description !!!!";
88 $this->type("description", $description);
90 //save the relationship
91 //$this->click("_qf_Relationship_upload");
92 $this->click('_qf_Relationship_upload-bottom');
93 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
95 //check the status message
96 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
101 $this->webtestVerifyTabularData(
103 'Description' => $description,
104 'Status' => 'Enabled',
108 $this->assertTrue($this->isTextPresent($params['label_b_a']));
110 //create a New Individual subtype
111 $this->openCiviPage('admin/options/subtype', "action=add&reset=1");
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());
118 //create a new contact of individual subtype
119 $this->openCiviPage('contact/add', "ct=Individual&cst={$label}&reset=1", '_qf_Contact_upload_view');
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";
129 $this->click("_qf_Contact_upload_view");
130 $this->waitForElementPresent("css=.crm-contact-tabs-list");
132 //create a New household subtype
133 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
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());
144 //create a new contact of household subtype
145 $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view');
147 //fill in Household name
148 $householdName = substr(sha1(rand()), 0, 4) . 'home';
149 $this->click("household_name");
150 $this->type("household_name", $householdName);
153 $this->click("_qf_Contact_upload_view");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
156 //choose the created relationship type
157 $this->click('css=li#tab_rel a');
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']}");
165 //fill in the individual
166 $this->select2('related_contact_id', $sortName, TRUE);
169 //fill in the relationship start date
170 $this->webtestFillDate('start_date', '-2 year');
171 $this->webtestFillDate('end_date', '+1 year');
173 $description = "Well here is some description !!!!";
174 $this->type("description", $description);
176 //save the relationship
177 $this->click('_qf_Relationship_upload-bottom');
178 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
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']");
183 $this->webtestVerifyTabularData(
185 'Description' => $description,
186 'Status' => 'Enabled',
190 $this->assertTrue($this->isTextPresent($params['label_b_a']));
192 //test for individual contact and household subtype contact
194 $typeb = "Household__". $householdSubtypeName;
196 //create a relationship type between different contact types
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',
205 //create relationship type
206 $this->openCiviPage('admin/reltype', 'reset=1&action=add');
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']);
213 $params['contact_type_b'] = preg_replace('/__/', ' - ', $params['contact_type_b']);
216 $this->click('_qf_RelationshipType_next-bottom');
217 $this->waitForPageToLoad($this->getTimeoutMsec());
220 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
221 "Status message didn't show up after saving!"
224 $this->openCiviPage("admin/reltype", "reset=1");
226 //validate data on selector.
228 if (isset($data['description'])) {
229 unset($data['description']);
231 $this->assertStringsPresent($data);
233 //create a New Individual
234 $firstName = substr(sha1(rand()), 0, 7);
235 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
236 $sortName = "Anderson, $firstName";
238 //create a new contact of household subtype
239 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
241 //fill in Household name
242 $householdName = substr(sha1(rand()), 0, 4) . 'home';
243 $this->click("household_name");
244 $this->type("household_name", $householdName);
247 $this->click("_qf_Contact_upload_view");
248 $this->waitForPageToLoad($this->getTimeoutMsec());
250 //choose the created relationship type
251 $this->click('css=li#tab_rel a');
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']}");
259 //fill in the individual
261 $this->select2('related_contact_id', $sortName, TRUE);
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);
269 //save the relationship
270 $this->click('_qf_Relationship_upload-bottom');
271 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
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']");
276 $this->webtestVerifyTabularData(
278 'Description' => $description,
279 'Status' => 'Enabled',
283 $this->assertTrue($this->isTextPresent($params['label_b_a']));
286 function testRelationshipAddNewIndividualTest() {
287 $this->webtestLogin();
289 //create a relationship type between different contact types
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.',
298 $this->webtestAddRelationshipType($params);
300 //create a New Individual
301 $firstName = substr(sha1(rand()), 0, 7);
302 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
304 // visit relationship tab of the Individual
305 $this->click("css=li#tab_rel a");
307 // wait for add Relationship link
308 $this->waitForElementPresent('link=Add Relationship');
309 $this->click('link=Add Relationship');
311 //choose the created relationship type
312 $this->waitForElementPresent("relationship_type_id");
313 $this->select('relationship_type_id', "label={$params['label_a_b']}");
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
320 // create a new organization
321 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
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");
331 //fill in the relationship start date
332 $this->webtestFillDate('start_date', '-2 year');
333 $this->webtestFillDate('end_date', '+1 year');
335 $description = "Long-standing board member.";
336 $this->type("description", $description);
338 //save the relationship
339 //$this->click("_qf_Relationship_upload");
340 $this->click("_qf_Relationship_upload-bottom");
341 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
343 //check the status message
344 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
349 $this->webtestVerifyTabularData(
351 'Description' => $description,
352 'Status' => 'Enabled',
355 $this->assertTrue($this->isTextPresent($params['label_a_b']));
358 function testAjaxCustomGroupLoad() {
359 $this->webtestLogin();
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());
366 $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select');
368 array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement),
369 array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement)
372 $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
373 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
376 function testRelationshipAddCurrentEmployerTest() {
377 $this->webtestLogin();
379 //create a New Individual
380 $firstName = substr(sha1(rand()), 0, 7);
381 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
383 // visit relationship tab of the Individual
384 $this->click("css=li#tab_rel a");
386 // wait for add Relationship link
387 $this->waitForElementPresent('link=Add Relationship');
388 $this->click('link=Add Relationship');
390 //choose the created relationship type
391 $this->waitForElementPresent("relationship_type_id");
392 $this->select('relationship_type_id', "label=Employee of");
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
399 // create a new organization
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");
410 //fill in the relationship start date
411 $this->webtestFillDate('start_date', '-2 year');
412 $this->webtestFillDate('end_date', '+1 year');
414 $description = "Current employee test.";
415 $this->type("description", $description);
418 //save the relationship
419 //$this->click("_qf_Relationship_upload");
420 $this->click('_qf_Relationship_upload-bottom');
421 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
423 //check the status message
424 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
429 $this->webtestVerifyTabularData(
431 'Description' => $description,
432 'Current Employee?' => 'Yes',
433 'Status' => 'Enabled',
436 $this->assertTrue($this->isTextPresent("Employee of"),"Employee of relationship type not visible on View Relationship page.");