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