remove duplicate assignments
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / ActivityTest.php
CommitLineData
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
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Campaign_ActivityTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCreateCampaign() {
42daf119 35 $this->webtestLogin('admin');
6a488035
TO
36
37 // Enable CiviCampaign module if necessary
8f737a72 38 $this->enableComponents(array('CiviCampaign'));
6a488035
TO
39
40 // add the required Drupal permission
41 $permissions = array('edit-2-administer-civicampaign');
42 $this->changePermissions($permissions);
43
42daf119
CW
44 // Log in as normal user
45 $this->webtestLogin();
46
6a488035
TO
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");
2af8120a 64 $this->waitForElementPresent('link=Remove');
6a488035
TO
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");
2af8120a 77 $this->waitForElementPresent('link=Remove');
6a488035 78
8f737a72 79 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
6a488035 80
6a488035
TO
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
6c5f7368 105 $this->waitForText('crm-notification-container', "Campaign $title");
6a488035 106
1d4d99e9 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]");
6a488035
TO
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
6a488035
TO
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
6a488035 132 // ...and verifying if the page contains properly formatted display name for chosen contact.
2af8120a
AS
133 $this->waitForElementPresent("//*[@id='s2id_target_contact_id']");
134 $this->assertElementContainsText('//*[@id="s2id_target_contact_id"]/ul/li[1]/div', 'Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__);
6a488035
TO
135
136 // Now we're filling the "Assigned To" field.
137 // Typing contact's name into the field (using typeKeys(), not type()!)...
2af8120a 138 $this->select2("assignee_contact_id", $firstName1, TRUE);
6a488035
TO
139
140 // ...and verifying if the page contains properly formatted display name for chosen contact.
2af8120a
AS
141 $this->waitForElementPresent("//*[@id='s2id_assignee_contact_id']");
142 $this->assertElementContainsText('//*[@id="s2id_assignee_contact_id"]/ul/li[1]/div', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__);
6a488035
TO
143
144 // Since we're here, let's check if screen help is being displayed properly
2af8120a 145 //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
6a488035
TO
146
147 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
148 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
149 // For simple input fields we can use field id as selector
150 $this->type("subject", $subject);
151
152 // select campaign
153 $this->click("campaign_id");
154 $this->select("campaign_id", "value=$id");
155
156 $this->type("location", "Some location needs to be put in this field.");
157
158 // Choosing the Date.
159 // Please note that we don't want to put in fixed date, since
160 // we want this test to work in the future and not fail because
161 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
162 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
163
164 // Setting duration.
165 $this->type("duration", "30");
166
167 // Putting in details.
168 $this->type("details", "Really brief details information.");
169
170 // Making sure that status is set to Scheduled (using value, not label).
171 $this->select("status_id", "value=1");
172
173 // Setting priority.
174 $this->select("priority_id", "value=1");
175
176 // Adding attachment
177 // TODO TBD
178
179 // Scheduling follow-up.
180 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
181 $this->select("followup_activity_type_id", "value=1");
182 $this->webtestFillDateTime('followup_date', '+1 month 11:10PM');
183 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
184
185 // Clicking save.
2af8120a 186 $this->clickLink("_qf_Activity_upload",'link=View',FALSE);
6a488035
TO
187
188 // Is status message correct?
6c5f7368 189 $this->waitForText('crm-notification-container', $subject);
6a488035 190
fbcfc163 191 $this->waitForElementPresent("
192 xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
193
194 // click through to the Activity view screen
fbcfc163 195 $this->click("xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
6a488035 196 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
76e86fd8 197
6a488035 198 // verify Activity created
1d4d99e9 199 $this->verifyText("xpath=id('Activity')/div[2]/table[1]/tbody/tr[5]/td[2]/span", preg_quote($campaignTitle));
6a488035
TO
200 }
201}
202