Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | ||
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 | ||
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"); | |
05e39ac3 | 95 | $this->clickLink("_qf_Basic_refresh", "xpath=//form[@id='Basic']//div/div//div/table/tbody/tr/"); |
6a488035 TO |
96 | |
97 | // click through to the Relationship view screen | |
05e39ac3 | 98 | $this->click("xpath=//form[@id='Basic']//div/div//div/table/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 TO |
111 | |
112 | $this->type("sort_name", $sortName); | |
113 | $this->click('_qf_Advanced_refresh'); | |
114 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
115 | ||
d84aa55c | 116 | $this->waitForElementPresent('search-status'); |
79d6583c | 117 | $this->assertElementContainsText('search-status', '1 Contact'); |
6a488035 TO |
118 | |
119 | $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header'); | |
120 | $this->select("component_mode", "label=Related Contacts"); | |
121 | $this->select("display_relationship_type", $relType); | |
122 | $this->click('_qf_Advanced_refresh'); | |
123 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
124 | ||
d84aa55c | 125 | $this->waitForElementPresent('search-status'); |
79d6583c | 126 | $this->assertElementContainsText('search-status', '2 Contact'); |
6a488035 TO |
127 | |
128 | $this->select("task", "label=Add Contacts to Group"); | |
129 | ||
6a488035 TO |
130 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
131 | ||
132 | $this->click('CIVICRM_QFID_1_group_option'); | |
133 | ||
134 | $groupName = "Group " . substr(sha1(rand()), 0, 7); | |
135 | $this->type('title', $groupName); | |
136 | ||
137 | $this->click("_qf_AddToGroup_next-bottom"); | |
138 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
139 | ||
92fcb95f | 140 | $this->waitForText('crm-notification-container', "Added Contacts to " . $groupName); |
6c5f7368 | 141 | $this->waitForText('crm-notification-container', '2 contacts added to group'); |
6a488035 TO |
142 | $this->_testSearchResult($relType); |
143 | } | |
144 | ||
4cbe18b8 EM |
145 | /** |
146 | * @param $eventTitle | |
147 | * @param $eventDescription | |
148 | */ | |
00be9182 | 149 | public function _testAddEventInfo($eventTitle, $eventDescription) { |
6a488035 TO |
150 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
151 | ||
6a488035 TO |
152 | $this->select("event_type_id", "value=1"); |
153 | ||
154 | // Attendee role s/b selected now. | |
155 | $this->select("default_role_id", "value=1"); | |
156 | ||
157 | // Enter Event Title, Summary and Description | |
158 | $this->type("title", $eventTitle); | |
159 | $this->type("summary", "This is a great conference. Sign up now!"); | |
160 | ||
161 | // Type description in ckEditor (fieldname, text to type, editor) | |
162 | $this->fillRichTextField("description", $eventDescription, 'CKEditor'); | |
163 | ||
164 | // Choose Start and End dates. | |
165 | // Using helper webtestFillDate function. | |
166 | $this->webtestFillDateTime("start_date", "+1 week"); | |
167 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
168 | ||
169 | $this->type("max_participants", "50"); | |
170 | $this->click("is_map"); | |
171 | $this->click("_qf_EventInfo_upload-bottom"); | |
172 | } | |
173 | ||
4cbe18b8 EM |
174 | /** |
175 | * @param $streetAddress | |
176 | */ | |
00be9182 | 177 | public function _testAddLocation($streetAddress) { |
6a488035 TO |
178 | // Wait for Location tab form to load |
179 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
180 | $this->waitForElementPresent("_qf_Location_upload-bottom"); | |
181 | ||
182 | // Fill in address fields | |
183 | $streetAddress = "100 Main Street"; | |
184 | $this->type("address_1_street_address", $streetAddress); | |
185 | $this->type("address_1_city", "San Francisco"); | |
186 | $this->type("address_1_postal_code", "94117"); | |
86797006 | 187 | $this->select('address_1_country_id', 'UNITED STATES'); |
6a488035 TO |
188 | $this->select("address_1_state_province_id", "value=1004"); |
189 | $this->type("email_1_email", "info@civicrm.org"); | |
190 | ||
191 | $this->click("_qf_Location_upload-bottom"); | |
192 | ||
193 | // Wait for "saved" status msg | |
6acc185a | 194 | $this->waitForElementPresent("_qf_Location_upload-bottom"); |
195 | $this->waitForText('crm-notification-container', "'Event Location' information has been saved."); | |
6a488035 TO |
196 | } |
197 | ||
4cbe18b8 EM |
198 | /** |
199 | * @param bool $discount | |
200 | * @param bool $priceSet | |
100fef9d | 201 | * @param int $processorId |
4cbe18b8 | 202 | */ |
00be9182 | 203 | public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) { |
6a488035 TO |
204 | // Go to Fees tab |
205 | $this->click("link=Fees"); | |
206 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); | |
207 | $this->click("CIVICRM_QFID_1_is_monetary"); | |
208 | $this->check("payment_processor[{$processorId}]"); | |
79d6583c | 209 | $this->select("financial_type_id", "value=4"); |
6a488035 TO |
210 | if ($priceSet) { |
211 | // get one - TBD | |
212 | } | |
213 | else { | |
214 | $this->type("label_1", "Member"); | |
215 | $this->type("value_1", "250.00"); | |
216 | $this->type("label_2", "Non-member"); | |
217 | $this->type("value_2", "325.00"); | |
218 | //set default | |
219 | $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input"); | |
220 | } | |
221 | ||
222 | if ($discount) { | |
223 | // enter early bird discounts TBD | |
224 | } | |
225 | ||
226 | $this->click("_qf_Fee_upload-bottom"); | |
227 | ||
228 | // Wait for "saved" status msg | |
6acc185a | 229 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
230 | $this->waitForTextPresent("'Fees' information has been saved."); | |
6a488035 TO |
231 | } |
232 | ||
4cbe18b8 | 233 | /** |
100fef9d CW |
234 | * @param string $ContactName |
235 | * @param string $relatedName | |
4cbe18b8 EM |
236 | * @param $relType |
237 | */ | |
00be9182 | 238 | public function _testAddRelationship($ContactName, $relatedName, $relType) { |
6a488035 | 239 | |
79d6583c | 240 | $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh'); |
6a488035 TO |
241 | $this->type("sort_name", $ContactName); |
242 | $this->select("contact_type", "value=Individual"); | |
225a8648 | 243 | $this->clickLink("_qf_Basic_refresh", "xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/"); |
6a488035 TO |
244 | |
245 | // click through to the Contribution view screen | |
246 | $this->click("xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/td[11]/span/a[text()='View']"); | |
247 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
248 | ||
249 | $this->click("css=li#tab_rel a"); | |
250 | ||
251 | // wait for add Relationship link | |
252 | $this->waitForElementPresent('link=Add Relationship'); | |
253 | $this->click('link=Add Relationship'); | |
254 | ||
255 | //choose the created relationship type | |
256 | $this->waitForElementPresent("relationship_type_id"); | |
257 | $this->select('relationship_type_id', "label={$relType}"); | |
258 | ||
259 | //fill in the individual | |
ca0cdd20 | 260 | $this->waitForElementPresent("related_contact_id"); |
6acc185a | 261 | $this->select2('related_contact_id', $relatedName, TRUE); |
6a488035 TO |
262 | |
263 | //fill in the relationship start date | |
264 | $this->webtestFillDate('start_date', '-2 year'); | |
265 | $this->webtestFillDate('end_date', '+1 year'); | |
266 | ||
267 | $description = "Well here is some description !!!!"; | |
268 | $this->type("description", $description); | |
269 | ||
270 | //save the relationship | |
271 | //$this->click("_qf_Relationship_upload"); | |
6acc185a | 272 | $this->click('_qf_Relationship_upload-bottom'); |
3e60ff7f | 273 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']"); |
6a488035 TO |
274 | |
275 | //check the status message | |
6acc185a | 276 | $this->waitForText('crm-notification-container', "Relationship created."); |
6a488035 | 277 | |
3e60ff7f JP |
278 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody//tr/td[9]/span/a[text()='View']"); |
279 | $this->click("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody//tr/td[9]/span/a[text()='View']"); | |
6a488035 | 280 | |
6acc185a | 281 | $this->waitForElementPresent("xpath=//table[@class='crm-info-panel']"); |
6a488035 TO |
282 | $this->webtestVerifyTabularData( |
283 | array( | |
284 | 'Description' => $description, | |
285 | 'Status' => 'Enabled', | |
286 | ) | |
287 | ); | |
6acc185a | 288 | $this->assertElementContainsText("xpath=//table[@class='crm-info-panel']", $relType); |
6a488035 TO |
289 | } |
290 | ||
4cbe18b8 EM |
291 | /** |
292 | * @param $relType | |
293 | */ | |
00be9182 | 294 | public function _testSearchResult($relType) { |
6a488035 TO |
295 | |
296 | //search related contact using Advanced Search | |
79d6583c | 297 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
6a488035 TO |
298 | $this->select("component_mode", "label=Related Contacts"); |
299 | $this->select("display_relationship_type", "label={$relType}"); | |
300 | $this->click("CiviEvent"); | |
6acc185a | 301 | $this->waitForElementPresent("event_type_id"); |
302 | $this->select2("event_type_id", "Conference"); | |
6a488035 | 303 | $this->click("_qf_Advanced_refresh"); |
a488ca1a | 304 | $this->waitForElementPresent("xpath=id('search-status')"); |
79d6583c | 305 | $this->assertElementContainsText('search-status', '2 Contacts'); |
6a488035 TO |
306 | } |
307 | ||
6c6e6187 | 308 | public function testAdvanceSearchForLog() { |
6a488035 | 309 | $this->webtestLogin(); |
76e86fd8 | 310 | |
92915c55 TO |
311 | $Pdate = date('F jS, Y h:i:s A', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))); |
312 | $Ndate = date('F jS, Y h:i:s A', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))); | |
6a488035 TO |
313 | |
314 | //create a contact and return the contact id | |
92fcb95f | 315 | $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5); |
92915c55 | 316 | $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5); |
481a74f4 | 317 | $this->webtestAddContact($firstNameSoft, $lastNameSoft); |
a471a3b6 | 318 | $cid = $this->urlArg('cid'); |
6a488035 TO |
319 | |
320 | //advance search for created contacts | |
79d6583c | 321 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
92fcb95f | 322 | $this->type('sort_name', $lastNameSoft . ', ' . $firstNameSoft); |
6a488035 TO |
323 | $this->click('changeLog'); |
324 | $this->waitForElementPresent("log_date_low"); | |
6c6e6187 | 325 | $this->select("log_date_relative", "value=0"); |
6a488035 TO |
326 | $this->webtestFillDate('log_date_low', "-1 day"); |
327 | $this->webtestFillDate('log_date_high', "+1 day"); | |
328 | $this->click('_qf_Advanced_refresh'); | |
329 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c6e6187 | 330 | $this->assertTrue(TRUE, 'greater than or equal to "{$Pdate}" AND less than or equal to "{$Ndate}"'); |
6a488035 TO |
331 | $value = "$lastNameSoft, $firstNameSoft"; |
332 | $this->verifyText("xpath= id('rowid{$cid}')/td[3]/a", preg_quote($value)); | |
6a488035 | 333 | |
6c6e6187 | 334 | } |
6a488035 TO |
335 | |
336 | } |