whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Generic / CheckDashboardTest.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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Generic_CheckDashboardTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCheckDashboardElements() {
36
37 $this->webtestLogin();
38
39 $this->open($this->sboxPath . "civicrm");
40 $this->waitForPageToLoad($this->getTimeoutMsec());
41 $this->assertTrue($this->isElementPresent("link=Configure Your Dashboard"));
42
43 // Test Activities widget enable and full screen.
44 $this->_testActivityDashlet();
45
46 // More dashlet tests can be added here using the functions modeled below
47 }
48
49 function _testAddDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle) {
50 // Check if desired widget is already loaded on dashboard and remove it if it is so we can test adding it.
51 // Because it tends to cause problems, all uses of sleep() must be justified in comments
52 // Sleep should never be used for wait for anything to load from the server
53 // Justification for this instance: FIXME
54 sleep(10);
55 if ($this->isElementPresent($widgetEnabledSelector)) {
56 $this->_testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle);
57 };
58 $this->click("link=Configure Your Dashboard");
59 $this->waitForElementPresent("dashlets-header-col-0");
60 $this->mouseDownAt($widgetConfigureID, "");
61 // Because it tends to cause problems, all uses of sleep() must be justified in comments
62 // Sleep should never be used for wait for anything to load from the server
63 // Justification for this instance: FIXME
64 sleep(3);
65 $this->mouseMoveAt("existing-dashlets-col-1", "");
66 // Because it tends to cause problems, all uses of sleep() must be justified in comments
67 // Sleep should never be used for wait for anything to load from the server
68 // Justification for this instance: FIXME
69 sleep(3);
70 $this->mouseUpAt("existing-dashlets-col-1", "");
71 // Because it tends to cause problems, all uses of sleep() must be justified in comments
72 // Sleep should never be used for wait for anything to load from the server
73 // Justification for this instance: FIXME
74 sleep(3);
75 $this->click("link=Done");
76 $this->waitForElementPresent("link=Configure Your Dashboard");
77 $this->waitForTextPresent("$widgetTitle");
78
79 // click Full Screen icon and test full screen container
80 $this->waitForElementPresent("css=li#widget-2 a.fullscreen-icon");
81 $this->click("css=li#widget-2 a.fullscreen-icon");
82 $this->waitForElementPresent("ui-id-1");
83 $this->assertTrue($this->isTextPresent($widgetTitle));
84 // Because it tends to cause problems, all uses of sleep() must be justified in comments
85 // Sleep should never be used for wait for anything to load from the server
86 // Justification for this instance: FIXME
87 sleep(5);
88 $this->click("link=close");
89 }
90
91 function _testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector) {
92 $this->click("link=Configure Your Dashboard");
93 $this->waitForElementPresent("dashlets-header-col-0");
94 $this->mouseDownAt("{$widgetConfigureID}", "");
95 // Because it tends to cause problems, all uses of sleep() must be justified in comments
96 // Sleep should never be used for wait for anything to load from the server
97 // Justification for this instance: FIXME
98 sleep(1);
99 $this->mouseMoveAt("available-dashlets", "");
100 // Because it tends to cause problems, all uses of sleep() must be justified in comments
101 // Sleep should never be used for wait for anything to load from the server
102 // Justification for this instance: FIXME
103 sleep(1);
104 $this->mouseUpAt("available-dashlets", "");
105 // Because it tends to cause problems, all uses of sleep() must be justified in comments
106 // Sleep should never be used for wait for anything to load from the server
107 // Justification for this instance: FIXME
108 sleep(1);
109 $this->click("link=Done");
110 $this->waitForElementPresent("link=Configure Your Dashboard");
111 // giving time for activity widget to load (and make sure it did NOT)
112 // Because it tends to cause problems, all uses of sleep() must be justified in comments
113 // Sleep should never be used for wait for anything to load from the server
114 // Justification for this instance: FIXME
115 sleep(10);
116 $this->assertFalse($this->isElementPresent($widgetEnabledSelector));
117 }
118
119 function _testActivityDashlet() {
120 // Add an activity that will show up in the widget
121 $this->WebtestAddActivity();
122 $widgetTitle = "Activities";
123 $widgetEnabledSelector = "contact-activity-selector-dashlet_wrapper";
124 $widgetConfigureID = "2-0";
125
126 // now add the widget
127 $this->open($this->sboxPath . "civicrm");
128 $this->waitForPageToLoad($this->getTimeoutMsec());
129 $this->waitForTextPresent("Configure Your Dashboard");
130 $this->_testAddDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle);
131
132 // If CiviCase enabled, click 'more' link for context menu pop-up in the widget selector
133 if ($this->isElementPresent("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[8]/span[text()='more ']")) {
134 // click 'Delete Activity' link
135 $this->click("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[8]/span[text()='more ']/ul/li[2]/a[text()='Delete']");
136 }
137 else {
138 // click 'Delete Activity' link
139 $this->click("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[9]/span//a[text()='Delete']");
140 }
141 $this->waitForPageToLoad($this->getTimeoutMsec());
142 $this->waitForElementPresent("_qf_Activity_next-bottom");
143 $this->assertTrue($this->isTextPresent("Are you sure you want to delete"));
144 $this->click("_qf_Activity_next-bottom");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146 $this->assertTrue($this->isTextPresent("Selected Activity has been deleted successfully."));
147 // FIXMED: Currently there's a bug, dashboard context is ignored after delete so we should already be back on home dash.
148 // Issue filed: CRM-
149 // $this->assertTrue($this->isTextPresent("Configure Your Dashboard");
150 $this->open($this->sboxPath . "civicrm");
151 $this->waitForPageToLoad($this->getTimeoutMsec());
152 $this->waitForTextPresent("Configure Your Dashboard");
153
154 // cleanup by removing the widget
155 $this->_testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector);
156 }
157 }
158