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_Campaign_ActivityTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testCreateCampaign() { | |
36 | $this->webtestLogin(TRUE); | |
37 | ||
38 | // Enable CiviCampaign module if necessary | |
39 | $this->open($this->sboxPath . "civicrm/admin/setting/component?reset=1"); | |
40 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
41 | $this->waitForElementPresent("_qf_Component_next-bottom"); | |
42 | $enabledComponents = $this->getSelectOptions("enableComponents-t"); | |
43 | if (!in_array("CiviCampaign", $enabledComponents)) { | |
44 | $this->addSelection("enableComponents-f", "label=CiviCampaign"); | |
45 | $this->click("//option[@value='CiviCampaign']"); | |
46 | $this->click("add"); | |
47 | $this->click("_qf_Component_next-bottom"); | |
48 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
49 | sleep(1); | |
50 | $this->assertTrue($this->isTextPresent("Changes Saved.")); | |
51 | } | |
52 | ||
53 | // add the required Drupal permission | |
54 | $permissions = array('edit-2-administer-civicampaign'); | |
55 | $this->changePermissions($permissions); | |
56 | ||
57 | // Create new group | |
58 | $title = substr(sha1(rand()), 0, 7); | |
59 | $groupName = $this->WebtestAddGroup(); | |
60 | ||
61 | // Adding contact | |
62 | // We're using Quick Add block on the main page for this. | |
63 | $firstName1 = substr(sha1(rand()), 0, 7); | |
64 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); | |
65 | ||
66 | // add contact to group | |
67 | // visit group tab | |
68 | $this->click("css=li#tab_group a"); | |
69 | $this->waitForElementPresent("group_id"); | |
70 | ||
71 | // add to group | |
72 | $this->select("group_id", "label=$groupName"); | |
73 | $this->click("_qf_GroupContact_next"); | |
74 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
75 | ||
76 | $firstName2 = substr(sha1(rand()), 0, 7); | |
77 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org"); | |
78 | ||
79 | // add contact to group | |
80 | // visit group tab | |
81 | $this->click("css=li#tab_group a"); | |
82 | $this->waitForElementPresent("group_id"); | |
83 | ||
84 | // add to group | |
85 | $this->select("group_id", "label=$groupName"); | |
86 | $this->click("_qf_GroupContact_next"); | |
87 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
88 | ||
89 | // Go directly to the URL of the screen that you will be testing | |
90 | $this->open($this->sboxPath . "civicrm/campaign/add?reset=1"); | |
91 | ||
92 | // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
93 | // button at the end of this page to show up, to make sure it's fully loaded. | |
94 | $this->waitForElementPresent("_qf_Campaign_upload-bottom"); | |
95 | ||
96 | // Let's start filling the form with values. | |
97 | $campaignTitle = "Campaign " . $title; | |
98 | $this->type("title", $campaignTitle); | |
99 | ||
100 | // select the campaign type | |
101 | $this->select("campaign_type_id", "value=2"); | |
102 | ||
103 | // fill in the description | |
104 | $this->type("description", "This is a test campaign"); | |
105 | ||
106 | // include groups for the campaign | |
107 | $this->addSelection("includeGroups-f", "label=$groupName"); | |
108 | $this->click("//option[@value=4]"); | |
109 | $this->click("add"); | |
110 | ||
111 | // fill the end date for campaign | |
112 | $this->webtestFillDate("end_date", "+1 year"); | |
113 | ||
114 | // select campaign status | |
115 | $this->select("status_id", "value=2"); | |
116 | ||
117 | // click save | |
118 | $this->click("_qf_Campaign_upload-bottom"); | |
119 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
120 | ||
121 | $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."), | |
122 | "Status message didn't show up after saving campaign!" | |
123 | ); | |
124 | ||
125 | $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); | |
126 | $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]"); | |
127 | $this->activityAddTest($campaignTitle, $id); | |
128 | } | |
129 | ||
130 | function activityAddTest($campaignTitle, $id) { | |
131 | // Adding Adding contact with randomized first name for test testContactContextActivityAdd | |
132 | // We're using Quick Add block on the main page for this. | |
133 | $firstName1 = substr(sha1(rand()), 0, 7); | |
134 | $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name"); | |
135 | $firstName2 = substr(sha1(rand()), 0, 7); | |
136 | $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name"); | |
137 | ||
138 | // Go directly to the URL of the screen that you will be testing (Activity Tab). | |
139 | $this->click("css=li#tab_activity a"); | |
140 | ||
141 | // waiting for the activity dropdown to show up | |
142 | $this->waitForElementPresent("other_activity"); | |
143 | ||
144 | // Select the activity type from the activity dropdown | |
145 | $this->select("other_activity", "label=Meeting"); | |
146 | ||
147 | // waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
148 | // button at the end of this page to show up, to make sure it's fully loaded. | |
149 | $this->waitForElementPresent("_qf_Activity_upload"); | |
150 | ||
151 | // Let's start filling the form with values. | |
152 | ||
153 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
154 | $this->assertTrue($this->isTextPresent("Anderson, " . $firstName2), "Contact not found in line " . __LINE__); | |
155 | ||
156 | // Now we're filling the "Assigned To" field. | |
157 | // Typing contact's name into the field (using typeKeys(), not type()!)... | |
158 | $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id"); | |
159 | $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1); | |
160 | $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1); | |
161 | ||
162 | // ...waiting for drop down with results to show up... | |
163 | $this->waitForElementPresent("css=div.token-input-dropdown-facebook"); | |
164 | $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook"); | |
165 | ||
166 | // ...need to use mouseDownAt on first result (which is a li element), click does not work | |
167 | $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook"); | |
168 | // ...again, waiting for the box with contact name to show up... | |
169 | $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook"); | |
170 | ||
171 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
172 | $this->assertTrue($this->isTextPresent("Summerson, " . $firstName1), "Contact not found in line " . __LINE__); | |
173 | ||
174 | // Since we're here, let's check if screen help is being displayed properly | |
175 | // $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee")); | |
176 | ||
177 | // Putting the contents into subject field - assigning the text to variable, it'll come in handy later | |
178 | $subject = "This is subject of test activity being added through activity tab of contact summary screen."; | |
179 | // For simple input fields we can use field id as selector | |
180 | $this->type("subject", $subject); | |
181 | ||
182 | // select campaign | |
183 | $this->click("campaign_id"); | |
184 | $this->select("campaign_id", "value=$id"); | |
185 | ||
186 | $this->type("location", "Some location needs to be put in this field."); | |
187 | ||
188 | // Choosing the Date. | |
189 | // Please note that we don't want to put in fixed date, since | |
190 | // we want this test to work in the future and not fail because | |
191 | // of date being set in the past. Therefore, using helper webtestFillDateTime function. | |
192 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
193 | ||
194 | // Setting duration. | |
195 | $this->type("duration", "30"); | |
196 | ||
197 | // Putting in details. | |
198 | $this->type("details", "Really brief details information."); | |
199 | ||
200 | // Making sure that status is set to Scheduled (using value, not label). | |
201 | $this->select("status_id", "value=1"); | |
202 | ||
203 | // Setting priority. | |
204 | $this->select("priority_id", "value=1"); | |
205 | ||
206 | // Adding attachment | |
207 | // TODO TBD | |
208 | ||
209 | // Scheduling follow-up. | |
210 | $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header"); | |
211 | $this->select("followup_activity_type_id", "value=1"); | |
212 | $this->webtestFillDateTime('followup_date', '+1 month 11:10PM'); | |
213 | $this->type("followup_activity_subject", "This is subject of schedule follow-up activity"); | |
214 | ||
215 | // Clicking save. | |
216 | $this->click("_qf_Activity_upload"); | |
217 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
218 | ||
219 | // Is status message correct? | |
220 | $this->assertTrue($this->isTextPresent("Activity '$subject' has been saved."), "Status message didn't show up after saving!"); | |
221 | ||
222 | $this->waitForElementPresent("xpath=//div[@id='Activities']//table/tbody/tr[1]/td[9]/span/a[text()='View']"); | |
223 | ||
224 | // click through to the Activity view screen | |
225 | $this->click("xpath=//div[@id='Activities']//table/tbody//tr/td[2][text()='This is subject of test activity being added through activity tab of contact summary screen.']/../td[9]/span/a[text()='View']"); | |
226 | $this->waitForElementPresent('_qf_Activity_cancel-bottom'); | |
227 | ||
228 | // verify Activity created | |
229 | $this->verifyText("xpath=id( 'Activity' )/div[2]/table[1]/tbody/tr[5]/td[2]", preg_quote($campaignTitle)); | |
230 | } | |
231 | } | |
232 |