3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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';
30 * Class WebTest_Campaign_ActivityTest
32 class WebTest_Campaign_ActivityTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testCreateCampaign() {
39 $this->markTestSkipped('Skipping for now as it works fine locally.');
40 $this->webtestLogin('admin');
42 // Enable CiviCampaign module if necessary
43 $this->enableComponents(array('CiviCampaign'));
45 // add the required Drupal permission
46 $permissions = array('edit-2-administer-civicampaign');
47 $this->changePermissions($permissions);
49 // Log in as normal user
50 $this->webtestLogin();
53 $title = substr(sha1(rand()), 0, 7);
54 $groupName = $this->WebtestAddGroup();
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");
61 // add contact to group
63 $this->click("css=li#tab_group a");
64 $this->waitForElementPresent("group_id");
67 $this->select("group_id", "label=$groupName");
68 $this->click("_qf_GroupContact_next");
69 $this->waitForElementPresent('link=Remove');
71 $firstName2 = substr(sha1(rand()), 0, 7);
72 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
74 // add contact to group
76 $this->click("css=li#tab_group a");
77 $this->waitForElementPresent("group_id");
80 $this->select("group_id", "label=$groupName");
81 $this->click("_qf_GroupContact_next");
82 $this->waitForElementPresent('link=Remove');
84 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
86 $campaignTitle = "Campaign " . $title;
87 $this->type("title", $campaignTitle);
89 // select the campaign type
90 $this->select("campaign_type_id", "value=2");
92 // fill in the description
93 $this->type("description", "This is a test campaign");
95 // include groups for the campaign
96 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
98 // fill the end date for campaign
99 $this->webtestFillDate("end_date", "+1 year");
101 // select campaign status
102 $this->select("status_id", "value=2");
105 $this->click("_qf_Campaign_upload-bottom");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
108 $this->waitForText('crm-notification-container', "Campaign $title");
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);
116 * @param $campaignTitle
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");
127 $this->click("css=li#tab_activity a");
129 // waiting for the activity dropdown to show up
130 $this->waitForElementPresent("other_activity");
132 // Select the activity type from the activity dropdown
133 $this->select("other_activity", "label=Meeting");
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");
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__
);
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);
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__
);
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"));
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);
160 $this->waitForElementPresent("campaign_id");
161 $this->click("campaign_id");
162 $this->select("campaign_id", "value=$id");
164 $this->type("location", "Some location needs to be put in this field.");
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');
173 $this->type("duration", "30");
175 // Putting in details.
176 $this->type("details", "Really brief details information.");
178 // Making sure that status is set to Scheduled (using value, not label).
179 $this->select("status_id", "value=1");
182 $this->select("priority_id", "value=1");
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");
194 $this->clickLink("_qf_Activity_upload", 'link=View', FALSE);
196 // Is status message correct?
197 $this->waitForText('crm-notification-container', $subject);
199 $this->waitForElementPresent("xpath=//div[@class='crm-activity-selector-activity']/div[2]/table/tbody/tr[2]/td[8]/span[1]/a[1][text()='View']");
201 // click through to the Activity view screen
202 $this->click("xpath=//div[@class='crm-activity-selector-activity']/div[2]/table/tbody/tr[2]/td[8]/span[1]/a[1][text()='View']");
203 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Done')]");
205 // verify Activity created
206 $this->waitForAjaxContent();
207 $this->verifyText("xpath=//form[@id='Activity']/div[2]/table/tbody/tr[5]/td[2]/span", $campaignTitle);