add missing comments - tests directory
[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 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->waitForElementPresent('link=Remove');
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->waitForElementPresent('link=Remove');
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[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
108 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
109 $this->activityAddTest($campaignTitle, $id);
110 }
111
112 /**
113 * @param $campaignTitle
114 * @param $id
115 */
116 function activityAddTest($campaignTitle, $id) {
117 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
118 // We're using Quick Add block on the main page for this.
119 $firstName1 = substr(sha1(rand()), 0, 7);
120 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
121 $firstName2 = substr(sha1(rand()), 0, 7);
122 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
123
124 $this->click("css=li#tab_activity a");
125
126 // waiting for the activity dropdown to show up
127 $this->waitForElementPresent("other_activity");
128
129 // Select the activity type from the activity dropdown
130 $this->select("other_activity", "label=Meeting");
131
132 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
133 // button at the end of this page to show up, to make sure it's fully loaded.
134 $this->waitForElementPresent("_qf_Activity_upload");
135
136 // ...and verifying if the page contains properly formatted display name for chosen contact.
137 $this->waitForElementPresent("//*[@id='s2id_target_contact_id']");
138 $this->assertElementContainsText('//*[@id="s2id_target_contact_id"]/ul/li[1]/div', 'Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__);
139
140 // Now we're filling the "Assigned To" field.
141 // Typing contact's name into the field (using typeKeys(), not type()!)...
142 $this->select2("assignee_contact_id", $firstName1, TRUE);
143
144 // ...and verifying if the page contains properly formatted display name for chosen contact.
145 $this->waitForElementPresent("//*[@id='s2id_assignee_contact_id']");
146 $this->assertElementContainsText('//*[@id="s2id_assignee_contact_id"]/ul/li[1]/div', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__);
147
148 // Since we're here, let's check if screen help is being displayed properly
149 //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
150
151 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
152 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
153 // For simple input fields we can use field id as selector
154 $this->type("subject", $subject);
155
156 // select campaign
157 $this->click("campaign_id");
158 $this->select("campaign_id", "value=$id");
159
160 $this->type("location", "Some location needs to be put in this field.");
161
162 // Choosing the Date.
163 // Please note that we don't want to put in fixed date, since
164 // we want this test to work in the future and not fail because
165 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
166 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
167
168 // Setting duration.
169 $this->type("duration", "30");
170
171 // Putting in details.
172 $this->type("details", "Really brief details information.");
173
174 // Making sure that status is set to Scheduled (using value, not label).
175 $this->select("status_id", "value=1");
176
177 // Setting priority.
178 $this->select("priority_id", "value=1");
179
180 // Adding attachment
181 // TODO TBD
182
183 // Scheduling follow-up.
184 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
185 $this->select("followup_activity_type_id", "value=1");
186 $this->webtestFillDateTime('followup_date', '+1 month 11:10PM');
187 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
188
189 // Clicking save.
190 $this->clickLink("_qf_Activity_upload",'link=View',FALSE);
191
192 // Is status message correct?
193 $this->waitForText('crm-notification-container', $subject);
194
195 $this->waitForElementPresent("
196 xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
197
198 // click through to the Activity view screen
199 $this->click("xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
200 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
201
202 // verify Activity created
203 $this->verifyText("xpath=id('Activity')/div[2]/table[1]/tbody/tr[5]/td[2]/span", preg_quote($campaignTitle));
204 }
205 }
206