Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Campaign_ActivityTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Campaign_ActivityTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testCreateCampaign() { | |
42daf119 | 39 | $this->webtestLogin('admin'); |
6a488035 TO |
40 | |
41 | // Enable CiviCampaign module if necessary | |
8f737a72 | 42 | $this->enableComponents(array('CiviCampaign')); |
6a488035 TO |
43 | |
44 | // add the required Drupal permission | |
45 | $permissions = array('edit-2-administer-civicampaign'); | |
46 | $this->changePermissions($permissions); | |
47 | ||
42daf119 CW |
48 | // Log in as normal user |
49 | $this->webtestLogin(); | |
50 | ||
6a488035 TO |
51 | // Create new group |
52 | $title = substr(sha1(rand()), 0, 7); | |
53 | $groupName = $this->WebtestAddGroup(); | |
54 | ||
55 | // Adding contact | |
56 | // We're using Quick Add block on the main page for this. | |
57 | $firstName1 = substr(sha1(rand()), 0, 7); | |
58 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); | |
59 | ||
60 | // add contact to group | |
61 | // visit group tab | |
62 | $this->click("css=li#tab_group a"); | |
63 | $this->waitForElementPresent("group_id"); | |
64 | ||
65 | // add to group | |
66 | $this->select("group_id", "label=$groupName"); | |
67 | $this->click("_qf_GroupContact_next"); | |
2af8120a | 68 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
69 | |
70 | $firstName2 = substr(sha1(rand()), 0, 7); | |
71 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org"); | |
72 | ||
73 | // add contact to group | |
74 | // visit group tab | |
75 | $this->click("css=li#tab_group a"); | |
76 | $this->waitForElementPresent("group_id"); | |
77 | ||
78 | // add to group | |
79 | $this->select("group_id", "label=$groupName"); | |
80 | $this->click("_qf_GroupContact_next"); | |
2af8120a | 81 | $this->waitForElementPresent('link=Remove'); |
6a488035 | 82 | |
8f737a72 | 83 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
6a488035 | 84 | |
6a488035 TO |
85 | $campaignTitle = "Campaign " . $title; |
86 | $this->type("title", $campaignTitle); | |
87 | ||
88 | // select the campaign type | |
89 | $this->select("campaign_type_id", "value=2"); | |
90 | ||
91 | // fill in the description | |
92 | $this->type("description", "This is a test campaign"); | |
93 | ||
94 | // include groups for the campaign | |
ba6f320f | 95 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
6a488035 TO |
96 | |
97 | // fill the end date for campaign | |
98 | $this->webtestFillDate("end_date", "+1 year"); | |
99 | ||
100 | // select campaign status | |
101 | $this->select("status_id", "value=2"); | |
102 | ||
103 | // click save | |
104 | $this->click("_qf_Campaign_upload-bottom"); | |
105 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
106 | ||
6c5f7368 | 107 | $this->waitForText('crm-notification-container', "Campaign $title"); |
6a488035 | 108 | |
39c74f87 RK |
109 | $this->waitForElementPresent("xpath=//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[3][text()='{$campaignTitle}']/../td[1]"); |
110 | $id = (int) $this->getText("xpath=//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[3][text()='{$campaignTitle}']/../td[1]"); | |
6a488035 TO |
111 | $this->activityAddTest($campaignTitle, $id); |
112 | } | |
113 | ||
4cbe18b8 EM |
114 | /** |
115 | * @param $campaignTitle | |
100fef9d | 116 | * @param int $id |
4cbe18b8 | 117 | */ |
6a488035 TO |
118 | function activityAddTest($campaignTitle, $id) { |
119 | // Adding Adding contact with randomized first name for test testContactContextActivityAdd | |
120 | // We're using Quick Add block on the main page for this. | |
121 | $firstName1 = substr(sha1(rand()), 0, 7); | |
122 | $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name"); | |
123 | $firstName2 = substr(sha1(rand()), 0, 7); | |
124 | $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name"); | |
125 | ||
6a488035 TO |
126 | $this->click("css=li#tab_activity a"); |
127 | ||
128 | // waiting for the activity dropdown to show up | |
129 | $this->waitForElementPresent("other_activity"); | |
130 | ||
131 | // Select the activity type from the activity dropdown | |
132 | $this->select("other_activity", "label=Meeting"); | |
133 | ||
134 | // waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
135 | // button at the end of this page to show up, to make sure it's fully loaded. | |
136 | $this->waitForElementPresent("_qf_Activity_upload"); | |
137 | ||
6a488035 | 138 | // ...and verifying if the page contains properly formatted display name for chosen contact. |
2af8120a AS |
139 | $this->waitForElementPresent("//*[@id='s2id_target_contact_id']"); |
140 | $this->assertElementContainsText('//*[@id="s2id_target_contact_id"]/ul/li[1]/div', 'Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__); | |
6a488035 TO |
141 | |
142 | // Now we're filling the "Assigned To" field. | |
143 | // Typing contact's name into the field (using typeKeys(), not type()!)... | |
2af8120a | 144 | $this->select2("assignee_contact_id", $firstName1, TRUE); |
6a488035 TO |
145 | |
146 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
2af8120a AS |
147 | $this->waitForElementPresent("//*[@id='s2id_assignee_contact_id']"); |
148 | $this->assertElementContainsText('//*[@id="s2id_assignee_contact_id"]/ul/li[1]/div', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__); | |
6a488035 TO |
149 | |
150 | // Since we're here, let's check if screen help is being displayed properly | |
2af8120a | 151 | //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee")); |
6a488035 TO |
152 | |
153 | // Putting the contents into subject field - assigning the text to variable, it'll come in handy later | |
154 | $subject = "This is subject of test activity being added through activity tab of contact summary screen."; | |
155 | // For simple input fields we can use field id as selector | |
156 | $this->type("subject", $subject); | |
157 | ||
158 | // select campaign | |
39c74f87 | 159 | $this->waitForElementPresent("campaign_id"); |
6a488035 TO |
160 | $this->click("campaign_id"); |
161 | $this->select("campaign_id", "value=$id"); | |
162 | ||
163 | $this->type("location", "Some location needs to be put in this field."); | |
164 | ||
165 | // Choosing the Date. | |
166 | // Please note that we don't want to put in fixed date, since | |
167 | // we want this test to work in the future and not fail because | |
168 | // of date being set in the past. Therefore, using helper webtestFillDateTime function. | |
169 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
170 | ||
171 | // Setting duration. | |
172 | $this->type("duration", "30"); | |
173 | ||
174 | // Putting in details. | |
175 | $this->type("details", "Really brief details information."); | |
176 | ||
177 | // Making sure that status is set to Scheduled (using value, not label). | |
178 | $this->select("status_id", "value=1"); | |
179 | ||
180 | // Setting priority. | |
181 | $this->select("priority_id", "value=1"); | |
182 | ||
183 | // Adding attachment | |
184 | // TODO TBD | |
185 | ||
186 | // Scheduling follow-up. | |
187 | $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header"); | |
188 | $this->select("followup_activity_type_id", "value=1"); | |
189 | $this->webtestFillDateTime('followup_date', '+1 month 11:10PM'); | |
190 | $this->type("followup_activity_subject", "This is subject of schedule follow-up activity"); | |
191 | ||
192 | // Clicking save. | |
2af8120a | 193 | $this->clickLink("_qf_Activity_upload",'link=View',FALSE); |
6a488035 TO |
194 | |
195 | // Is status message correct? | |
6c5f7368 | 196 | $this->waitForText('crm-notification-container', $subject); |
6a488035 | 197 | |
ba6f320f | 198 | $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
6a488035 TO |
199 | |
200 | // click through to the Activity view screen | |
39c74f87 | 201 | $this->click("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr[2]/td[8]/span/a[text()='View']"); |
6a488035 | 202 | $this->waitForElementPresent('_qf_Activity_cancel-bottom'); |
60ad1b50 | 203 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]"); |
76e86fd8 | 204 | |
6a488035 | 205 | // verify Activity created |
60ad1b50 | 206 | $this->verifyText("xpath=//form[@id='Activity']/div[2]/table/tbody/tr[5]/td[2]/span", $campaignTitle); |
6a488035 TO |
207 | } |
208 | } | |
209 |