Merge pull request #5550 from civicrm/4.5
[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
22/**
23 * Include class definitions
24 */
25require_once 'CiviTest/CiviUnitTestCase.php';
26
27/**
28 * Test APIv3 civicrm_action_schedule functions
29 *
151da6c3
TO
30 * @package CiviCRM_APIv3
31 * @subpackage API_ActionSchedule
15d9b3ae 32 */
15d9b3ae
N
33class api_v3_DashboardTest extends CiviUnitTestCase {
34 protected $_params;
35 protected $_params2;
36 protected $_entity = 'dashboard';
37 protected $_apiversion = 3;
38
15d9b3ae 39 /**
eceb18cc 40 * Test setup for every test.
15d9b3ae 41 *
d177a2a6
EM
42 * Connect to the database, truncate the tables that will be used
43 * and redirect stdin to a temporary file
151da6c3 44 */
15d9b3ae 45 public function setUp() {
151da6c3 46 // Connect to the database
15d9b3ae 47 parent::setUp();
51a11406 48 $this->useTransaction(TRUE);
15d9b3ae
N
49 }
50
00be9182 51 public function testDashboardCreate() {
151da6c3 52 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
15d9b3ae
N
53 $params = array(
54 'version' => 3,
55 'label' => 'New Dashlet element',
56 'name' => 'New Dashlet element',
57 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
58 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
59 );
60 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
61 $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
62 $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
63 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
151da6c3
TO
64 $this->assertEquals($oldCount + 1, $newCount);
65 $this->DashboardDelete($dashboard['id'], $oldCount);
15d9b3ae
N
66 }
67
4cbe18b8 68 /**
100fef9d 69 * @param int $id
4cbe18b8
EM
70 * @param $oldCount
71 */
00be9182 72 public function DashboardDelete($id, $oldCount) {
15d9b3ae
N
73 $params = array(
74 'version' => 3,
75 'id' => $id,
76 );
77 $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
78 $this->assertEquals($id, $dashboardget['id']);
79 $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
80 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
81 $this->assertEquals($oldCount, $newCount);
82 }
96025800 83
4b2694ae 84}