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