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