| 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_RelationshipAddTest |
| 31 | */ |
| 32 | class WebTest_Contact_RelationshipAddTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testRelationshipAddTest() { |
| 39 | $this->webtestLogin(); |
| 40 | |
| 41 | //create a relationship type between different contact types |
| 42 | $params = array( |
| 43 | 'label_a_b' => 'Owner of ' . rand(), |
| 44 | 'label_b_a' => 'Belongs to ' . rand(), |
| 45 | 'contact_type_a' => 'Individual', |
| 46 | 'contact_type_b' => 'Household', |
| 47 | 'description' => 'The company belongs to this individual', |
| 48 | ); |
| 49 | |
| 50 | $this->webtestAddRelationshipType($params); |
| 51 | |
| 52 | //create a New Individual |
| 53 | $firstName = substr(sha1(rand()), 0, 7); |
| 54 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); |
| 55 | $sortName = "Anderson, $firstName"; |
| 56 | |
| 57 | $this->openCiviPage("contact/add", "reset=1&ct=Household"); |
| 58 | |
| 59 | //fill in Household name |
| 60 | $this->click("household_name"); |
| 61 | $name = "Fraddie Grant's home " . substr(sha1(rand()), 0, 7); |
| 62 | $this->type("household_name", $name); |
| 63 | |
| 64 | // Clicking save. |
| 65 | $this->click("_qf_Contact_upload_view"); |
| 66 | $this->waitForElementPresent("css=.crm-contact-tabs-list"); |
| 67 | |
| 68 | // visit relationship tab of the household |
| 69 | $this->click("css=li#tab_rel a"); |
| 70 | |
| 71 | // wait for add Relationship link |
| 72 | $this->waitForElementPresent('link=Add Relationship'); |
| 73 | $this->click('link=Add Relationship'); |
| 74 | |
| 75 | //choose the created relationship type |
| 76 | $this->waitForElementPresent("relationship_type_id"); |
| 77 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); |
| 78 | |
| 79 | //fill in the individual |
| 80 | $this->select2('related_contact_id', $sortName, TRUE); |
| 81 | |
| 82 | //fill in the relationship start date |
| 83 | $this->webtestFillDate('start_date', '-2 year'); |
| 84 | $this->webtestFillDate('end_date', '+1 year'); |
| 85 | |
| 86 | $description = "Well here is some description !!!!"; |
| 87 | $this->type("description", $description); |
| 88 | |
| 89 | //save the relationship |
| 90 | //$this->click("_qf_Relationship_upload"); |
| 91 | $this->click('_qf_Relationship_upload-bottom'); |
| 92 | |
| 93 | //check the status message |
| 94 | $this->waitForText('crm-notification-container', 'Relationship created.'); |
| 95 | $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 96 | $this->click("xpath=//div[@class='crm-contact-relationship-current']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 97 | |
| 98 | $this->webtestVerifyTabularData( |
| 99 | array( |
| 100 | 'Description' => $description, |
| 101 | 'Status' => 'Enabled', |
| 102 | ) |
| 103 | ); |
| 104 | |
| 105 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); |
| 106 | |
| 107 | //create a New Individual subtype |
| 108 | $this->openCiviPage('admin/options/subtype', "action=add&reset=1"); |
| 109 | $label = "IndividualSubtype" . substr(sha1(rand()), 0, 4); |
| 110 | $this->type("label", $label); |
| 111 | $this->type("description", "here is individual subtype"); |
| 112 | $this->click("_qf_ContactType_next-bottom"); |
| 113 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 114 | |
| 115 | //create a new contact of individual subtype |
| 116 | $this->openCiviPage('contact/add', "ct=Individual&cst={$label}&reset=1", '_qf_Contact_upload_view'); |
| 117 | $firstName = substr(sha1(rand()), 0, 7); |
| 118 | $lastName = 'And' . substr(sha1(rand()), 0, 7); |
| 119 | $this->click("first_name"); |
| 120 | $this->type("first_name", $firstName); |
| 121 | $this->click("last_name"); |
| 122 | $this->type("last_name", $lastName); |
| 123 | $sortName = "$lastName, $firstName"; |
| 124 | |
| 125 | // Clicking save. |
| 126 | $this->click("_qf_Contact_upload_view"); |
| 127 | $this->waitForElementPresent("css=.crm-contact-tabs-list"); |
| 128 | |
| 129 | //create a New household subtype |
| 130 | $this->openCiviPage("admin/options/subtype", "action=add&reset=1"); |
| 131 | |
| 132 | $label = "HouseholdSubtype" . substr(sha1(rand()), 0, 4); |
| 133 | $householdSubtypeName = $label; |
| 134 | $this->click("label"); |
| 135 | $this->type("label", $label); |
| 136 | $this->select("parent_id", "label=Household"); |
| 137 | $this->type("description", "here is household subtype"); |
| 138 | $this->click("_qf_ContactType_next-bottom"); |
| 139 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 140 | |
| 141 | //create a new contact of household subtype |
| 142 | $this->openCiviPage('contact/add', "ct=Household&cst={$label}&reset=1", '_qf_Contact_upload_view'); |
| 143 | |
| 144 | //fill in Household name |
| 145 | $householdName = substr(sha1(rand()), 0, 4) . 'home'; |
| 146 | $this->click("household_name"); |
| 147 | $this->type("household_name", $householdName); |
| 148 | |
| 149 | // Clicking save. |
| 150 | $this->click("_qf_Contact_upload_view"); |
| 151 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 152 | |
| 153 | //choose the created relationship type |
| 154 | $this->click('css=li#tab_rel a'); |
| 155 | |
| 156 | // wait for add Relationship link |
| 157 | $this->waitForElementPresent('link=Add Relationship'); |
| 158 | $this->click('link=Add Relationship'); |
| 159 | $this->waitForElementPresent("relationship_type_id"); |
| 160 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); |
| 161 | |
| 162 | //fill in the individual |
| 163 | $this->waitForElementPresent("related_contact_id"); |
| 164 | $this->select2('related_contact_id', $sortName, TRUE); |
| 165 | |
| 166 | //fill in the relationship start date |
| 167 | $this->webtestFillDate('start_date', '-2 year'); |
| 168 | $this->webtestFillDate('end_date', '+1 year'); |
| 169 | |
| 170 | $description = "Well here is some description !!!!"; |
| 171 | $this->type("description", $description); |
| 172 | |
| 173 | //save the relationship |
| 174 | $this->click('_qf_Relationship_upload-bottom'); |
| 175 | |
| 176 | $this->waitForElementPresent("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 177 | $this->click("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 178 | |
| 179 | $this->webtestVerifyTabularData( |
| 180 | array( |
| 181 | 'Description' => $description, |
| 182 | 'Status' => 'Enabled', |
| 183 | ) |
| 184 | ); |
| 185 | |
| 186 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); |
| 187 | |
| 188 | //test for individual contact and household subtype contact |
| 189 | //relationship |
| 190 | $typeb = "Household__" . $householdSubtypeName; |
| 191 | |
| 192 | //create a relationship type between different contact types |
| 193 | $params = array( |
| 194 | 'label_a_b' => 'Owner of ' . rand(), |
| 195 | 'label_b_a' => 'Belongs to ' . rand(), |
| 196 | 'contact_type_a' => 'Individual', |
| 197 | 'contact_type_b' => $typeb, |
| 198 | 'description' => 'The company belongs to this individual', |
| 199 | ); |
| 200 | |
| 201 | //create relationship type |
| 202 | $this->openCiviPage('admin/reltype', 'reset=1&action=add'); |
| 203 | $this->type('label_a_b', $params['label_a_b']); |
| 204 | $this->type('label_b_a', $params['label_b_a']); |
| 205 | $this->select('contact_types_a', "value={$params['contact_type_a']}"); |
| 206 | $this->select('contact_types_b', "value={$params['contact_type_b']}"); |
| 207 | $this->type('description', $params['description']); |
| 208 | |
| 209 | $params['contact_type_b'] = preg_replace('/__/', ' - ', $params['contact_type_b']); |
| 210 | |
| 211 | //save the data. |
| 212 | $this->click('_qf_RelationshipType_next-bottom'); |
| 213 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 214 | |
| 215 | //does data saved. |
| 216 | $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'), |
| 217 | "Status message didn't show up after saving!" |
| 218 | ); |
| 219 | |
| 220 | $this->openCiviPage("admin/reltype", "reset=1"); |
| 221 | |
| 222 | //validate data on selector. |
| 223 | $data = $params; |
| 224 | if (isset($data['description'])) { |
| 225 | unset($data['description']); |
| 226 | } |
| 227 | $this->assertStringsPresent($data); |
| 228 | |
| 229 | //create a New Individual |
| 230 | $firstName = substr(sha1(rand()), 0, 7); |
| 231 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); |
| 232 | $sortName = "Anderson, $firstName"; |
| 233 | |
| 234 | //create a new contact of household subtype |
| 235 | $this->openCiviPage('contact/add', "ct=Household&cst={$householdSubtypeName}&reset=1", '_qf_Contact_upload_view'); |
| 236 | |
| 237 | //fill in Household name |
| 238 | $householdName = substr(sha1(rand()), 0, 4) . 'home'; |
| 239 | $this->click("household_name"); |
| 240 | $this->type("household_name", $householdName); |
| 241 | |
| 242 | // Clicking save. |
| 243 | $this->click("_qf_Contact_upload_view"); |
| 244 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 245 | |
| 246 | //choose the created relationship type |
| 247 | $this->click('css=li#tab_rel a'); |
| 248 | |
| 249 | // wait for add Relationship link |
| 250 | $this->waitForElementPresent('link=Add Relationship'); |
| 251 | $this->click('link=Add Relationship'); |
| 252 | $this->waitForElementPresent("relationship_type_id"); |
| 253 | $this->select('relationship_type_id', "label={$params['label_b_a']}"); |
| 254 | |
| 255 | //fill in the individual |
| 256 | |
| 257 | $this->select2('related_contact_id', $sortName, TRUE); |
| 258 | |
| 259 | //fill in the relationship start date |
| 260 | $this->webtestFillDate('start_date', '-2 year'); |
| 261 | $this->webtestFillDate('end_date', '+1 year'); |
| 262 | $description = "Well here is some description !!!!"; |
| 263 | $this->type("description", $description); |
| 264 | |
| 265 | //save the relationship |
| 266 | $this->click('_qf_Relationship_upload-bottom'); |
| 267 | |
| 268 | $this->waitForElementPresent("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 269 | $this->click("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 270 | |
| 271 | $this->webtestVerifyTabularData( |
| 272 | array( |
| 273 | 'Description' => $description, |
| 274 | 'Status' => 'Enabled', |
| 275 | ) |
| 276 | ); |
| 277 | |
| 278 | $this->assertTrue($this->isTextPresent($params['label_b_a'])); |
| 279 | } |
| 280 | |
| 281 | public function testRelationshipAddNewIndividualTest() { |
| 282 | $this->webtestLogin(); |
| 283 | |
| 284 | //create a relationship type between different contact types |
| 285 | $params = array( |
| 286 | 'label_a_b' => 'Board Member of ' . rand(), |
| 287 | 'label_b_a' => 'Board Member is' . rand(), |
| 288 | 'contact_type_a' => 'Individual', |
| 289 | 'contact_type_b' => 'Organization', |
| 290 | 'description' => 'Board members of organizations.', |
| 291 | ); |
| 292 | |
| 293 | $this->webtestAddRelationshipType($params); |
| 294 | |
| 295 | //create a New Individual |
| 296 | $firstName = substr(sha1(rand()), 0, 7); |
| 297 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); |
| 298 | |
| 299 | // visit relationship tab of the Individual |
| 300 | $this->click("css=li#tab_rel a"); |
| 301 | |
| 302 | // wait for add Relationship link |
| 303 | $this->waitForElementPresent('link=Add Relationship'); |
| 304 | $this->click('link=Add Relationship'); |
| 305 | |
| 306 | //choose the created relationship type |
| 307 | $this->waitForElementPresent("relationship_type_id"); |
| 308 | $this->select('relationship_type_id', "label={$params['label_a_b']}"); |
| 309 | $this->waitForAjaxContent(); |
| 310 | |
| 311 | // create a new organization |
| 312 | $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7); |
| 313 | |
| 314 | $this->click("//*[@id='related_contact_id']/../div/ul/li/input"); |
| 315 | $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]"); |
| 316 | $this->waitForElementPresent('_qf_Edit_next'); |
| 317 | $this->type('organization_name', $orgName); |
| 318 | $this->type('email-Primary', "info@" . $orgName . ".com"); |
| 319 | $this->click('_qf_Edit_next'); |
| 320 | $this->waitForText("xpath=//div[@id='s2id_related_contact_id']", "$orgName"); |
| 321 | |
| 322 | //fill in the relationship start date |
| 323 | $this->webtestFillDate('start_date', '-2 year'); |
| 324 | $this->webtestFillDate('end_date', '+1 year'); |
| 325 | |
| 326 | $description = "Long-standing board member."; |
| 327 | $this->type("description", $description); |
| 328 | |
| 329 | //save the relationship |
| 330 | //$this->click("_qf_Relationship_upload"); |
| 331 | $this->click("_qf_Relationship_upload-bottom"); |
| 332 | |
| 333 | //check the status message |
| 334 | $this->waitForText('crm-notification-container', 'Relationship created.'); |
| 335 | $this->waitForElementPresent("xpath=//div[@id='contact-summary-relationship-tab']/div[2]/div[1]/table/tbody/tr/td[9]/span[1]//a[text()='View']"); |
| 336 | $this->click("xpath=//div[@id='contact-summary-relationship-tab']/div[2]/div[1]/table/tbody/tr/td[9]/span[1]//a[text()='View']"); |
| 337 | |
| 338 | $this->webtestVerifyTabularData( |
| 339 | array( |
| 340 | 'Description' => $description, |
| 341 | 'Status' => 'Enabled', |
| 342 | ) |
| 343 | ); |
| 344 | $this->assertTrue($this->isTextPresent($params['label_a_b'])); |
| 345 | } |
| 346 | |
| 347 | public function testAjaxCustomGroupLoad() { |
| 348 | $this->webtestLogin(); |
| 349 | |
| 350 | //create a New Individual |
| 351 | $firstName = substr(sha1(rand()), 0, 7); |
| 352 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); |
| 353 | $contactId = explode('cid=', $this->getLocation()); |
| 354 | |
| 355 | $triggerElement = array('name' => 'relationship_type_id', 'type' => 'select'); |
| 356 | $customSets = array( |
| 357 | array('entity' => 'Relationship', 'subEntity' => 'Partner of', 'triggerElement' => $triggerElement), |
| 358 | array('entity' => 'Relationship', 'subEntity' => 'Spouse of', 'triggerElement' => $triggerElement), |
| 359 | ); |
| 360 | |
| 361 | $pageUrl = array('url' => 'contact/view/rel', 'args' => "cid={$contactId[1]}&action=add&reset=1"); |
| 362 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); |
| 363 | } |
| 364 | |
| 365 | public function testRelationshipAddCurrentEmployerTest() { |
| 366 | $this->webtestLogin(); |
| 367 | |
| 368 | //create a New Individual |
| 369 | $firstName = substr(sha1(rand()), 0, 7); |
| 370 | $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name"); |
| 371 | |
| 372 | // visit relationship tab of the Individual |
| 373 | $this->click("css=li#tab_rel a"); |
| 374 | |
| 375 | // wait for add Relationship link |
| 376 | $this->waitForElementPresent('link=Add Relationship'); |
| 377 | $this->click('link=Add Relationship'); |
| 378 | |
| 379 | //choose the created relationship type |
| 380 | $this->waitForElementPresent("relationship_type_id"); |
| 381 | $this->select('relationship_type_id', "label=Employee of"); |
| 382 | $this->waitForAjaxContent(); |
| 383 | |
| 384 | // create a new organization |
| 385 | |
| 386 | $orgName = 'WestsideCoop' . substr(sha1(rand()), 0, 7); |
| 387 | $this->click("//*[@id='related_contact_id']/../div/ul/li/input"); |
| 388 | $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]"); |
| 389 | $this->waitForElementPresent('_qf_Edit_next'); |
| 390 | $this->type('organization_name', $orgName); |
| 391 | $this->type('email-Primary', "info@" . $orgName . ".com"); |
| 392 | $this->click('_qf_Edit_next'); |
| 393 | $this->waitForText("xpath=//div[@id='s2id_related_contact_id']", "$orgName"); |
| 394 | |
| 395 | //fill in the relationship start date |
| 396 | $this->webtestFillDate('start_date', '-2 year'); |
| 397 | $this->webtestFillDate('end_date', '+1 year'); |
| 398 | |
| 399 | $description = "Current employee test."; |
| 400 | $this->type("description", $description); |
| 401 | |
| 402 | //save the relationship |
| 403 | //$this->click("_qf_Relationship_upload"); |
| 404 | $this->click('_qf_Relationship_upload-bottom'); |
| 405 | |
| 406 | //check the status message |
| 407 | $this->waitForText('crm-notification-container', 'Relationship created.'); |
| 408 | |
| 409 | $this->waitForElementPresent("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 410 | $this->click("xpath=//div[@id='contact-summary-relationship-tab']/div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[9]//span//a[text()='View']"); |
| 411 | |
| 412 | $this->webtestVerifyTabularData( |
| 413 | array( |
| 414 | 'Description' => $description, |
| 415 | 'Current Employee?' => 'Yes', |
| 416 | 'Status' => 'Enabled', |
| 417 | ) |
| 418 | ); |
| 419 | $this->assertTrue($this->isTextPresent("Employee of"), "Employee of relationship type not visible on View Relationship page."); |
| 420 | } |
| 421 | |
| 422 | } |