Merge pull request #9438 from jmcclelland/CRM-19298
[civicrm-core.git] / tests / phpunit / api / v3 / DashboardTest.php
CommitLineData
15d9b3ae
N
1<?php
2/**
3 * File for the TestActionSchedule class
4 *
5 * (PHP 5)
6 *
7 * CiviCRM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation; either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * CiviCRM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 */
21
15d9b3ae
N
22/**
23 * Test APIv3 civicrm_action_schedule functions
24 *
151da6c3
TO
25 * @package CiviCRM_APIv3
26 * @subpackage API_ActionSchedule
acb109b7 27 * @group headless
15d9b3ae 28 */
15d9b3ae
N
29class api_v3_DashboardTest extends CiviUnitTestCase {
30 protected $_params;
31 protected $_params2;
32 protected $_entity = 'dashboard';
33 protected $_apiversion = 3;
34
15d9b3ae 35 /**
eceb18cc 36 * Test setup for every test.
15d9b3ae 37 *
d177a2a6
EM
38 * Connect to the database, truncate the tables that will be used
39 * and redirect stdin to a temporary file
151da6c3 40 */
15d9b3ae 41 public function setUp() {
151da6c3 42 // Connect to the database
15d9b3ae 43 parent::setUp();
51a11406 44 $this->useTransaction(TRUE);
15d9b3ae
N
45 }
46
00be9182 47 public function testDashboardCreate() {
151da6c3 48 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
15d9b3ae 49 $params = array(
15d9b3ae
N
50 'label' => 'New Dashlet element',
51 'name' => 'New Dashlet element',
242055d3
CW
52 'url' => 'civicrm/report/list&reset=1&compid=99',
53 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
15d9b3ae
N
54 );
55 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
56 $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
57 $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
58 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
151da6c3
TO
59 $this->assertEquals($oldCount + 1, $newCount);
60 $this->DashboardDelete($dashboard['id'], $oldCount);
3f14cb24
SL
61 $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 1);
62 }
63
cc4988ae 64 /**
65 * CRM-19534.
66 *
67 * Ensure that Dashboard create works fine for non admins
68 */
69 public function testDashboardCreateByNonAdmins() {
70 $loggedInContactID = $this->createLoggedInUser();
71 CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
72 $params = array(
73 'label' => 'New Dashlet element',
74 'name' => 'New Dashlet element',
75 'url' => 'civicrm/report/list&reset=1&compid=99',
76 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
77 );
78 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
79 $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
80 $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
81
82 $this->callAPISuccess('dashboard', 'create', $params);
83 $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 1);
84 }
85
3f14cb24
SL
86 /**
87 * CRM-19217.
06056f90 88 *
3f14cb24
SL
89 * Ensure that where is_active is specifically set to 0 is_active returns 0.
90 */
91 public function testDashboardCreateNotActive() {
92 $params = array(
3f14cb24
SL
93 'label' => 'New Dashlet element',
94 'name' => 'New Dashlet element',
95 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
96 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
97 'is_active' => 0,
98 );
99 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
100 $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 0);
15d9b3ae
N
101 }
102
4cbe18b8 103 /**
100fef9d 104 * @param int $id
4cbe18b8
EM
105 * @param $oldCount
106 */
00be9182 107 public function DashboardDelete($id, $oldCount) {
15d9b3ae 108 $params = array(
15d9b3ae
N
109 'id' => $id,
110 );
111 $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
112 $this->assertEquals($id, $dashboardget['id']);
113 $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
114 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
115 $this->assertEquals($oldCount, $newCount);
116 }
96025800 117
4b2694ae 118}