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