3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_RelationshipAddTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
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();
43 //create a relationship type between different contact types
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',
52 $this->webtestAddRelationshipType($params);
54 //create a New Individual
55 $firstName = substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
57 $sortName = "Anderson, $firstName";
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");
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);
68 $this->click("_qf_Contact_upload_view");
69 $this->waitForElementPresent("css=.crm-contact-tabs-list");
71 // visit relationship tab of the household
72 $this->click("css=li#tab_rel a");
74 // wait for add Relationship link
75 $this->waitForElementPresent('link=Add Relationship');
76 $this->click('link=Add Relationship');
78 //choose the created relationship type
79 $this->waitForElementPresent("relationship_type_id");
80 $this->select('relationship_type_id', "label={$params['label_b_a']}");
82 //fill in the individual
83 $this->webtestFillAutocomplete($sortName);
85 $this->waitForElementPresent("quick-save");
87 //fill in the relationship start date
88 $this->webtestFillDate('start_date', '-2 year');
89 $this->webtestFillDate('end_date', '+1 year');
91 $description = "Well here is some description !!!!";
92 $this->type("description", $description);
94 //save the relationship
95 //$this->click("_qf_Relationship_upload");
96 $this->click("quick-save");
97 $this->waitForElementPresent("current-relationships");
99 //check the status message
100 $this->assertTrue($this->isTextPresent("New relationship created."));
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']");
105 $this->waitForPageToLoad($this->getTimeoutMsec());
106 $this->webtestVerifyTabularData(
108 'Description' => $description,
109 'Status' => 'Enabled',
113 $this->assertTrue($this->isTextPresent($params['label_b_a']));
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());
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";
136 $this->click("_qf_Contact_upload_view");
137 $this->waitForElementPresent("css=.crm-contact-tabs-list");
139 //create a New household subtype
140 $this->open($this->sboxPath
. "civicrm/admin/options/subtype?action=add&reset=1");
141 $this->waitForPageToLoad($this->getTimeoutMsec());
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());
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');
156 //fill in Household name
157 $householdName = substr(sha1(rand()), 0, 4) . 'home';
158 $this->click("household_name");
159 $this->type("household_name", $householdName);
162 $this->click("_qf_Contact_upload_view");
163 $this->waitForPageToLoad($this->getTimeoutMsec());
165 //choose the created relationship type
166 $this->click('css=li#tab_rel a');
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']}");
174 //fill in the individual
175 $this->webtestFillAutocomplete($sortName);
177 $this->waitForElementPresent("quick-save");
179 //fill in the relationship start date
180 $this->webtestFillDate('start_date', '-2 year');
181 $this->webtestFillDate('end_date', '+1 year');
183 $description = "Well here is some description !!!!";
184 $this->type("description", $description);
186 //save the relationship
187 $this->click("quick-save");
188 $this->waitForElementPresent("current-relationships");
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']");
193 $this->waitForPageToLoad($this->getTimeoutMsec());
194 $this->webtestVerifyTabularData(
196 'Description' => $description,
197 'Status' => 'Enabled',
201 $this->assertTrue($this->isTextPresent($params['label_b_a']));
203 //test for individual contact and household subtype contact
205 $typeb = "Household" . CRM_Core_DAO
::VALUE_SEPARATOR
. $householdSubtypeName;
207 //create a relationship type between different contact types
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',
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']);
224 $params['contact_type_b'] = preg_replace('/' . CRM_Core_DAO
::VALUE_SEPARATOR
. '/', ' - ', $params['contact_type_b']);
227 $this->click('_qf_RelationshipType_next-bottom');
228 $this->waitForPageToLoad($this->getTimeoutMsec());
231 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
232 "Status message didn't show up after saving!"
235 $this->open($this->sboxPath
. 'civicrm/admin/reltype?reset=1');
236 $this->waitForPageToLoad($this->getTimeoutMsec());
238 //validate data on selector.
240 if (isset($data['description'])) {
241 unset($data['description']);
243 $this->assertStringsPresent($data);
245 //create a New Individual
246 $firstName = substr(sha1(rand()), 0, 7);
247 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
248 $sortName = "Anderson, $firstName";
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');
254 //fill in Household name
255 $householdName = substr(sha1(rand()), 0, 4) . 'home';
256 $this->click("household_name");
257 $this->type("household_name", $householdName);
260 $this->click("_qf_Contact_upload_view");
261 $this->waitForPageToLoad($this->getTimeoutMsec());
263 //choose the created relationship type
264 $this->click('css=li#tab_rel a');
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']}");
272 //fill in the individual
273 $this->webtestFillAutocomplete($sortName);
275 $this->waitForElementPresent("quick-save");
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);
283 //save the relationship
284 $this->click("quick-save");
285 $this->waitForElementPresent("current-relationships");
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']");
290 $this->waitForPageToLoad($this->getTimeoutMsec());
291 $this->webtestVerifyTabularData(
293 'Description' => $description,
294 'Status' => 'Enabled',
298 $this->assertTrue($this->isTextPresent($params['label_b_a']));
301 function testRelationshipAddNewIndividualTest() {
302 $this->webtestLogin();
304 //create a relationship type between different contact types
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.',
313 $this->webtestAddRelationshipType($params);
315 //create a New Individual
316 $firstName = substr(sha1(rand()), 0, 7);
317 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
319 // visit relationship tab of the Individual
320 $this->click("css=li#tab_rel a");
322 // wait for add Relationship link
323 $this->waitForElementPresent('link=Add Relationship');
324 $this->click('link=Add Relationship');
326 //choose the created relationship type
327 $this->waitForElementPresent("relationship_type_id");
328 $this->select('relationship_type_id', "label={$params['label_a_b']}");
330 //wait untill new contact dialog select is built
333 // create a new organization
334 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
335 $this->webtestNewDialogContact($orgName, "", "info@" . $orgName . ".com", 5);
337 $this->waitForElementPresent("quick-save");
339 //fill in the relationship start date
340 $this->webtestFillDate('start_date', '-2 year');
341 $this->webtestFillDate('end_date', '+1 year');
343 $description = "Long-standing board member.";
344 $this->type("description", $description);
346 //save the relationship
347 //$this->click("_qf_Relationship_upload");
348 $this->click("quick-save");
349 $this->waitForElementPresent("current-relationships");
351 //check the status message
352 $this->assertTrue($this->isTextPresent("New relationship created."));
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']");
357 $this->waitForPageToLoad($this->getTimeoutMsec());
358 $this->webtestVerifyTabularData(
360 'Description' => $description,
361 'Status' => 'Enabled',
364 $this->assertTrue($this->isTextPresent($params['label_a_b']));