CRM-12378 a new webtest helper function introduction which can help detect break...
[civicrm-core.git] / tests / phpunit / WebTest / Contact / RelationshipAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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->webtestFillAutocomplete($sortName);
77
78 $this->waitForElementPresent("quick-save");
79
80 //fill in the relationship start date
81 $this->webtestFillDate('start_date', '-2 year');
82 $this->webtestFillDate('end_date', '+1 year');
83
84 $description = "Well here is some description !!!!";
85 $this->type("description", $description);
86
87 //save the relationship
88 //$this->click("_qf_Relationship_upload");
89 $this->click("quick-save");
90 $this->waitForElementPresent("current-relationships");
91
92 //check the status message
93 $this->assertTrue($this->isTextPresent("New relationship created."));
94
95 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
96 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
97
98 $this->waitForPageToLoad($this->getTimeoutMsec());
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->webtestFillAutocomplete($sortName);
165
166 $this->waitForElementPresent("quick-save");
167
168 //fill in the relationship start date
169 $this->webtestFillDate('start_date', '-2 year');
170 $this->webtestFillDate('end_date', '+1 year');
171
172 $description = "Well here is some description !!!!";
173 $this->type("description", $description);
174
175 //save the relationship
176 $this->click("quick-save");
177 $this->waitForElementPresent("current-relationships");
178
179 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
180 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
181
182 $this->waitForPageToLoad($this->getTimeoutMsec());
183 $this->webtestVerifyTabularData(
184 array(
185 'Description' => $description,
186 'Status' => 'Enabled',
187 )
188 );
189
190 $this->assertTrue($this->isTextPresent($params['label_b_a']));
191
192 //test for individual contact and household subtype contact
193 //relationship
194 $typeb = "Household" . CRM_Core_DAO::VALUE_SEPARATOR . $householdSubtypeName;
195
196 //create a relationship type between different contact types
197 $params = array(
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',
203 );
204
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']);
212
213 $params['contact_type_b'] = preg_replace('/' . CRM_Core_DAO::VALUE_SEPARATOR . '/', ' - ', $params['contact_type_b']);
214
215 //save the data.
216 $this->click('_qf_RelationshipType_next-bottom');
217 $this->waitForPageToLoad($this->getTimeoutMsec());
218
219 //does data saved.
220 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
221 "Status message didn't show up after saving!"
222 );
223
224 $this->openCiviPage("admin/reltype", "reset=1");
225
226 //validate data on selector.
227 $data = $params;
228 if (isset($data['description'])) {
229 unset($data['description']);
230 }
231 $this->assertStringsPresent($data);
232
233 //create a New Individual
234 $firstName = substr(sha1(rand()), 0, 7);
235 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
236 $sortName = "Anderson, $firstName";
237
238 //create a new contact of household subtype
239 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
240
241 //fill in Household name
242 $householdName = substr(sha1(rand()), 0, 4) . 'home';
243 $this->click("household_name");
244 $this->type("household_name", $householdName);
245
246 // Clicking save.
247 $this->click("_qf_Contact_upload_view");
248 $this->waitForPageToLoad($this->getTimeoutMsec());
249
250 //choose the created relationship type
251 $this->click('css=li#tab_rel a');
252
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']}");
258
259 //fill in the individual
260 $this->webtestFillAutocomplete($sortName);
261
262 $this->waitForElementPresent("quick-save");
263
264 //fill in the relationship start date
265 $this->webtestFillDate('start_date', '-2 year');
266 $this->webtestFillDate('end_date', '+1 year');
267 $description = "Well here is some description !!!!";
268 $this->type("description", $description);
269
270 //save the relationship
271 $this->click("quick-save");
272 $this->waitForElementPresent("current-relationships");
273
274 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
275 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
276
277 $this->waitForPageToLoad($this->getTimeoutMsec());
278 $this->webtestVerifyTabularData(
279 array(
280 'Description' => $description,
281 'Status' => 'Enabled',
282 )
283 );
284
285 $this->assertTrue($this->isTextPresent($params['label_b_a']));
286 }
287
288 function testRelationshipAddNewIndividualTest() {
289 $this->webtestLogin();
290
291 //create a relationship type between different contact types
292 $params = array(
293 'label_a_b' => 'Board Member of ' . rand(),
294 'label_b_a' => 'Board Member is' . rand(),
295 'contact_type_a' => 'Individual',
296 'contact_type_b' => 'Organization',
297 'description' => 'Board members of organizations.',
298 );
299
300 $this->webtestAddRelationshipType($params);
301
302 //create a New Individual
303 $firstName = substr(sha1(rand()), 0, 7);
304 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
305
306 // visit relationship tab of the Individual
307 $this->click("css=li#tab_rel a");
308
309 // wait for add Relationship link
310 $this->waitForElementPresent('link=Add Relationship');
311 $this->click('link=Add Relationship');
312
313 //choose the created relationship type
314 $this->waitForElementPresent("relationship_type_id");
315 $this->select('relationship_type_id', "label={$params['label_a_b']}");
316
317 // Because it tends to cause problems, all uses of sleep() must be justified in comments
318 // Sleep should never be used for wait for anything to load from the server
319 // Justification for this instance: wait until new contact dialog select is built
320 sleep(2);
321
322 // create a new organization
323 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
324 $this->webtestNewDialogContact($orgName, "", "info@" . $orgName . ".com", 5);
325
326 $this->waitForElementPresent("quick-save");
327
328 //fill in the relationship start date
329 $this->webtestFillDate('start_date', '-2 year');
330 $this->webtestFillDate('end_date', '+1 year');
331
332 $description = "Long-standing board member.";
333 $this->type("description", $description);
334
335 //save the relationship
336 //$this->click("_qf_Relationship_upload");
337 $this->click("quick-save");
338 $this->waitForElementPresent("current-relationships");
339
340 //check the status message
341 $this->assertTrue($this->isTextPresent("New relationship created."));
342
343 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
344 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
345
346 $this->waitForPageToLoad($this->getTimeoutMsec());
347 $this->webtestVerifyTabularData(
348 array(
349 'Description' => $description,
350 'Status' => 'Enabled',
351 )
352 );
353 $this->assertTrue($this->isTextPresent($params['label_a_b']));
354 }
355
356 function testAjaxCustomGroupLoad() {
357 $this->webtestLogin();
358
359 //create a New Individual
360 $firstName = substr(sha1(rand()), 0, 7);
361 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
362 $contactId = explode('cid=', $this->getLocation());
363
364 $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select');
365 $customSets = array(
366 array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement),
367 array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement)
368 );
369
370 $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1");
371 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
372 }
373 }