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