620f45808ed26364bb02cf350f83c1837a39c649
[civicrm-core.git] / tests / phpunit / WebTest / Generic / CheckDashboardTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 /**
50 * @param $widgetConfigureID
51 * @param $widgetEnabledSelector
52 * @param $widgetTitle
53 */
54 function _testAddDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle) {
55 // Check if desired widget is already loaded on dashboard and remove it if it is so we can test adding it.
56 // Because it tends to cause problems, all uses of sleep() must be justified in comments
57 // Sleep should never be used for wait for anything to load from the server
58 // Justification for this instance: FIXME
59 sleep(10);
60 if ($this->isElementPresent($widgetEnabledSelector)) {
61 $this->_testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle);
62 };
63 $this->click("link=Configure Your Dashboard");
64 $this->waitForElementPresent("dashlets-header-col-0");
65 $this->mouseDownAt($widgetConfigureID, "");
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->mouseMoveAt("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->mouseUpAt("existing-dashlets-col-1", "");
76 // Because it tends to cause problems, all uses of sleep() must be justified in comments
77 // Sleep should never be used for wait for anything to load from the server
78 // Justification for this instance: FIXME
79 sleep(3);
80 $this->click("link=Done");
81 $this->waitForElementPresent("link=Configure Your Dashboard");
82 $this->waitForTextPresent("$widgetTitle");
83
84 // click Full Screen icon and test full screen container
85 $this->waitForElementPresent("css=li#widget-2 a.fullscreen-icon");
86 $this->click("css=li#widget-2 a.fullscreen-icon");
87 $this->waitForElementPresent("ui-id-1");
88 $this->waitForTextPresent("$widgetTitle");
89 // Because it tends to cause problems, all uses of sleep() must be justified in comments
90 // Sleep should never be used for wait for anything to load from the server
91 // Justification for this instance: FIXME
92 sleep(5);
93 $this->click("xpath=//*[@class='ui-button-text'][contains(text(), 'close')]");
94 }
95
96 /**
97 * @param $widgetConfigureID
98 * @param $widgetEnabledSelector
99 */
100 function _testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector) {
101 $this->click("link=Configure Your Dashboard");
102 $this->waitForElementPresent("dashlets-header-col-0");
103 $this->mouseDownAt("{$widgetConfigureID}", "");
104 // Because it tends to cause problems, all uses of sleep() must be justified in comments
105 // Sleep should never be used for wait for anything to load from the server
106 // Justification for this instance: FIXME
107 sleep(1);
108 $this->mouseMoveAt("available-dashlets", "");
109 // Because it tends to cause problems, all uses of sleep() must be justified in comments
110 // Sleep should never be used for wait for anything to load from the server
111 // Justification for this instance: FIXME
112 sleep(1);
113 $this->mouseUpAt("available-dashlets", "");
114 // Because it tends to cause problems, all uses of sleep() must be justified in comments
115 // Sleep should never be used for wait for anything to load from the server
116 // Justification for this instance: FIXME
117 sleep(1);
118 $this->click("link=Done");
119 $this->waitForElementPresent("link=Configure Your Dashboard");
120 // giving time for activity widget to load (and make sure it did NOT)
121 // Because it tends to cause problems, all uses of sleep() must be justified in comments
122 // Sleep should never be used for wait for anything to load from the server
123 // Justification for this instance: FIXME
124 sleep(10);
125 $this->assertFalse($this->isElementPresent($widgetEnabledSelector));
126 }
127
128 function _testActivityDashlet() {
129 // Add an activity that will show up in the widget
130 $this->WebtestAddActivity();
131 $widgetTitle = "Activities";
132 $widgetEnabledSelector = "contact-activity-selector-dashlet_wrapper";
133 $widgetConfigureID = "2-0";
134
135 // now add the widget
136 $this->open($this->sboxPath . "civicrm");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138 $this->waitForTextPresent("Configure Your Dashboard");
139 $this->_testAddDashboardElement($widgetConfigureID, $widgetEnabledSelector, $widgetTitle);
140
141 // If CiviCase enabled, click 'more' link for context menu pop-up in the widget selector
142 if ($this->isElementPresent("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[8]/span[text()='more ']")) {
143 // click 'Delete Activity' link
144 $this->click("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[8]/span[text()='more ']/ul/li[2]/a[text()='Delete']");
145 }
146 else {
147 // click 'Delete Activity' link
148 $this->click("//table[@id='contact-activity-selector-dashlet']/tbody/tr[1]/td[8]/span//a[text()='Delete']");
149 }
150 $this->waitForPageToLoad($this->getTimeoutMsec());
151 $this->waitForElementPresent("_qf_Activity_next-bottom");
152 $this->assertTrue($this->isTextPresent("Are you sure you want to delete"));
153 $this->click("_qf_Activity_next-bottom");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
155 $this->assertTrue($this->isTextPresent("Selected Activity has been deleted successfully."));
156 // FIXMED: Currently there's a bug, dashboard context is ignored after delete so we should already be back on home dash.
157 // Issue filed: CRM-
158 // $this->assertTrue($this->isTextPresent("Configure Your Dashboard");
159 $this->open($this->sboxPath . "civicrm");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161 $this->waitForTextPresent("Configure Your Dashboard");
162
163 // cleanup by removing the widget
164 $this->_testRemoveDashboardElement($widgetConfigureID, $widgetEnabledSelector);
165 }
166 }
167