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