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 +--------------------------------------------------------------------+
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->webtestFillAutocomplete($sortName);
78 $this->waitForElementPresent("quick-save");
80 //fill in the relationship start date
81 $this->webtestFillDate('start_date', '-2 year');
82 $this->webtestFillDate('end_date', '+1 year');
84 $description = "Well here is some description !!!!";
85 $this->type("description", $description);
87 //save the relationship
88 //$this->click("_qf_Relationship_upload");
89 $this->click("quick-save");
90 $this->waitForElementPresent("current-relationships");
92 //check the status message
93 $this->assertTrue($this->isTextPresent("New relationship created."));
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']");
98 $this->waitForPageToLoad($this->getTimeoutMsec());
99 $this->webtestVerifyTabularData(
101 'Description' => $description,
102 'Status' => 'Enabled',
106 $this->assertTrue($this->isTextPresent($params['label_b_a']));
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());
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";
127 $this->click("_qf_Contact_upload_view");
128 $this->waitForElementPresent("css=.crm-contact-tabs-list");
130 //create a New household subtype
131 $this->openCiviPage("admin/options/subtype", "action=add&reset=1");
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());
142 //create a new contact of household subtype
143 $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view');
145 //fill in Household name
146 $householdName = substr(sha1(rand()), 0, 4) . 'home';
147 $this->click("household_name");
148 $this->type("household_name", $householdName);
151 $this->click("_qf_Contact_upload_view");
152 $this->waitForPageToLoad($this->getTimeoutMsec());
154 //choose the created relationship type
155 $this->click('css=li#tab_rel a');
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']}");
163 //fill in the individual
164 $this->webtestFillAutocomplete($sortName);
166 $this->waitForElementPresent("quick-save");
168 //fill in the relationship start date
169 $this->webtestFillDate('start_date', '-2 year');
170 $this->webtestFillDate('end_date', '+1 year');
172 $description = "Well here is some description !!!!";
173 $this->type("description", $description);
175 //save the relationship
176 $this->click("quick-save");
177 $this->waitForElementPresent("current-relationships");
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']");
182 $this->waitForPageToLoad($this->getTimeoutMsec());
183 $this->webtestVerifyTabularData(
185 'Description' => $description,
186 'Status' => 'Enabled',
190 $this->assertTrue($this->isTextPresent($params['label_b_a']));
192 //test for individual contact and household subtype contact
194 $typeb = "Household" . CRM_Core_DAO
::VALUE_SEPARATOR
. $householdSubtypeName;
196 //create a relationship type between different contact types
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',
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']);
213 $params['contact_type_b'] = preg_replace('/' . CRM_Core_DAO
::VALUE_SEPARATOR
. '/', ' - ', $params['contact_type_b']);
216 $this->click('_qf_RelationshipType_next-bottom');
217 $this->waitForPageToLoad($this->getTimeoutMsec());
220 $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'),
221 "Status message didn't show up after saving!"
224 $this->openCiviPage("admin/reltype", "reset=1");
226 //validate data on selector.
228 if (isset($data['description'])) {
229 unset($data['description']);
231 $this->assertStringsPresent($data);
233 //create a New Individual
234 $firstName = substr(sha1(rand()), 0, 7);
235 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
236 $sortName = "Anderson, $firstName";
238 //create a new contact of household subtype
239 $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view');
241 //fill in Household name
242 $householdName = substr(sha1(rand()), 0, 4) . 'home';
243 $this->click("household_name");
244 $this->type("household_name", $householdName);
247 $this->click("_qf_Contact_upload_view");
248 $this->waitForPageToLoad($this->getTimeoutMsec());
250 //choose the created relationship type
251 $this->click('css=li#tab_rel a');
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']}");
259 //fill in the individual
260 $this->webtestFillAutocomplete($sortName);
262 $this->waitForElementPresent("quick-save");
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);
270 //save the relationship
271 $this->click("quick-save");
272 $this->waitForElementPresent("current-relationships");
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']");
277 $this->waitForPageToLoad($this->getTimeoutMsec());
278 $this->webtestVerifyTabularData(
280 'Description' => $description,
281 'Status' => 'Enabled',
285 $this->assertTrue($this->isTextPresent($params['label_b_a']));
288 function testRelationshipAddNewIndividualTest() {
289 $this->webtestLogin();
291 //create a relationship type between different contact types
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.',
300 $this->webtestAddRelationshipType($params);
302 //create a New Individual
303 $firstName = substr(sha1(rand()), 0, 7);
304 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
306 // visit relationship tab of the Individual
307 $this->click("css=li#tab_rel a");
309 // wait for add Relationship link
310 $this->waitForElementPresent('link=Add Relationship');
311 $this->click('link=Add Relationship');
313 //choose the created relationship type
314 $this->waitForElementPresent("relationship_type_id");
315 $this->select('relationship_type_id', "label={$params['label_a_b']}");
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
322 // create a new organization
323 $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7);
324 $this->webtestNewDialogContact($orgName, "", "info@" . $orgName . ".com", 5);
326 $this->waitForElementPresent("quick-save");
328 //fill in the relationship start date
329 $this->webtestFillDate('start_date', '-2 year');
330 $this->webtestFillDate('end_date', '+1 year');
332 $description = "Long-standing board member.";
333 $this->type("description", $description);
335 //save the relationship
336 //$this->click("_qf_Relationship_upload");
337 $this->click("quick-save");
338 $this->waitForElementPresent("current-relationships");
340 //check the status message
341 $this->assertTrue($this->isTextPresent("New relationship created."));
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']");
346 $this->waitForPageToLoad($this->getTimeoutMsec());
347 $this->webtestVerifyTabularData(
349 'Description' => $description,
350 'Status' => 'Enabled',
353 $this->assertTrue($this->isTextPresent($params['label_a_b']));