| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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, $paymentProcessorId); |
| 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", "xpath=//form[@id='Basic']//div/div//div/table/tbody/tr/"); |
| 96 | |
| 97 | // click through to the Relationship view screen |
| 98 | $this->click("xpath=//form[@id='Basic']//div/div//div/table/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->type("sort_name", $sortName); |
| 113 | $this->click('_qf_Advanced_refresh'); |
| 114 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); |
| 115 | |
| 116 | $this->waitForElementPresent('search-status'); |
| 117 | $this->assertElementContainsText('search-status', '1 Contact'); |
| 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 | |
| 125 | $this->waitForElementPresent('search-status'); |
| 126 | $this->assertElementContainsText('search-status', '2 Contact'); |
| 127 | |
| 128 | $this->select("task", "label=Group - add contacts"); |
| 129 | |
| 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 | |
| 140 | $this->waitForText('crm-notification-container', "Added Contacts to " . $groupName); |
| 141 | $this->waitForText('crm-notification-container', '2 contacts added to group'); |
| 142 | $this->_testSearchResult($relType); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @param $eventTitle |
| 147 | * @param $eventDescription |
| 148 | */ |
| 149 | public function _testAddEventInfo($eventTitle, $eventDescription) { |
| 150 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
| 151 | |
| 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 | |
| 174 | /** |
| 175 | * @param $streetAddress |
| 176 | */ |
| 177 | public function _testAddLocation($streetAddress) { |
| 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"); |
| 187 | $this->select('address_1_country_id', 'UNITED STATES'); |
| 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 |
| 194 | $this->waitForElementPresent("_qf_Location_upload-bottom"); |
| 195 | $this->waitForText('crm-notification-container', "'Event Location' information has been saved."); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * @param bool $discount |
| 200 | * @param bool $priceSet |
| 201 | * @param int $processorId |
| 202 | */ |
| 203 | public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) { |
| 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}]"); |
| 209 | $this->select("financial_type_id", "value=4"); |
| 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 |
| 229 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); |
| 230 | $this->waitForTextPresent("'Fees' information has been saved."); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @param string $ContactName |
| 235 | * @param string $relatedName |
| 236 | * @param $relType |
| 237 | */ |
| 238 | public function _testAddRelationship($ContactName, $relatedName, $relType) { |
| 239 | |
| 240 | $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh'); |
| 241 | $this->type("sort_name", $ContactName); |
| 242 | $this->select("contact_type", "value=Individual"); |
| 243 | $this->clickLink("_qf_Basic_refresh", "xpath=//form[@id='Basic']/div[3]/div/div[2]/table/tbody/tr/"); |
| 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 |
| 260 | $this->waitForElementPresent("related_contact_id"); |
| 261 | $this->select2('related_contact_id', $relatedName, TRUE); |
| 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"); |
| 272 | $this->click('_qf_Relationship_upload-bottom'); |
| 273 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']"); |
| 274 | |
| 275 | //check the status message |
| 276 | $this->waitForText('crm-notification-container', "Relationship created."); |
| 277 | |
| 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']"); |
| 280 | |
| 281 | $this->waitForElementPresent("xpath=//table[@class='crm-info-panel']"); |
| 282 | $this->webtestVerifyTabularData( |
| 283 | array( |
| 284 | 'Description' => $description, |
| 285 | 'Status' => 'Enabled', |
| 286 | ) |
| 287 | ); |
| 288 | $this->assertElementContainsText("xpath=//table[@class='crm-info-panel']", $relType); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @param $relType |
| 293 | */ |
| 294 | public function _testSearchResult($relType) { |
| 295 | |
| 296 | //search related contact using Advanced Search |
| 297 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
| 298 | $this->select("component_mode", "label=Related Contacts"); |
| 299 | $this->select("display_relationship_type", "label={$relType}"); |
| 300 | $this->click("CiviEvent"); |
| 301 | $this->waitForElementPresent("event_type_id"); |
| 302 | $this->select2("event_type_id", "Conference"); |
| 303 | $this->click("_qf_Advanced_refresh"); |
| 304 | $this->waitForElementPresent("xpath=id('search-status')"); |
| 305 | $this->assertElementContainsText('search-status', '2 Contacts'); |
| 306 | } |
| 307 | |
| 308 | public function testAdvanceSearchForLog() { |
| 309 | $this->webtestLogin(); |
| 310 | |
| 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'))); |
| 313 | |
| 314 | //create a contact and return the contact id |
| 315 | $firstNameSoft = "John_" . substr(sha1(rand()), 0, 5); |
| 316 | $lastNameSoft = "Doe_" . substr(sha1(rand()), 0, 5); |
| 317 | $this->webtestAddContact($firstNameSoft, $lastNameSoft); |
| 318 | $cid = $this->urlArg('cid'); |
| 319 | |
| 320 | //advance search for created contacts |
| 321 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
| 322 | $this->type('sort_name', $lastNameSoft . ', ' . $firstNameSoft); |
| 323 | $this->click('changeLog'); |
| 324 | $this->waitForElementPresent("log_date_low"); |
| 325 | $this->select("log_date_relative", "value=0"); |
| 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()); |
| 330 | $this->assertTrue(TRUE, 'greater than or equal to "{$Pdate}" AND less than or equal to "{$Ndate}"'); |
| 331 | $value = "$lastNameSoft, $firstNameSoft"; |
| 332 | $this->verifyText("xpath= id('rowid{$cid}')/td[3]/a", preg_quote($value)); |
| 333 | |
| 334 | } |
| 335 | |
| 336 | } |