3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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->waitForPageToLoad($this->getTimeoutMsec());
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->waitForPageToLoad($this->getTimeoutMsec());
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[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
108 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
109 $this->activityAddTest($campaignTitle, $id);
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");
120 $this->click("css=li#tab_activity a");
122 // waiting for the activity dropdown to show up
123 $this->waitForElementPresent("other_activity");
125 // Select the activity type from the activity dropdown
126 $this->select("other_activity", "label=Meeting");
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");
132 // ...and verifying if the page contains properly formatted display name for chosen contact.
133 $this->assertElementContainsText('css=tr.crm-activity-form-block-target_contact_id td ul li.token-input-token-facebook','Anderson, ' . $firstName2, 'Contact not found in line ' . __LINE__
);
135 // Now we're filling the "Assigned To" field.
136 // Typing contact's name into the field (using typeKeys(), not type()!)...
137 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
138 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
139 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
141 // ...waiting for drop down with results to show up...
142 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
143 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
145 // ...need to use mouseDownAt on first result (which is a li element), click does not work
146 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
147 // ...again, waiting for the box with contact name to show up...
148 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
150 // ...and verifying if the page contains properly formatted display name for chosen contact.
151 $this->assertElementContainsText('css=tr.crm-activity-form-block-assignee_contact_id td ul li.token-input-token-facebook', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__
);
153 // Since we're here, let's check if screen help is being displayed properly
154 // $this->assertTrue($this->isTextPresent("A copy of this activity will be emailed to each Assignee"));
156 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
157 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
158 // For simple input fields we can use field id as selector
159 $this->type("subject", $subject);
162 $this->click("campaign_id");
163 $this->select("campaign_id", "value=$id");
165 $this->type("location", "Some location needs to be put in this field.");
167 // Choosing the Date.
168 // Please note that we don't want to put in fixed date, since
169 // we want this test to work in the future and not fail because
170 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
171 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
174 $this->type("duration", "30");
176 // Putting in details.
177 $this->type("details", "Really brief details information.");
179 // Making sure that status is set to Scheduled (using value, not label).
180 $this->select("status_id", "value=1");
183 $this->select("priority_id", "value=1");
188 // Scheduling follow-up.
189 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
190 $this->select("followup_activity_type_id", "value=1");
191 $this->webtestFillDateTime('followup_date', '+1 month 11:10PM');
192 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
195 $this->clickLink("_qf_Activity_upload");
197 // Is status message correct?
198 $this->waitForText('crm-notification-container', $subject);
200 $this->waitForElementPresent("
201 xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
203 // click through to the Activity view screen
204 $this->click("xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[1]/td[8]/span/a[text()='View']");
205 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
207 // verify Activity created
208 $this->verifyText("xpath=id('Activity')/div[2]/table[1]/tbody/tr[5]/td[2]", preg_quote($campaignTitle));