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