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';
28 class WebTest_Contact_RelationshipAddTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testRelationshipAddTest() {
35 $this->webtestLogin();
37 //create a relationship type between different contact types
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',
46 $this->webtestAddRelationshipType($params);
48 //create a New Individual
49 $firstName = substr(sha1(rand()), 0, 7);
50 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
51 $sortName = "Anderson, $firstName";
53 $this->openCiviPage("contact/add", "reset=1&ct=Household");
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);
61 $this->click("_qf_Contact_upload_view");
62 $this->waitForElementPresent("css=.crm-contact-tabs-list");
64 // visit relationship tab of the household
65 $this->click("css=li#tab_rel a");
67 // wait for add Relationship link
68 $this->waitForElementPresent('link=Add Relationship');
69 $this->click('link=Add Relationship');
71 //choose the created relationship type
72 $this->waitForElementPresent("relationship_type_id");
73 $this->select('relationship_type_id', "label={$params['label_b_a']}");
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]");
84 //fill in the relationship start date
85 $this->webtestFillDate('start_date', '-2 year');
86 $this->webtestFillDate('end_date', '+1 year');
88 $description = "Well here is some description !!!!";
89 $this->type("description", $description);
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");
96 //check the status message
97 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
102 $this->webtestVerifyTabularData(
104 'Description' => $description,
105 'Status' => 'Enabled',
109 $this->assertTrue($this->isTextPresent($params['label_b_a']));
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());
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";
130 $this->click("_qf_Contact_upload_view");
131 $this->waitForElementPresent("css=.crm-contact-tabs-list");
133 //create a New household subtype
134 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
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());
145 //create a new contact of household subtype
146 $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view');
148 //fill in Household name
149 $householdName = substr(sha1(rand()), 0, 4) . 'home';
150 $this->click("household_name");
151 $this->type("household_name", $householdName);
154 $this->click("_qf_Contact_upload_view");
155 $this->waitForPageToLoad($this->getTimeoutMsec());
157 //choose the created relationship type
158 $this->click('css=li#tab_rel a');
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']}");
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]");
175 //fill in the relationship start date
176 $this->webtestFillDate('start_date', '-2 year');
177 $this->webtestFillDate('end_date', '+1 year');
179 $description = "Well here is some description !!!!";
180 $this->type("description", $description);
182 //save the relationship
183 $this->click('_qf_Relationship_upload-bottom');
184 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
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']");
189 $this->webtestVerifyTabularData(
191 'Description' => $description,
192 'Status' => 'Enabled',
196 $this->assertTrue($this->isTextPresent($params['label_b_a']));
198 //test for individual contact and household subtype contact
200 $typeb = "Household" . CRM_Core_DAO
::VALUE_SEPARATOR
. $householdSubtypeName;
202 //create a relationship type between different contact types
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',
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']);
219 $params['contact_type_b'] = preg_replace('/' . CRM_Core_DAO
::VALUE_SEPARATOR
. '/', ' - ', $params['contact_type_b']);
222 $this->click('_qf_RelationshipType_next-bottom');
223 $this->waitForPageToLoad($this->getTimeoutMsec());
226 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
227 "Status message didn't show up after saving!"
230 $this->openCiviPage("admin/reltype", "reset=1");
232 //validate data on selector.
234 if (isset($data['description'])) {
235 unset($data['description']);
237 $this->assertStringsPresent($data);
239 //create a New Individual
240 $firstName = substr(sha1(rand()), 0, 7);
241 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
242 $sortName = "Anderson, $firstName";
244 //create a new contact of household subtype
245 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
247 //fill in Household name
248 $householdName = substr(sha1(rand()), 0, 4) . 'home';
249 $this->click("household_name");
250 $this->type("household_name", $householdName);
253 $this->click("_qf_Contact_upload_view");
254 $this->waitForPageToLoad($this->getTimeoutMsec());
256 //choose the created relationship type
257 $this->click('css=li#tab_rel a');
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']}");
265 //fill in the individual
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]");
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);
280 //save the relationship
281 $this->click('_qf_Relationship_upload-bottom');
282 $this->waitForElementPresent("crm-contact-relationship-selector-current_wrapper");
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']");
287 $this->webtestVerifyTabularData(
289 'Description' => $description,
290 'Status' => 'Enabled',
294 $this->assertTrue($this->isTextPresent($params['label_b_a']));
297 function testRelationshipAddNewIndividualTest() {
298 $this->webtestLogin();
300 //create a relationship type between different contact types
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.',
309 $this->webtestAddRelationshipType($params);
311 //create a New Individual
312 $firstName = substr(sha1(rand()), 0, 7);
313 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
315 // visit relationship tab of the Individual
316 $this->click("css=li#tab_rel a");
318 // wait for add Relationship link
319 $this->waitForElementPresent('link=Add Relationship');
320 $this->click('link=Add Relationship');
322 //choose the created relationship type
323 $this->waitForElementPresent("relationship_type_id");
324 $this->select('relationship_type_id', "label={$params['label_a_b']}");
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
331 // create a new organization
332 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
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");
342 //fill in the relationship start date
343 $this->webtestFillDate('start_date', '-2 year');
344 $this->webtestFillDate('end_date', '+1 year');
346 $description = "Long-standing board member.";
347 $this->type("description", $description);
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");
354 //check the status message
355 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
360 $this->webtestVerifyTabularData(
362 'Description' => $description,
363 'Status' => 'Enabled',
366 $this->assertTrue($this->isTextPresent($params['label_a_b']));
369 function testAjaxCustomGroupLoad() {
370 $this->webtestLogin();
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());
377 $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select');
379 array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement),
380 array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement)
383 $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
384 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
387 function testRelationshipAddCurrentEmployerTest() {
388 $this->webtestLogin();
390 //create a New Individual
391 $firstName = substr(sha1(rand()), 0, 7);
392 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
394 // visit relationship tab of the Individual
395 $this->click("css=li#tab_rel a");
397 // wait for add Relationship link
398 $this->waitForElementPresent('link=Add Relationship');
399 $this->click('link=Add Relationship');
401 //choose the created relationship type
402 $this->waitForElementPresent("relationship_type_id");
403 $this->select('relationship_type_id', "label=Employee of");
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
410 // create a new organization
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");
421 //fill in the relationship start date
422 $this->webtestFillDate('start_date', '-2 year');
423 $this->webtestFillDate('end_date', '+1 year');
425 $description = "Current employee test.";
426 $this->type("description", $description);
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");
434 //check the status message
435 $this->waitForText('crm-notification-container', 'Relationship created.');
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']");
440 $this->webtestVerifyTabularData(
442 'Description' => $description,
443 'Current Employee?' => 'Yes',
444 'Status' => 'Enabled',
447 $this->assertTrue($this->isTextPresent("Employee of"),"Employee of relationship type not visible on View Relationship page.");