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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_MultipleContactSubTypes | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_MultipleContactSubTypes extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testIndividualAdd() { |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
41 | $selection1 = 'Student'; | |
42 | $selection2 = 'Parent'; | |
43 | $selection3 = 'Staff'; | |
44 | ||
45 | //Create custom group for contact sub-types | |
46 | list($groupTitleForStudent, $customGroupIdForStudent) = $this->_addCustomData($selection1); | |
47 | list($groupTitleForParent, $customGroupIdForParent) = $this->_addCustomData($selection2); | |
48 | list($groupTitleForStaff, $customGroupIdForStaff) = $this->_addCustomData($selection3); | |
49 | ||
071a6d2e | 50 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
51 | |
52 | //contact details section | |
53 | //select prefix | |
54 | $this->click("prefix_id"); | |
55 | $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix')); | |
56 | ||
57 | $this->addSelection('contact_sub_type', "value={$selection1}"); | |
58 | $this->addSelection('contact_sub_type', "value={$selection2}"); | |
59 | ||
60 | //fill in first name | |
61 | $this->type("first_name", substr(sha1(rand()), 0, 7) . "John"); | |
62 | ||
63 | //fill in middle name | |
64 | $this->type("middle_name", "Bruce"); | |
65 | ||
66 | //fill in last name | |
67 | $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith"); | |
68 | ||
69 | //select suffix | |
70 | $this->select("suffix_id", "value=3"); | |
71 | ||
72 | //fill in nick name | |
73 | $this->type("nick_name", "jsmith"); | |
74 | ||
75 | //fill in email | |
76 | $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com"); | |
77 | ||
78 | //fill in phone | |
79 | $this->type("phone_1_phone", "2222-4444"); | |
80 | ||
81 | //fill in IM | |
82 | $this->type("im_1_name", "testYahoo"); | |
83 | ||
6a488035 TO |
84 | //fill in website |
85 | $this->type("website_1_url", "http://www.john.com"); | |
86 | ||
87 | //fill in source | |
88 | $this->type("contact_source", "johnSource"); | |
89 | ||
90 | //fill in external identifier | |
91 | $indExternalId = substr(sha1(rand()), 0, 4); | |
92 | $this->type("external_identifier", $indExternalId); | |
93 | ||
efb29358 CW |
94 | $this->waitForElementPresent("customData$customGroupIdForStudent"); |
95 | $this->waitForElementPresent("customData$customGroupIdForParent"); | |
6a488035 | 96 | |
efb29358 CW |
97 | // Make sure our staff custom set does NOT show up |
98 | $this->assertFalse($this->isElementPresent("customData$customGroupIdForStaff"), "A custom field showed up for the wrong subtype!"); | |
6a488035 | 99 | |
efb29358 CW |
100 | $this->type("xpath=//div[@id='customData{$customGroupIdForStudent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForStudent}"); |
101 | $this->type("xpath=//div[@id='customData{$customGroupIdForParent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForParent}"); | |
6a488035 TO |
102 | |
103 | //address section | |
104 | $this->click("addressBlock"); | |
105 | $this->waitForElementPresent("address_1_street_address"); | |
106 | //fill in address 1 | |
107 | $this->type("address_1_street_address", "902C El Camino Way SW"); | |
108 | $this->type("address_1_city", "Dumfries"); | |
109 | $this->type("address_1_postal_code", "1234"); | |
110 | ||
111 | $this->click("address_1_country_id"); | |
112 | $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID()); | |
113 | ||
efb29358 | 114 | if ($this->isElementPresent("address_1_geo_code_1")) { |
6a488035 TO |
115 | $this->type("address_1_geo_code_1", "1234"); |
116 | $this->type("address_1_geo_code_2", "5678"); | |
117 | } | |
118 | ||
119 | //fill in address 2 | |
120 | $this->click("//div[@id='addMoreAddress1']/a/span"); | |
121 | $this->waitForElementPresent("address_2_street_address"); | |
122 | $this->type("address_2_street_address", "2782Y Dowlen Path W"); | |
123 | $this->type("address_2_city", "Birmingham"); | |
124 | $this->type("address_2_postal_code", "3456"); | |
125 | ||
126 | $this->click("address_2_country_id"); | |
127 | $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID()); | |
128 | ||
efb29358 | 129 | if ($this->isElementPresent("address_2_geo_code_1")) { |
6a488035 TO |
130 | $this->type("address_2_geo_code_1", "1234"); |
131 | $this->type("address_2_geo_code_2", "5678"); | |
132 | } | |
133 | ||
134 | //Communication Preferences section | |
135 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Communication Preferences')]"); | |
136 | ||
137 | //select greeting/addressee options | |
138 | $this->waitForElementPresent("email_greeting_id"); | |
139 | $this->select("email_greeting_id", "value=2"); | |
140 | $this->select("postal_greeting_id", "value=3"); | |
141 | ||
142 | //Select preferred method for Privacy | |
143 | $this->click("privacy[do_not_trade]"); | |
144 | $this->click("privacy[do_not_sms]"); | |
145 | ||
146 | //Select preferred method(s) of communication | |
147 | $this->click("preferred_communication_method[1]"); | |
148 | $this->click("preferred_communication_method[2]"); | |
149 | ||
150 | //select preferred language | |
151 | $this->waitForElementPresent("preferred_language"); | |
152 | $this->select("preferred_language", "value=en_US"); | |
153 | ||
154 | //Demographics section | |
155 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]"); | |
156 | $this->waitForElementPresent("birth_date"); | |
157 | ||
158 | $this->webtestFillDate('birth_date', "-1 year"); | |
159 | ||
160 | //Tags and Groups section | |
161 | $this->click("//div[@class='crm-accordion-header' and contains(.,'Tags and Groups')]"); | |
162 | ||
163 | $this->click("group[{$this->webtestGetValidEntityID('Group')}]"); | |
164 | $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]"); | |
165 | ||
166 | // Clicking save. | |
167 | $this->click("_qf_Contact_upload_view"); | |
168 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
169 | ||
170 | //checking the contact sub-type of newly created individual | |
6c5f7368 | 171 | $this->waitForText('crm-notification-container', "Contact Saved"); |
efb29358 CW |
172 | $this->assertElementContainsText('css=.crm-contact_type_label', "Student"); |
173 | $this->assertElementContainsText('css=.crm-contact_type_label', "Parent"); | |
6a488035 TO |
174 | |
175 | //custom data check | |
2ac4a694 RN |
176 | $this->waitForText("custom-set-content-{$customGroupIdForParent}", "dummy text for customData{$customGroupIdForParent}"); |
177 | $this->waitForText("custom-set-content-{$customGroupIdForStudent}", "dummy text for customData{$customGroupIdForStudent}"); | |
6a488035 | 178 | |
efb29358 CW |
179 | // Get contact id |
180 | $cid = $this->urlArg('cid'); | |
6a488035 | 181 | |
efb29358 CW |
182 | //editing contact sub-type |
183 | $this->openCiviPage('contact/add', "reset=1&action=update&cid=$cid"); | |
6a488035 TO |
184 | |
185 | //edit contact sub-type | |
186 | $this->removeSelection("contact_sub_type", "value={$selection1}"); | |
187 | $this->addSelection('contact_sub_type', "value={$selection3}"); | |
188 | ||
efb29358 | 189 | $this->waitForElementPresent("customData$customGroupIdForStaff"); |
6a488035 | 190 | |
efb29358 CW |
191 | // Make sure our staff custom set does NOT show up |
192 | $this->assertFalse($this->isElementPresent("customData$customGroupIdForStudent"), "A custom field showed up for the wrong subtype!"); | |
6a488035 | 193 | |
efb29358 CW |
194 | $this->type("xpath=//div[@id='customData{$customGroupIdForParent}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForParent}"); |
195 | $this->type("xpath=//div[@id='customData{$customGroupIdForStaff}']/table/tbody/tr//td/input", "dummy text for customData{$customGroupIdForStaff}"); | |
6a488035 TO |
196 | |
197 | $this->click("_qf_Contact_upload_view-bottom"); | |
efb29358 | 198 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
6a488035 TO |
199 | |
200 | // Check confirmation alert. | |
6c6e6187 | 201 | $this->assertTrue((bool) preg_match("/One or more contact subtypes have been de-selected from the list for this contact. Any custom data associated with de-selected subtype will be removed. Click OK to proceed, or Cancel to review your changes before saving./", $this->getConfirmation())); |
6a488035 | 202 | $this->chooseOkOnNextConfirmation(); |
efb29358 | 203 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
6a488035 | 204 | |
efb29358 | 205 | // Verify contact types |
6c5f7368 | 206 | $this->waitForText('crm-notification-container', "Contact Saved"); |
efb29358 CW |
207 | $this->assertElementNotContainsText('css=.crm-contact_type_label', "Student"); |
208 | $this->assertElementContainsText('css=.crm-contact_type_label', "Staff"); | |
209 | $this->assertElementContainsText('css=.crm-contact_type_label', "Parent"); | |
6a488035 TO |
210 | |
211 | //custom data check | |
2ac4a694 RN |
212 | $this->waitForText("custom-set-content-{$customGroupIdForParent}", "dummy text for customData{$customGroupIdForParent}"); |
213 | $this->waitForText("custom-set-content-{$customGroupIdForStaff}", "dummy text for customData{$customGroupIdForStaff}"); | |
6a488035 TO |
214 | } |
215 | ||
efb29358 CW |
216 | /** |
217 | * Add custom fields for a contact sub-type | |
1e1fdcf6 EM |
218 | * @param $contactSubType |
219 | * @return array | |
efb29358 | 220 | */ |
00be9182 | 221 | public function _addCustomData($contactSubType) { |
efb29358 | 222 | $this->openCiviPage("admin/custom/group", "action=add&reset=1"); |
6a488035 TO |
223 | |
224 | //fill custom group title | |
efb29358 | 225 | $customGroupTitle = "Custom group For {$contactSubType}" . substr(sha1(rand()), 0, 4); |
6a488035 TO |
226 | $this->click("title"); |
227 | $this->type("title", $customGroupTitle); | |
228 | ||
229 | //custom group extends | |
efb29358 CW |
230 | $this->click("extends_0"); |
231 | $this->select("extends_0", "value=Individual"); | |
232 | $this->addSelection("extends_1", "label={$contactSubType}"); | |
233 | ||
234 | // Don't collapse | |
235 | $this->uncheck('collapse_display'); | |
236 | ||
237 | // Save | |
6a488035 TO |
238 | $this->click('_qf_Group_next-bottom'); |
239 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
240 | ||
241 | //Is custom group created? | |
2ac4a694 | 242 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added."); |
a471a3b6 | 243 | $gid = $this->urlArg('gid'); |
6a488035 | 244 | |
39a2888d CW |
245 | // Add field |
246 | $this->openCiviPage('admin/custom/group/field/add', "reset=1&action=add&gid=$gid"); | |
6a488035 TO |
247 | $fieldLabel = "custom_field_for_{$contactSubType}" . substr(sha1(rand()), 0, 4); |
248 | $this->type('label', $fieldLabel); | |
39a2888d | 249 | $this->click('_qf_Field_done-bottom'); |
6a488035 TO |
250 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
251 | $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); | |
252 | return array($customGroupTitle, $gid); | |
253 | } | |
96025800 | 254 | |
6a488035 | 255 | } |