Commit | Line | Data |
---|---|---|
6a488035 TO |
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testRelationshipAddTest() { | |
36 | // Logging in. Remember to wait for page to load. In most cases, | |
37 | // you can rely on 30000 as the value that allows your test to pass, however, | |
38 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
39 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
40 | // page contents loaded and you can continue your test execution. | |
41 | $this->webtestLogin(); | |
42 | ||
43 | //create a relationship type between different contact types | |
44 | $params = array( | |
45 | 'label_a_b' => 'Owner of ' . rand(), | |
46 | 'label_b_a' => 'Belongs to ' . rand(), | |
47 | 'contact_type_a' => 'Individual', | |
48 | 'contact_type_b' => 'Household', | |
49 | 'description' => 'The company belongs to this individual', | |
50 | ); | |
51 | ||
52 | $this->webtestAddRelationshipType($params); | |
53 | ||
54 | //create a New Individual | |
55 | $firstName = substr(sha1(rand()), 0, 7); | |
56 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); | |
57 | $sortName = "Anderson, $firstName"; | |
58 | ||
59 | // Go directly to the URL of the screen that you will be testing (New Household). | |
60 | $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Household"); | |
61 | ||
62 | //fill in Household name | |
63 | $this->click("household_name"); | |
64 | $name = "Fraddie Grant's home " . substr(sha1(rand()), 0, 7); | |
65 | $this->type("household_name", $name); | |
66 | ||
67 | // Clicking save. | |
68 | $this->click("_qf_Contact_upload_view"); | |
69 | $this->waitForElementPresent("css=.crm-contact-tabs-list"); | |
70 | ||
71 | // visit relationship tab of the household | |
72 | $this->click("css=li#tab_rel a"); | |
73 | ||
74 | // wait for add Relationship link | |
75 | $this->waitForElementPresent('link=Add Relationship'); | |
76 | $this->click('link=Add Relationship'); | |
77 | ||
78 | //choose the created relationship type | |
79 | $this->waitForElementPresent("relationship_type_id"); | |
80 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); | |
81 | ||
82 | //fill in the individual | |
83 | $this->webtestFillAutocomplete($sortName); | |
84 | ||
85 | $this->waitForElementPresent("quick-save"); | |
86 | ||
87 | //fill in the relationship start date | |
88 | $this->webtestFillDate('start_date', '-2 year'); | |
89 | $this->webtestFillDate('end_date', '+1 year'); | |
90 | ||
91 | $description = "Well here is some description !!!!"; | |
92 | $this->type("description", $description); | |
93 | ||
94 | //save the relationship | |
95 | //$this->click("_qf_Relationship_upload"); | |
96 | $this->click("quick-save"); | |
97 | $this->waitForElementPresent("current-relationships"); | |
98 | ||
99 | //check the status message | |
100 | $this->assertTrue($this->isTextPresent("New relationship created.")); | |
101 | ||
102 | $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
103 | $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
104 | ||
105 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
106 | $this->webtestVerifyTabularData( | |
107 | array( | |
108 | 'Description' => $description, | |
109 | 'Status' => 'Enabled', | |
110 | ) | |
111 | ); | |
112 | ||
113 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); | |
114 | ||
115 | //create a New Individual subtype | |
116 | $this->open($this->sboxPath . "civicrm/admin/options/subtype?action=add&reset=1"); | |
117 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
118 | $label = "IndividualSubtype" . substr(sha1(rand()), 0, 4); | |
119 | $this->type("label", $label); | |
120 | $this->type("description", "here is individual subtype"); | |
121 | $this->click("_qf_ContactType_next-bottom"); | |
122 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
123 | ||
124 | //create a new contact of individual subtype | |
125 | $this->open($this->sboxPath . "civicrm/contact/add?ct=Individual&cst={$label}&reset=1"); | |
126 | $this->waitForElementPresent('_qf_Contact_upload_view'); | |
127 | $firstName = substr(sha1(rand()), 0, 7); | |
128 | $lastName = 'And' . substr(sha1(rand()), 0, 7); | |
129 | $this->click("first_name"); | |
130 | $this->type("first_name", $firstName); | |
131 | $this->click("last_name"); | |
132 | $this->type("last_name", $lastName); | |
133 | $sortName = "$lastName, $firstName"; | |
134 | ||
135 | // Clicking save. | |
136 | $this->click("_qf_Contact_upload_view"); | |
137 | $this->waitForElementPresent("css=.crm-contact-tabs-list"); | |
138 | ||
139 | //create a New household subtype | |
140 | $this->open($this->sboxPath . "civicrm/admin/options/subtype?action=add&reset=1"); | |
141 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
142 | ||
143 | $label = "HouseholdSubtype" . substr(sha1(rand()), 0, 4); | |
144 | $householdSubtypeName = $label; | |
145 | $this->click("label"); | |
146 | $this->type("label", $label); | |
147 | $this->select("parent_id", "label=Household"); | |
148 | $this->type("description", "here is household subtype"); | |
149 | $this->click("_qf_ContactType_next-bottom"); | |
150 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
151 | ||
152 | //create a new contact of household subtype | |
153 | $this->open($this->sboxPath . "civicrm/contact/add?ct=Household&cst={$label}&reset=1"); | |
154 | $this->waitForElementPresent('_qf_Contact_upload_view'); | |
155 | ||
156 | //fill in Household name | |
157 | $householdName = substr(sha1(rand()), 0, 4) . 'home'; | |
158 | $this->click("household_name"); | |
159 | $this->type("household_name", $householdName); | |
160 | ||
161 | // Clicking save. | |
162 | $this->click("_qf_Contact_upload_view"); | |
163 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
164 | ||
165 | //choose the created relationship type | |
166 | $this->click('css=li#tab_rel a'); | |
167 | ||
168 | // wait for add Relationship link | |
169 | $this->waitForElementPresent('link=Add Relationship'); | |
170 | $this->click('link=Add Relationship'); | |
171 | $this->waitForElementPresent("relationship_type_id"); | |
172 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); | |
173 | ||
174 | //fill in the individual | |
175 | $this->webtestFillAutocomplete($sortName); | |
176 | ||
177 | $this->waitForElementPresent("quick-save"); | |
178 | ||
179 | //fill in the relationship start date | |
180 | $this->webtestFillDate('start_date', '-2 year'); | |
181 | $this->webtestFillDate('end_date', '+1 year'); | |
182 | ||
183 | $description = "Well here is some description !!!!"; | |
184 | $this->type("description", $description); | |
185 | ||
186 | //save the relationship | |
187 | $this->click("quick-save"); | |
188 | $this->waitForElementPresent("current-relationships"); | |
189 | ||
190 | $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
191 | $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
192 | ||
193 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
194 | $this->webtestVerifyTabularData( | |
195 | array( | |
196 | 'Description' => $description, | |
197 | 'Status' => 'Enabled', | |
198 | ) | |
199 | ); | |
200 | ||
201 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); | |
202 | ||
203 | //test for individual contact and household subtype contact | |
204 | //relationship | |
205 | $typeb = "Household" . CRM_Core_DAO::VALUE_SEPARATOR . $householdSubtypeName; | |
206 | ||
207 | //create a relationship type between different contact types | |
208 | $params = array( | |
209 | 'label_a_b' => 'Owner of ' . rand(), | |
210 | 'label_b_a' => 'Belongs to ' . rand(), | |
211 | 'contact_type_a' => 'Individual', | |
212 | 'contact_type_b' => $typeb, | |
213 | 'description' => 'The company belongs to this individual', | |
214 | ); | |
215 | ||
216 | //create relationship type | |
217 | $this->open($this->sboxPath . 'civicrm/admin/reltype?reset=1&action=add'); | |
218 | $this->type('label_a_b', $params['label_a_b']); | |
219 | $this->type('label_b_a', $params['label_b_a']); | |
220 | $this->select('contact_types_a', "value={$params['contact_type_a']}"); | |
221 | $this->select('contact_types_b', "value={$params['contact_type_b']}"); | |
222 | $this->type('description', $params['description']); | |
223 | ||
224 | $params['contact_type_b'] = preg_replace('/' . CRM_Core_DAO::VALUE_SEPARATOR . '/', ' - ', $params['contact_type_b']); | |
225 | ||
226 | //save the data. | |
227 | $this->click('_qf_RelationshipType_next-bottom'); | |
228 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
229 | ||
230 | //does data saved. | |
231 | $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'), | |
232 | "Status message didn't show up after saving!" | |
233 | ); | |
234 | ||
235 | $this->open($this->sboxPath . 'civicrm/admin/reltype?reset=1'); | |
236 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
237 | ||
238 | //validate data on selector. | |
239 | $data = $params; | |
240 | if (isset($data['description'])) { | |
241 | unset($data['description']); | |
242 | } | |
243 | $this->assertStringsPresent($data); | |
244 | ||
245 | //create a New Individual | |
246 | $firstName = substr(sha1(rand()), 0, 7); | |
247 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); | |
248 | $sortName = "Anderson, $firstName"; | |
249 | ||
250 | //create a new contact of household subtype | |
251 | $this->open($this->sboxPath . "civicrm/contact/add?ct=Household&cst=" . $householdSubtypeName . "&reset=1"); | |
252 | $this->waitForElementPresent('_qf_Contact_upload_view'); | |
253 | ||
254 | //fill in Household name | |
255 | $householdName = substr(sha1(rand()), 0, 4) . 'home'; | |
256 | $this->click("household_name"); | |
257 | $this->type("household_name", $householdName); | |
258 | ||
259 | // Clicking save. | |
260 | $this->click("_qf_Contact_upload_view"); | |
261 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
262 | ||
263 | //choose the created relationship type | |
264 | $this->click('css=li#tab_rel a'); | |
265 | ||
266 | // wait for add Relationship link | |
267 | $this->waitForElementPresent('link=Add Relationship'); | |
268 | $this->click('link=Add Relationship'); | |
269 | $this->waitForElementPresent("relationship_type_id"); | |
270 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); | |
271 | ||
272 | //fill in the individual | |
273 | $this->webtestFillAutocomplete($sortName); | |
274 | ||
275 | $this->waitForElementPresent("quick-save"); | |
276 | ||
277 | //fill in the relationship start date | |
278 | $this->webtestFillDate('start_date', '-2 year'); | |
279 | $this->webtestFillDate('end_date', '+1 year'); | |
280 | $description = "Well here is some description !!!!"; | |
281 | $this->type("description", $description); | |
282 | ||
283 | //save the relationship | |
284 | $this->click("quick-save"); | |
285 | $this->waitForElementPresent("current-relationships"); | |
286 | ||
287 | $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
288 | $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
289 | ||
290 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
291 | $this->webtestVerifyTabularData( | |
292 | array( | |
293 | 'Description' => $description, | |
294 | 'Status' => 'Enabled', | |
295 | ) | |
296 | ); | |
297 | ||
298 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); | |
299 | } | |
300 | ||
301 | function testRelationshipAddNewIndividualTest() { | |
302 | $this->webtestLogin(); | |
303 | ||
304 | //create a relationship type between different contact types | |
305 | $params = array( | |
306 | 'label_a_b' => 'Board Member of ' . rand(), | |
307 | 'label_b_a' => 'Board Member is' . rand(), | |
308 | 'contact_type_a' => 'Individual', | |
309 | 'contact_type_b' => 'Organization', | |
310 | 'description' => 'Board members of organizations.', | |
311 | ); | |
312 | ||
313 | $this->webtestAddRelationshipType($params); | |
314 | ||
315 | //create a New Individual | |
316 | $firstName = substr(sha1(rand()), 0, 7); | |
317 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); | |
318 | ||
319 | // visit relationship tab of the Individual | |
320 | $this->click("css=li#tab_rel a"); | |
321 | ||
322 | // wait for add Relationship link | |
323 | $this->waitForElementPresent('link=Add Relationship'); | |
324 | $this->click('link=Add Relationship'); | |
325 | ||
326 | //choose the created relationship type | |
327 | $this->waitForElementPresent("relationship_type_id"); | |
328 | $this->select('relationship_type_id', "label={$params['label_a_b']}"); | |
329 | ||
330 | //wait untill new contact dialog select is built | |
331 | sleep(2); | |
332 | ||
333 | // create a new organization | |
334 | $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7); | |
335 | $this->webtestNewDialogContact($orgName, "", "info@" . $orgName . ".com", 5); | |
336 | ||
337 | $this->waitForElementPresent("quick-save"); | |
338 | ||
339 | //fill in the relationship start date | |
340 | $this->webtestFillDate('start_date', '-2 year'); | |
341 | $this->webtestFillDate('end_date', '+1 year'); | |
342 | ||
343 | $description = "Long-standing board member."; | |
344 | $this->type("description", $description); | |
345 | ||
346 | //save the relationship | |
347 | //$this->click("_qf_Relationship_upload"); | |
348 | $this->click("quick-save"); | |
349 | $this->waitForElementPresent("current-relationships"); | |
350 | ||
351 | //check the status message | |
352 | $this->assertTrue($this->isTextPresent("New relationship created.")); | |
353 | ||
354 | $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
355 | $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']"); | |
356 | ||
357 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
358 | $this->webtestVerifyTabularData( | |
359 | array( | |
360 | 'Description' => $description, | |
361 | 'Status' => 'Enabled', | |
362 | ) | |
363 | ); | |
364 | $this->assertTrue($this->isTextPresent($params['label_a_b'])); | |
365 | } | |
366 | } | |
367 | ||
368 |