3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Campaign_ActivityTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCreateCampaign() {
35 $this->webtestLogin('admin');
37 // Enable CiviCampaign module if necessary
38 $this->enableComponents(array('CiviCampaign'));
40 // add the required Drupal permission
41 $permissions = array('edit-2-administer-civicampaign');
42 $this->changePermissions($permissions);
44 // Log in as normal user
45 $this->webtestLogin();
48 $title = substr(sha1(rand()), 0, 7);
49 $groupName = $this->WebtestAddGroup();
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");
56 // add contact to group
58 $this->click("css=li#tab_group a");
59 $this->waitForElementPresent("group_id");
62 $this->select("group_id", "label=$groupName");
63 $this->click("_qf_GroupContact_next");
64 $this->waitForElementPresent('link=Remove');
66 $firstName2 = substr(sha1(rand()), 0, 7);
67 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
69 // add contact to group
71 $this->click("css=li#tab_group a");
72 $this->waitForElementPresent("group_id");
75 $this->select("group_id", "label=$groupName");
76 $this->click("_qf_GroupContact_next");
77 $this->waitForElementPresent('link=Remove');
79 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
81 $campaignTitle = "Campaign " . $title;
82 $this->type("title", $campaignTitle);
84 // select the campaign type
85 $this->select("campaign_type_id", "value=2");
87 // fill in the description
88 $this->type("description", "This is a test campaign");
90 // include groups for the campaign
91 $this->addSelection("includeGroups-f", "label=$groupName");
92 $this->click("//option[@value=4]");
95 // fill the end date for campaign
96 $this->webtestFillDate("end_date", "+1 year");
98 // select campaign status
99 $this->select("status_id", "value=2");
102 $this->click("_qf_Campaign_upload-bottom");
103 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $this->waitForText('crm-notification-container', "Campaign $title");
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);
113 * @param $campaignTitle
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");
124 $this->click("css=li#tab_activity a");
126 // waiting for the activity dropdown to show up
127 $this->waitForElementPresent("other_activity");
129 // Select the activity type from the activity dropdown
130 $this->select("other_activity", "label=Meeting");
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");
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__
);
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);
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__
);
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"));
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);
157 $this->click("campaign_id");
158 $this->select("campaign_id", "value=$id");
160 $this->type("location", "Some location needs to be put in this field.");
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');
169 $this->type("duration", "30");
171 // Putting in details.
172 $this->type("details", "Really brief details information.");
174 // Making sure that status is set to Scheduled (using value, not label).
175 $this->select("status_id", "value=1");
178 $this->select("priority_id", "value=1");
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");
190 $this->clickLink("_qf_Activity_upload",'link=View',FALSE);
192 // Is status message correct?
193 $this->waitForText('crm-notification-container', $subject);
195 $this->waitForElementPresent("
196 xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
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');
202 // verify Activity created
203 $this->verifyText("xpath=id('Activity')/div[2]/table[1]/tbody/tr[5]/td[2]/span", preg_quote($campaignTitle));