CRM-14043 - cid=0 contribution form giving contribution to logged in user
[civicrm-core.git] / tests / phpunit / WebTest / Activity / ContactContextAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 class WebTest_Activity_ContactContextAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testContactContextActivityAdd() {
35 $this->webtestLogin();
36
37 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
38 // We're using Quick Add block on the main page for this.
39 $firstName1 = substr(sha1(rand()), 0, 7);
40 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
41 $firstName2 = substr(sha1(rand()), 0, 7);
42 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
43
44 $this->click("css=li#tab_activity a");
45
46 // waiting for the activity dropdown to show up
47 $this->waitForElementPresent("other_activity");
48
49 // Select the activity type from the activity dropdown
50 $this->select("other_activity", "label=Meeting");
51 $this->waitForPageToLoad($this->getTimeoutMsec());
52
53 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
54 // button at the end of this page to show up, to make sure it's fully loaded.
55 $this->waitForElementPresent("_qf_Activity_upload");
56
57 // ...and verifying if the page contains properly formatted display name for chosen contact.
58 $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__);
59
60 // Now we're filling the "Assigned To" field.
61 // Typing contact's name into the field (using typeKeys(), not type()!)...
62 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
63 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
64 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
65
66 // ...waiting for drop down with results to show up...
67 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
68 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
69
70 // ...need to use mouseDownAt on first result (which is a li element), click does not work
71 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
72
73 // ...again, waiting for the box with contact name to show up...
74 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
75
76 // ...and verifying if the page contains properly formatted display name for chosen contact.
77 $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__);
78
79 // Since we're here, let's check if screen help is being displayed properly
80
81 $this->assertElementContainsText('css=tr.crm-activity-form-block-assignee_contact_id', 'You can optionally assign this activity to someone', 'Help text is missing.');
82 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
83 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
84 // For simple input fields we can use field id as selector
85 $this->type("subject", $subject);
86 $this->type("location", "Some location needs to be put in this field.");
87
88 // Choosing the Date.
89 // Please note that we don't want to put in fixed date, since
90 // we want this test to work in the future and not fail because
91 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
92 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
93
94 // Setting duration.
95 $this->type("duration", "30");
96
97 // Putting in details.
98 $this->type("details", "Really brief details information.");
99
100 // Making sure that status is set to Scheduled (using value, not label).
101 $this->select("status_id", "value=1");
102
103 // Setting priority.
104 $this->select("priority_id", "value=1");
105
106 // Adding attachment
107 // TODO TBD
108
109 // Scheduling follow-up.
110 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
111 $this->select("followup_activity_type_id", "value=1");
112 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
113 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
114
115 // Clicking save.
116 $this->click("_qf_Activity_upload");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118
119 // Is status message correct?
120 $this->waitForText('crm-notification-container', $subject);
121
122 $this->waitForElementPresent(
123 "xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[2]/td[8]/span/a[text()='View']");
124
125 // click through to the Activity view screen
126 $this->click("xpath=//table[@id='contact-activity-selector-activity']//tbody//tr[2]/td[8]/span/a[text()='View']");
127 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
128
129 // verify Activity created
130 $this->webtestVerifyTabularData(
131 array(
132 'Subject' => $subject,
133 'Location' => 'Some location needs to be put in this field.',
134 'Status' => 'Scheduled',
135 'Duration' => '30',
136 // Tough luck filling in WYSIWYG editor, so skipping verification for now.
137 //'Details' => 'Really brief details information.',
138 'Priority' => 'Urgent',
139 ),
140 "/label"
141 );
142
143 $this->webtestVerifyTabularData(
144 array(
145 'With Contact' => "Anderson, {$firstName2}",
146 'Assigned To' => "Summerson, {$firstName1}",
147 )
148 );
149 }
150
151 function testSeparateActivityForMultiTargetContacts() {
152 $this->webtestLogin();
153
154 //creating contacts
155 $firstName1 = substr(sha1(rand()), 0, 7);
156 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
157 $firstName2 = substr(sha1(rand()), 0, 7);
158 $this->webtestAddContact($firstName2, "Andersonnn", $firstName2 . "@anderson.name");
159 $firstName3 = substr(sha1(rand()), 0, 7);
160 $this->webtestAddContact($firstName3, "Anderson", $firstName3 . "@andersonnn.name");
161
162 $this->click("css=li#tab_activity a");
163
164 // waiting for the activity dropdown to show up
165 $this->waitForElementPresent("other_activity");
166
167 // Select the activity type from the activity dropdown
168 $this->select("other_activity", "label=Meeting");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
170
171 // ...and verifying if the page contains properly formatted display name for chosen contact.
172 $this->waitForText('css=tr.crm-activity-form-block-target_contact_id td ul li.token-input-token-facebook', 'Anderson, ' . $firstName3, 'Contact not found in line ' . __LINE__);
173
174 //filling the second target Contact
175 $this->click("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1");
176 $this->type("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", $firstName1);
177 $this->typeKeys("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", $firstName1);
178
179 // ...waiting for drop down with results to show up...
180 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
181 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
182
183 // ...need to use mouseDownAt on first result (which is a li element), click does not work
184 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
185
186 // ...again, waiting for the box with contact name to show up...
187 $this->waitForElementPresent("css=tr.crm-activity-form-block-target_contact_id td ul li span.token-input-delete-token-facebook");
188
189 // ...and verifying if the page contains properly formatted display name for chosen contact.
190 $this->waitForText('css=tr.crm-activity-form-block-target_contact_id td ul', 'Summerson, ' . $firstName1, 'Contact not found in line ' . __LINE__);
191
192 //filling the third target contact
193 $this->click("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1");
194 $this->type("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", $firstName2);
195 $this->typeKeys("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", $firstName2);
196
197 // ...waiting for drop down with results to show up...
198 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
199 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
200
201 // ...need to use mouseDownAt on first result (which is a li element), click does not work
202 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
203
204 // ...again, waiting for the box with contact name to show up...
205 $this->waitForElementPresent("css=tr.crm-activity-form-block-target_contact_id td ul li span.token-input-delete-token-facebook");
206
207 // ...and verifying if the page contains properly formatted display name for chosen contact.
208 $this->waitForText('css=tr.crm-activity-form-block-target_contact_id td ul', 'Andersonnn, ' . $firstName2, 'Contact not found in line ' . __LINE__);
209
210 //check the checkbox to create a separate activity for the selected target contacts
211 $this->check('is_multi_activity');
212
213 $subject = "This is subject of test activity for creating a separate activity for contacts {$firstName1},{$firstName2} and {$firstName3}.";
214 $this->type("subject", $subject);
215
216 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
217 $this->select("status_id", "value=1");
218
219 // Clicking save.
220 $this->clickLink('_qf_Activity_upload');
221
222 // Is status message correct?
223 $this->waitForText('crm-notification-container', $subject);
224
225 //activity search page
226 $this->openCiviPage('activity/search', 'reset=1');
227
228 $this->type('activity_subject', $subject);
229
230 $this->clickLink('_qf_Search_refresh');
231
232 $targetContacts = array("Summerson, ". $firstName1, "Andersonnn, ". $firstName2, "Anderson, ". $firstName3 );
233
234 //check whether separate activities are created for the target contacts
235 foreach ($targetContacts as $contact) {
236 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody//tr/td[5]/a[text()='$contact']"));
237 }
238 }
239 }
240