whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Activity / StandaloneAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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_StandaloneAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testStandaloneActivityAdd() {
35 $this->webtestLogin();
36
37 // Adding Anderson, Anthony and Summerson, Samuel for testStandaloneActivityAdd test
38 // We're using Quick Add block on the main page for this.
39 $firstName1 = substr(sha1(rand()), 0, 7);
40 $this->webtestAddContact("$firstName1", "Anderson", $firstName1 . "@anderson.com");
41 $firstName2 = substr(sha1(rand()), 0, 7);
42 $this->webtestAddContact("$firstName2", "Summerson", $firstName2 . "@summerson.com");
43
44 $this->openCiviPage("activity", "reset=1&action=add&context=standalone", "_qf_Activity_upload");
45
46 // Select one of the options in Activity Type selector. Use option value, not label - since labels can be translated and test would fail
47 $this->select("activity_type_id", "value=1");
48
49 // We're filling in ajaxiefied "With Contact" field:
50 // We can not use id as selector for these input widgets. Use css selector, starting with the table row containing this field (which will have a unique class)
51 // Typing contact's name into the field (using typeKeys(), not type()!)...
52 $this->click("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1");
53 $this->type("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", "$firstName1");
54 $this->typeKeys("css=tr.crm-activity-form-block-target_contact_id input#token-input-contact_1", "$firstName1");
55
56 // ...waiting for drop down with results to show up...
57 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
58 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
59
60 // ...need to use mouseDownAt on first result (which is a li element), click does not work
61 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
62
63 // ...again, waiting for the box with contact name to show up (span with delete token class indicates that it's present)...
64 $this->waitForElementPresent("css=tr.crm-activity-form-block-target_contact_id td ul li span.token-input-delete-token-facebook");
65
66 //..and verifying if the page contains properly formatted display name for chosen contact.
67 $this->assertElementContainsText('css=tr.crm-activity-form-block-target_contact_id td ul li.token-input-token-facebook', "Anderson, $firstName1", 'Contact not found in line ' . __LINE__);
68
69 // Now we're doing the same for "Assigned To" field.
70 // Typing contact's name into the field (using typeKeys(), not type()!)...
71 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
72 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", "$firstName2");
73 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", "$firstName2");
74
75 // ...waiting for drop down with results to show up...
76 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
77 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
78
79 //..need to use mouseDownAt on first result (which is a li element), click does not work
80 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
81
82 // ...again, waiting for the box with contact name to show up...
83 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
84
85 // ...and verifying if the page contains properly formatted display name for chosen contact.
86 $this->assertElementContainsText('css=tr.crm-activity-form-block-assignee_contact_id td ul li.token-input-token-facebook', "Summerson, $firstName2", 'Contact not found in line ' . __LINE__);
87
88 // Since we're here, let's check of screen help is being displayed properly
89 $this->assertElementContainsText('css=tr.crm-activity-form-block-assignee_contact_id td span.description', 'You can optionally assign this activity to someone', 'Help text is missing.');
90
91 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
92 $subject = "This is subject of test activity being added through standalone screen.";
93 // For simple input fields we can use field id as selector
94 $this->type("subject", $subject);
95
96 $location = 'Some location needs to be put in this field.';
97 $this->type("location", $location);
98
99 // Choosing the Date.
100 // Please note that we don't want to put in fixed date, since
101 // we want this test to work in the future and not fail because
102 // of date being set in the past. Therefore, using helper webtestFillDate function.
103 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
104
105 // Setting duration.
106 $this->type("duration", "30");
107
108 // Putting in details.
109 $this->type("details", "Really brief details information.");
110
111 // Making sure that status is set to Scheduled (using value, not label).
112 $this->select("status_id", "value=1");
113
114 // Setting priority.
115 $this->select("priority_id", "value=1");
116
117 // Adding attachment
118 $this->click("css=.crm-activity-form-block-attachment div.crm-accordion-header");
119 //FIX ME: need to fix file uploading
120 //$this->waitForElementPresent("attachFile_1");
121 //$filePath = $this->webtestAttachFile( "attachFile_1" );
122
123 // Scheduling follow-up.
124 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
125 $this->select("followup_activity_type_id", "value=1");
126 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
127 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
128
129 // Clicking save.
130 $this->click("_qf_Activity_upload");
131 $this->waitForPageToLoad($this->getTimeoutMsec());
132
133 // Is status message correct?
134 $this->assertTrue($this->isTextPresent("Activity '$subject' has been saved."), "Status message didn't show up after saving!");
135
136 $this->openCiviPage("activity/search", "reset=1", "_qf_Search_refresh");
137
138 $this->type("sort_name", $firstName1);
139 $this->click("_qf_Search_refresh");
140 $this->waitForElementPresent("_qf_Search_next_print");
141
142 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[3]/td[9]/span/a[text()='View']");
143 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
144
145 $this->webtestVerifyTabularData(
146 array(
147 'Subject' => $subject,
148 'Location' => $location,
149 'Status' => 'Scheduled',
150 'Duration' => '30',
151 // Tough luck filling in WYSIWYG editor, so skipping verification for now.
152 //'Details' => 'Really brief details information.',
153 'Priority' => 'Urgent',
154 //'Current Attachment(s)' => basename($filePath)
155 ),
156 "/label"
157 );
158
159 $this->webtestVerifyTabularData(
160 array(
161 'With Contact' => "Anderson, {$firstName1}",
162 'Assigned To' => "Summerson, {$firstName2}",
163 )
164 );
165 }
166 }
167