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