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