commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / WebTest / Campaign / ActivityTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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->markTestSkipped('Skipping for now as it works fine locally.');
40 $this->webtestLogin('admin');
41
42 // Enable CiviCampaign module if necessary
43 $this->enableComponents(array('CiviCampaign'));
44
45 // add the required Drupal permission
46 $permissions = array('edit-2-administer-civicampaign');
47 $this->changePermissions($permissions);
48
49 // Log in as normal user
50 $this->webtestLogin();
51
52 // Create new group
53 $title = substr(sha1(rand()), 0, 7);
54 $groupName = $this->WebtestAddGroup();
55
56 // Adding contact
57 // We're using Quick Add block on the main page for this.
58 $firstName1 = substr(sha1(rand()), 0, 7);
59 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
60
61 // add contact to group
62 // visit group tab
63 $this->click("css=li#tab_group a");
64 $this->waitForElementPresent("group_id");
65
66 // add to group
67 $this->select("group_id", "label=$groupName");
68 $this->click("_qf_GroupContact_next");
69 $this->waitForElementPresent('link=Remove');
70
71 $firstName2 = substr(sha1(rand()), 0, 7);
72 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
73
74 // add contact to group
75 // visit group tab
76 $this->click("css=li#tab_group a");
77 $this->waitForElementPresent("group_id");
78
79 // add to group
80 $this->select("group_id", "label=$groupName");
81 $this->click("_qf_GroupContact_next");
82 $this->waitForElementPresent('link=Remove');
83
84 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
85
86 $campaignTitle = "Campaign " . $title;
87 $this->type("title", $campaignTitle);
88
89 // select the campaign type
90 $this->select("campaign_type_id", "value=2");
91
92 // fill in the description
93 $this->type("description", "This is a test campaign");
94
95 // include groups for the campaign
96 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
97
98 // fill the end date for campaign
99 $this->webtestFillDate("end_date", "+1 year");
100
101 // select campaign status
102 $this->select("status_id", "value=2");
103
104 // click save
105 $this->click("_qf_Campaign_upload-bottom");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107
108 $this->waitForText('crm-notification-container', "Campaign $title");
109
110 $this->waitForElementPresent("xpath=//div[@id='campaignList']/div/table/tbody//tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
111 $id = (int) $this->getText("xpath=//div[@id='campaignList']/div/table/tbody//tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
112 $this->activityAddTest($campaignTitle, $id);
113 }
114
115 /**
116 * @param $campaignTitle
117 * @param int $id
118 */
119 public function activityAddTest($campaignTitle, $id) {
120 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
121 // We're using Quick Add block on the main page for this.
122 $firstName1 = substr(sha1(rand()), 0, 7);
123 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
124 $firstName2 = substr(sha1(rand()), 0, 7);
125 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
126
127 $this->click("css=li#tab_activity a");
128
129 // waiting for the activity dropdown to show up
130 $this->waitForElementPresent("other_activity");
131
132 // Select the activity type from the activity dropdown
133 $this->select("other_activity", "label=Meeting");
134
135 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
136 // button at the end of this page to show up, to make sure it's fully loaded.
137 $this->waitForElementPresent("_qf_Activity_upload");
138
139 // ...and verifying if the page contains properly formatted display name for chosen contact.
140 $this->waitForElementPresent("//*[@id='s2id_target_contact_id']");
141 $this->assertElementContainsText('//*[@id="s2id_target_contact_id"]/ul/li[1]/div', 'Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__);
142
143 // Now we're filling the "Assigned To" field.
144 // Typing contact's name into the field (using typeKeys(), not type()!)...
145 $this->select2("assignee_contact_id", $firstName1, TRUE);
146
147 // ...and verifying if the page contains properly formatted display name for chosen contact.
148 $this->waitForElementPresent("//*[@id='s2id_assignee_contact_id']");
149 $this->assertElementContainsText('//*[@id="s2id_assignee_contact_id"]/ul/li[1]/div', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__);
150
151 // Since we're here, let's check if screen help is being displayed properly
152 //$this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
153
154 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
155 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
156 // For simple input fields we can use field id as selector
157 $this->type("subject", $subject);
158
159 // select campaign
160 $this->waitForElementPresent("campaign_id");
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("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr[1]/td[8]/span/a[1][text()='View']");
200
201 // click through to the Activity view screen
202 $this->click("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr[2]/td[8]/span/a[text()='View']");
203 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
204
205 // verify Activity created
206 $this->verifyText("xpath=//form[@id='Activity']/div[2]/table/tbody/tr[5]/td[2]/span", $campaignTitle);
207 }
208
209 }