Merge remote branch 'canonical/master' into merge-forward
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / ActivityTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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_Campaign_ActivityTest
31 */
32 class WebTest_Campaign_ActivityTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
40
41 // Enable CiviCampaign module if necessary
42 $this->enableComponents(array('CiviCampaign'));
43
44 // add the required Drupal permission
45 $permissions = array('edit-2-administer-civicampaign');
46 $this->changePermissions($permissions);
47
48 // Log in as normal user
49 $this->webtestLogin();
50
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");
68 $this->waitForElementPresent('link=Remove');
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");
81 $this->waitForElementPresent('link=Remove');
82
83 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
84
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
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
97 $this->click("add");
98
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
101
102 // select campaign status
103 $this->select("status_id", "value=2");
104
105 // click save
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108
109 $this->waitForText('crm-notification-container', "Campaign $title");
110
111 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
112 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
113 $this->activityAddTest($campaignTitle, $id);
114 }
115
116 /**
117 * @param $campaignTitle
118 * @param $id
119 */
120 function activityAddTest($campaignTitle, $id) {
121 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
122 // We're using Quick Add block on the main page for this.
123 $firstName1 = substr(sha1(rand()), 0, 7);
124 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
125 $firstName2 = substr(sha1(rand()), 0, 7);
126 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
127
128 $this->click("css=li#tab_activity a");
129
130 // waiting for the activity dropdown to show up
131 $this->waitForElementPresent("other_activity");
132
133 // Select the activity type from the activity dropdown
134 $this->select("other_activity", "label=Meeting");
135
136 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
137 // button at the end of this page to show up, to make sure it's fully loaded.
138 $this->waitForElementPresent("_qf_Activity_upload");
139
140 // ...and verifying if the page contains properly formatted display name for chosen contact.
141 $this->waitForElementPresent("//*[@id='s2id_target_contact_id']");
142 $this->assertElementContainsText('//*[@id="s2id_target_contact_id"]/ul/li[1]/div', 'Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__);
143
144 // Now we're filling the "Assigned To" field.
145 // Typing contact's name into the field (using typeKeys(), not type()!)...
146 $this->select2("assignee_contact_id", $firstName1, TRUE);
147
148 // ...and verifying if the page contains properly formatted display name for chosen contact.
149 $this->waitForElementPresent("//*[@id='s2id_assignee_contact_id']");
150 $this->assertElementContainsText('//*[@id="s2id_assignee_contact_id"]/ul/li[1]/div', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__);
151
152 // Since we're here, let's check if screen help is being displayed properly
153 //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
154
155 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
156 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
157 // For simple input fields we can use field id as selector
158 $this->type("subject", $subject);
159
160 // select campaign
161 $this->click("campaign_id");
162 $this->select("campaign_id", "value=$id");
163
164 $this->type("location", "Some location needs to be put in this field.");
165
166 // Choosing the Date.
167 // Please note that we don't want to put in fixed date, since
168 // we want this test to work in the future and not fail because
169 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
170 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
171
172 // Setting duration.
173 $this->type("duration", "30");
174
175 // Putting in details.
176 $this->type("details", "Really brief details information.");
177
178 // Making sure that status is set to Scheduled (using value, not label).
179 $this->select("status_id", "value=1");
180
181 // Setting priority.
182 $this->select("priority_id", "value=1");
183
184 // Adding attachment
185 // TODO TBD
186
187 // Scheduling follow-up.
188 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
189 $this->select("followup_activity_type_id", "value=1");
190 $this->webtestFillDateTime('followup_date', '+1 month 11:10PM');
191 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
192
193 // Clicking save.
194 $this->clickLink("_qf_Activity_upload",'link=View',FALSE);
195
196 // Is status message correct?
197 $this->waitForText('crm-notification-container', $subject);
198
199 $this->waitForElementPresent("
200 xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
201
202 // click through to the Activity view screen
203 $this->click("xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
204 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
205
206 // verify Activity created
207 $this->verifyText("xpath=id('Activity')/div[2]/table[1]/tbody/tr[5]/td[2]/span", preg_quote($campaignTitle));
208 }
209 }
210