Merge pull request #71 from dpradeep/merge-20140930
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvancedSearchedRelatedContactTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
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 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_AdvancedSearchedRelatedContactTest
31 */
6a488035
TO
32class WebTest_Contact_AdvancedSearchedRelatedContactTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testSearchRelatedContact() {
6a488035
TO
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
c3ad8633
CW
42 // Use default payment processor
43 $processorName = 'Test Processor';
6a488035
TO
44 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
45
79d6583c 46 $this->openCiviPage('event/add', 'reset=1&action=add');
6a488035
TO
47
48 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
49 $eventDescription = "Here is a description for this conference.";
50 $this->_testAddEventInfo($eventTitle, $eventDescription);
51
52 $streetAddress = "100 Main Street";
53 $this->_testAddLocation($streetAddress);
54
55 $this->_testAddFees(FALSE, FALSE, $paymentProcessorId);
79d6583c 56 $this->openCiviPage('event/manage', 'reset=1');
6a488035
TO
57 $this->type('title', $eventTitle);
58 $this->click('_qf_SearchEvent_refresh');
59 $this->waitForPageToLoad($this->getTimeoutMsec());
6acc185a 60 $Id = explode('-', $this->getAttribute("xpath=//div[@id='event_status_id']/div[2]/table/tbody/tr@id"));
6a488035
TO
61 $eventId = $Id[1];
62
63 $params = array('label_a_b' => 'Owner of ' . rand(),
64 'label_b_a' => 'Belongs to ' . rand(),
65 'contact_type_a' => 'Individual',
66 'contact_type_b' => 'Individual',
67 'description' => 'The company belongs to this individual',
68 );
69
70 $this->webtestAddRelationshipType($params);
71 $relType = $params['label_b_a'];
72
73 $firstName = substr(sha1(rand()), 0, 7);
74 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
75 $sortName = "Anderson, $firstName";
76 $displayName = "$firstName Anderson";
77
78 //create a New Individual
79 $firstName1 = substr(sha1(rand()), 0, 7);
80 $this->webtestAddContact($firstName1, "Andy", "$firstName1@andy.name");
81 $sortName1 = "Andy, $firstName1";
82 $displayName1 = "$firstName1 Andy";
83 $this->_testAddRelationship($sortName1, $sortName, $relType);
84
85 $firstName2 = substr(sha1(rand()), 0, 7);
86 $this->webtestAddContact($firstName2, "David", "$firstName2@andy.name");
87 $sortName2 = "David, $firstName2";
88 $displayName2 = "$firstName2 David";
89 $this->_testAddRelationship($sortName2, $sortName, $relType);
90
79d6583c 91 $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
6a488035
TO
92 $this->type("sort_name", $sortName);
93 $this->select("contact_type", "value=Individual");
225a8648 94 $this->clickLink("_qf_Basic_refresh", "xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/");
6a488035
TO
95
96 // click through to the Relationship view screen
97 $this->click("xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/td[11]/span/a[text()='View']");
98 $this->waitForPageToLoad($this->getTimeoutMsec());
99 $this->click("css=li#tab_participant a");
100
101 // wait for add Event link
102 $this->waitForElementPresent("link=Add Event Registration");
103 $this->click("link=Add Event Registration");
6acc185a 104 $this->waitForText("s2id_event_id", "- select event -");
105 $this->select2("event_id", $eventTitle);
6a488035 106 $this->click("_qf_Participant_upload-bottom");
6acc185a 107 $this->waitForElementPresent("link=Add Event Registration");
6a488035 108
79d6583c 109 $this->openCiviPage('contact/search/advanced', 'reset=1');
6a488035
TO
110
111 $this->type("sort_name", $sortName);
112 $this->click('_qf_Advanced_refresh');
113 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
114
d84aa55c 115 $this->waitForElementPresent('search-status');
79d6583c 116 $this->assertElementContainsText('search-status', '1 Contact');
6a488035
TO
117
118 $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header');
119 $this->select("component_mode", "label=Related Contacts");
120 $this->select("display_relationship_type", $relType);
121 $this->click('_qf_Advanced_refresh');
122 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
123
d84aa55c 124 $this->waitForElementPresent('search-status');
79d6583c 125 $this->assertElementContainsText('search-status', '2 Contact');
6a488035
TO
126
127 $this->select("task", "label=Add Contacts to Group");
128
6a488035
TO
129 $this->waitForPageToLoad($this->getTimeoutMsec());
130
131 $this->click('CIVICRM_QFID_1_group_option');
132
133 $groupName = "Group " . substr(sha1(rand()), 0, 7);
134 $this->type('title', $groupName);
135
136 $this->click("_qf_AddToGroup_next-bottom");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138
6c5f7368
CW
139 $this->waitForText('crm-notification-container', "Added Contacts to ".$groupName);
140 $this->waitForText('crm-notification-container', '2 contacts added to group');
6a488035
TO
141 $this->_testSearchResult($relType);
142 }
143
4cbe18b8
EM
144 /**
145 * @param $eventTitle
146 * @param $eventDescription
147 */
6a488035 148 function _testAddEventInfo($eventTitle, $eventDescription) {
6a488035
TO
149 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
150
6a488035
TO
151 $this->select("event_type_id", "value=1");
152
153 // Attendee role s/b selected now.
154 $this->select("default_role_id", "value=1");
155
156 // Enter Event Title, Summary and Description
157 $this->type("title", $eventTitle);
158 $this->type("summary", "This is a great conference. Sign up now!");
159
160 // Type description in ckEditor (fieldname, text to type, editor)
161 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
162
163 // Choose Start and End dates.
164 // Using helper webtestFillDate function.
165 $this->webtestFillDateTime("start_date", "+1 week");
166 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
167
168 $this->type("max_participants", "50");
169 $this->click("is_map");
170 $this->click("_qf_EventInfo_upload-bottom");
171 }
172
4cbe18b8
EM
173 /**
174 * @param $streetAddress
175 */
6a488035
TO
176 function _testAddLocation($streetAddress) {
177 // Wait for Location tab form to load
178 $this->waitForPageToLoad($this->getTimeoutMsec());
179 $this->waitForElementPresent("_qf_Location_upload-bottom");
180
181 // Fill in address fields
182 $streetAddress = "100 Main Street";
183 $this->type("address_1_street_address", $streetAddress);
184 $this->type("address_1_city", "San Francisco");
185 $this->type("address_1_postal_code", "94117");
3e60ff7f 186 $this->select('address_1_country_id', 'United States');
6a488035
TO
187 $this->select("address_1_state_province_id", "value=1004");
188 $this->type("email_1_email", "info@civicrm.org");
189
190 $this->click("_qf_Location_upload-bottom");
191
192 // Wait for "saved" status msg
6acc185a 193 $this->waitForElementPresent("_qf_Location_upload-bottom");
194 $this->waitForText('crm-notification-container', "'Event Location' information has been saved.");
6a488035
TO
195 }
196
4cbe18b8
EM
197 /**
198 * @param bool $discount
199 * @param bool $priceSet
200 * @param $processorId
201 */
6a488035
TO
202 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
203 // Go to Fees tab
204 $this->click("link=Fees");
205 $this->waitForElementPresent("_qf_Fee_upload-bottom");
206 $this->click("CIVICRM_QFID_1_is_monetary");
207 $this->check("payment_processor[{$processorId}]");
79d6583c 208 $this->select("financial_type_id", "value=4");
6a488035
TO
209 if ($priceSet) {
210 // get one - TBD
211 }
212 else {
213 $this->type("label_1", "Member");
214 $this->type("value_1", "250.00");
215 $this->type("label_2", "Non-member");
216 $this->type("value_2", "325.00");
217 //set default
218 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
219 }
220
221 if ($discount) {
222 // enter early bird discounts TBD
223 }
224
225 $this->click("_qf_Fee_upload-bottom");
226
227 // Wait for "saved" status msg
6acc185a 228 $this->waitForElementPresent("_qf_Fee_upload-bottom");
229 $this->waitForTextPresent("'Fees' information has been saved.");
6a488035
TO
230 }
231
4cbe18b8
EM
232 /**
233 * @param $ContactName
234 * @param $relatedName
235 * @param $relType
236 */
6a488035
TO
237 function _testAddRelationship($ContactName, $relatedName, $relType) {
238
79d6583c 239 $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh');
6a488035
TO
240 $this->type("sort_name", $ContactName);
241 $this->select("contact_type", "value=Individual");
225a8648 242 $this->clickLink("_qf_Basic_refresh", "xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/");
6a488035
TO
243
244 // click through to the Contribution view screen
245 $this->click("xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/td[11]/span/a[text()='View']");
246 $this->waitForPageToLoad($this->getTimeoutMsec());
247
248 $this->click("css=li#tab_rel a");
249
250 // wait for add Relationship link
251 $this->waitForElementPresent('link=Add Relationship');
252 $this->click('link=Add Relationship');
253
254 //choose the created relationship type
255 $this->waitForElementPresent("relationship_type_id");
256 $this->select('relationship_type_id', "label={$relType}");
257
258 //fill in the individual
6acc185a 259 $this->select2('related_contact_id', $relatedName, 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
265 $description = "Well here is some description !!!!";
266 $this->type("description", $description);
267
268 //save the relationship
269 //$this->click("_qf_Relationship_upload");
6acc185a 270 $this->click('_qf_Relationship_upload-bottom');
3e60ff7f 271 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']");
6a488035
TO
272
273 //check the status message
6acc185a 274 $this->waitForText('crm-notification-container', "Relationship created.");
6a488035 275
3e60ff7f
JP
276 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody//tr/td[9]/span/a[text()='View']");
277 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody//tr/td[9]/span/a[text()='View']");
6a488035 278
6acc185a 279 $this->waitForElementPresent("xpath=//table[@class='crm-info-panel']");
6a488035
TO
280 $this->webtestVerifyTabularData(
281 array(
282 'Description' => $description,
283 'Status' => 'Enabled',
284 )
285 );
6acc185a 286 $this->assertElementContainsText("xpath=//table[@class='crm-info-panel']", $relType);
6a488035
TO
287 }
288
4cbe18b8
EM
289 /**
290 * @param $relType
291 */
6a488035
TO
292 function _testSearchResult($relType) {
293
294 //search related contact using Advanced Search
79d6583c 295 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
6a488035
TO
296 $this->select("component_mode", "label=Related Contacts");
297 $this->select("display_relationship_type", "label={$relType}");
298 $this->click("CiviEvent");
6acc185a 299 $this->waitForElementPresent("event_type_id");
300 $this->select2("event_type_id", "Conference");
6a488035
TO
301 $this->click("_qf_Advanced_refresh");
302 $this->waitForPageToLoad($this->getTimeoutMsec());
d84aa55c 303 $this->waitForElementPresent('search-status');
79d6583c 304 $this->assertElementContainsText('search-status', '2 Contacts');
6a488035
TO
305 }
306
307 function testAdvanceSearchForLog() {
6a488035 308 $this->webtestLogin();
76e86fd8 309
6a488035
TO
310 $Pdate = date('F jS, Y h:i:s A', mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 1, date( 'Y' )) );
311 $Ndate = date('F jS, Y h:i:s A', mktime( 0, 0, 0, date( 'm' ), date( 'd' ) + 1, date( 'Y' )) );
312
313 //create a contact and return the contact id
314 $firstNameSoft = "John_".substr(sha1(rand()), 0, 5);
315 $lastNameSoft = "Doe_".substr(sha1(rand()), 0, 5);
316 $this->webtestAddContact( $firstNameSoft, $lastNameSoft );
a471a3b6 317 $cid = $this->urlArg('cid');
6a488035
TO
318
319 //advance search for created contacts
79d6583c 320 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
6a488035
TO
321 $this->type('sort_name', $lastNameSoft.', '.$firstNameSoft);
322 $this->click('changeLog');
323 $this->waitForElementPresent("log_date_low");
324 $this->select("log_date_relative","value=0");
325 $this->webtestFillDate('log_date_low', "-1 day");
326 $this->webtestFillDate('log_date_high', "+1 day");
327 $this->click('_qf_Advanced_refresh');
328 $this->waitForPageToLoad($this->getTimeoutMsec());
329 $this->assertTrue(True, 'greater than or equal to "{$Pdate}" AND less than or equal to "{$Ndate}"');
330 $value = "$lastNameSoft, $firstNameSoft";
331 $this->verifyText("xpath= id('rowid{$cid}')/td[3]/a", preg_quote($value));
6a488035 332
76e86fd8 333}
6a488035
TO
334
335}
336