INFRA-132 - Remove white space after an opening "(" or before a closing ")"
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / ActivityTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public 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->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
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
107 $this->waitForText('crm-notification-container', "Campaign $title");
108
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]");
111 $this->activityAddTest($campaignTitle, $id);
112 }
113
114 /**
115 * @param $campaignTitle
116 * @param int $id
117 */
118 public 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
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
138 // ...and verifying if the page contains properly formatted display name for chosen contact.
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__);
141
142 // Now we're filling the "Assigned To" field.
143 // Typing contact's name into the field (using typeKeys(), not type()!)...
144 $this->select2("assignee_contact_id", $firstName1, TRUE);
145
146 // ...and verifying if the page contains properly formatted display name for chosen contact.
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__);
149
150 // Since we're here, let's check if screen help is being displayed properly
151 //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
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
159 $this->waitForElementPresent("campaign_id");
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.
193 $this->clickLink("_qf_Activity_upload", 'link=View', FALSE);
194
195 // Is status message correct?
196 $this->waitForText('crm-notification-container', $subject);
197
198 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr[1]/td[8]/span/a[text()='View']");
199
200 // click through to the Activity view screen
201 $this->click("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr[2]/td[8]/span/a[text()='View']");
202 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
203 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]");
204
205 // verify Activity created
206 $this->verifyText("xpath=//form[@id='Activity']/div[2]/table/tbody/tr[5]/td[2]/span", $campaignTitle);
207 }
208 }