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