Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_AdvancedSearchedRelatedContactTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_AdvancedSearchedRelatedContactTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public 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 | ||
b9fdba0a | 55 | $this->_testAddFees(FALSE, FALSE, $processorName); |
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 | ||
6c6e6187 | 63 | $params = array( |
92915c55 | 64 | 'label_a_b' => 'Owner of ' . rand(), |
6a488035 TO |
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 | ||
79d6583c | 92 | $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh'); |
6a488035 TO |
93 | $this->type("sort_name", $sortName); |
94 | $this->select("contact_type", "value=Individual"); | |
751132dd | 95 | $this->clickLink("_qf_Basic_refresh", "//table[@class='selector row-highlight']/tbody//tr/td[11]/span/a[text()='View']", FALSE); |
6a488035 TO |
96 | |
97 | // click through to the Relationship view screen | |
33c81040 | 98 | $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[11]/span/a[text()='View']"); |
6a488035 TO |
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"); | |
6acc185a | 105 | $this->waitForText("s2id_event_id", "- select event -"); |
106 | $this->select2("event_id", $eventTitle); | |
6a488035 | 107 | $this->click("_qf_Participant_upload-bottom"); |
6acc185a | 108 | $this->waitForElementPresent("link=Add Event Registration"); |
6a488035 | 109 | |
79d6583c | 110 | $this->openCiviPage('contact/search/advanced', 'reset=1'); |
6a488035 | 111 | |
2815a5aa | 112 | $this->waitForElementPresent("sort_name"); |
6a488035 TO |
113 | $this->type("sort_name", $sortName); |
114 | $this->click('_qf_Advanced_refresh'); | |
115 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
116 | ||
d84aa55c | 117 | $this->waitForElementPresent('search-status'); |
79d6583c | 118 | $this->assertElementContainsText('search-status', '1 Contact'); |
6a488035 TO |
119 | |
120 | $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header'); | |
2815a5aa | 121 | $this->waitForElementPresent("component_mode"); |
6a488035 | 122 | $this->select("component_mode", "label=Related Contacts"); |
2815a5aa | 123 | $this->waitForElementPresent("display_relationship_type"); |
6a488035 TO |
124 | $this->select("display_relationship_type", $relType); |
125 | $this->click('_qf_Advanced_refresh'); | |
126 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
127 | ||
d84aa55c | 128 | $this->waitForElementPresent('search-status'); |
79d6583c | 129 | $this->assertElementContainsText('search-status', '2 Contact'); |
6a488035 | 130 | |
7f82e636 | 131 | $this->select("task", "label=Group - add contacts"); |
6a488035 | 132 | |
6a488035 TO |
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 | ||
92fcb95f | 143 | $this->waitForText('crm-notification-container', "Added Contacts to " . $groupName); |
6c5f7368 | 144 | $this->waitForText('crm-notification-container', '2 contacts added to group'); |
6a488035 TO |
145 | $this->_testSearchResult($relType); |
146 | } | |
147 | ||
4cbe18b8 EM |
148 | /** |
149 | * @param $eventTitle | |
150 | * @param $eventDescription | |
151 | */ | |
00be9182 | 152 | public function _testAddEventInfo($eventTitle, $eventDescription) { |
6a488035 TO |
153 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
154 | ||
6a488035 | 155 | $this->select("event_type_id", "value=1"); |
4ea7e2aa | 156 | $this->waitForAjaxContent(); |
6a488035 TO |
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 | ||
4cbe18b8 EM |
178 | /** |
179 | * @param $streetAddress | |
180 | */ | |
00be9182 | 181 | public function _testAddLocation($streetAddress) { |
6a488035 TO |
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"); | |
86797006 | 191 | $this->select('address_1_country_id', 'UNITED STATES'); |
4ea7e2aa | 192 | $this->waitForAjaxContent(); |
6a488035 TO |
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 | |
6acc185a | 199 | $this->waitForElementPresent("_qf_Location_upload-bottom"); |
200 | $this->waitForText('crm-notification-container', "'Event Location' information has been saved."); | |
6a488035 TO |
201 | } |
202 | ||
4cbe18b8 EM |
203 | /** |
204 | * @param bool $discount | |
205 | * @param bool $priceSet | |
ff5aacbe | 206 | * @param int|array $processorIDs |
4cbe18b8 | 207 | */ |
6e677443 | 208 | public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorIDs) { |
6a488035 TO |
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"); | |
6e677443 | 213 | $this->select2('payment_processor', $processorIDs, TRUE); |
79d6583c | 214 | $this->select("financial_type_id", "value=4"); |
6a488035 TO |
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 | |
6acc185a | 234 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
235 | $this->waitForTextPresent("'Fees' information has been saved."); | |
6a488035 TO |
236 | } |
237 | ||
4cbe18b8 | 238 | /** |
100fef9d CW |
239 | * @param string $ContactName |
240 | * @param string $relatedName | |
4cbe18b8 EM |
241 | * @param $relType |
242 | */ | |
00be9182 | 243 | public function _testAddRelationship($ContactName, $relatedName, $relType) { |
6a488035 | 244 | |
79d6583c | 245 | $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh'); |
6a488035 TO |
246 | $this->type("sort_name", $ContactName); |
247 | $this->select("contact_type", "value=Individual"); | |
5009a032 | 248 | $this->clickLink("_qf_Basic_refresh", "//div[@class='crm-search-results']/table[@class='selector row-highlight']/tbody/tr/", FALSE); |
6a488035 TO |
249 | |
250 | // click through to the Contribution view screen | |
4ea7e2aa | 251 | $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[11]//span/a[text()='View']"); |
6a488035 TO |
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 | |
ca0cdd20 | 265 | $this->waitForElementPresent("related_contact_id"); |
6acc185a | 266 | $this->select2('related_contact_id', $relatedName, TRUE); |
6a488035 TO |
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"); | |
6acc185a | 277 | $this->click('_qf_Relationship_upload-bottom'); |
3e60ff7f | 278 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']"); |
6a488035 TO |
279 | |
280 | //check the status message | |
6acc185a | 281 | $this->waitForText('crm-notification-container', "Relationship created."); |
1fd662d2 WA |
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']"); | |
6a488035 | 284 | |
6acc185a | 285 | $this->waitForElementPresent("xpath=//table[@class='crm-info-panel']"); |
6a488035 TO |
286 | $this->webtestVerifyTabularData( |
287 | array( | |
288 | 'Description' => $description, | |
289 | 'Status' => 'Enabled', | |
290 | ) | |
291 | ); | |
6acc185a | 292 | $this->assertElementContainsText("xpath=//table[@class='crm-info-panel']", $relType); |
6a488035 TO |
293 | } |
294 | ||
4cbe18b8 EM |
295 | /** |
296 | * @param $relType | |
297 | */ | |
00be9182 | 298 | public function _testSearchResult($relType) { |
6a488035 TO |
299 | |
300 | //search related contact using Advanced Search | |
79d6583c | 301 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
6a488035 TO |
302 | $this->select("component_mode", "label=Related Contacts"); |
303 | $this->select("display_relationship_type", "label={$relType}"); | |
304 | $this->click("CiviEvent"); | |
6acc185a | 305 | $this->waitForElementPresent("event_type_id"); |
306 | $this->select2("event_type_id", "Conference"); | |
6a488035 | 307 | $this->click("_qf_Advanced_refresh"); |
4dc8abb7 | 308 | $this->waitForElementPresent("xpath=//div[@class='crm-content-block']//div[@id='search-status']"); |
4ea7e2aa | 309 | $this->assertElementContainsText("xpath=//div[@id='search-status']/table/tbody/tr[1]/td[1]", "2 Contacts"); |
6a488035 TO |
310 | } |
311 | ||
6c6e6187 | 312 | public function testAdvanceSearchForLog() { |
6a488035 | 313 | $this->webtestLogin(); |
76e86fd8 | 314 | |
92915c55 TO |
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'))); | |
6a488035 TO |
317 | |
318 | //create a contact and return the contact id | |
92fcb95f | 319 | $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5); |
92915c55 | 320 | $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5); |
481a74f4 | 321 | $this->webtestAddContact($firstNameSoft, $lastNameSoft); |
a471a3b6 | 322 | $cid = $this->urlArg('cid'); |
6a488035 TO |
323 | |
324 | //advance search for created contacts | |
79d6583c | 325 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
92fcb95f | 326 | $this->type('sort_name', $lastNameSoft . ', ' . $firstNameSoft); |
6a488035 TO |
327 | $this->click('changeLog'); |
328 | $this->waitForElementPresent("log_date_low"); | |
6c6e6187 | 329 | $this->select("log_date_relative", "value=0"); |
6a488035 TO |
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()); | |
6c6e6187 | 334 | $this->assertTrue(TRUE, 'greater than or equal to "{$Pdate}" AND less than or equal to "{$Ndate}"'); |
6a488035 | 335 | $value = "$lastNameSoft, $firstNameSoft"; |
fb93fc39 | 336 | $this->waitForElementPresent("xpath= id('rowid{$cid}')/td[3]/a"); |
6a488035 | 337 | $this->verifyText("xpath= id('rowid{$cid}')/td[3]/a", preg_quote($value)); |
6a488035 | 338 | |
6c6e6187 | 339 | } |
6a488035 TO |
340 | |
341 | } |