Merge branch 'phpunit-ob-fix' of https://github.com/giant-rabbit/civicrm-core into...
[civicrm-core.git] / tests / phpunit / api / v3 / DashboardTest.php
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 */
25 require_once 'CiviTest/CiviUnitTestCase.php';
26
27 /**
28 * Test APIv3 civicrm_action_schedule functions
29 *
30 * @package CiviCRM_APIv3
31 * @subpackage API_ActionSchedule
32 */
33
34 class api_v3_DashboardTest extends CiviUnitTestCase {
35 protected $_params;
36 protected $_params2;
37 protected $_entity = 'dashboard';
38 protected $_apiversion = 3;
39
40 /**
41 * Test setup for every test
42 *
43 * Connect to the database, truncate the tables that will be used
44 * and redirect stdin to a temporary file
45 */
46 public function setUp() {
47 // Connect to the database
48 parent::setUp();
49 }
50
51 /**
52 * Tears down the fixture, for example, closes a network connection.
53 * This method is called after a test is executed.
54 *
55 * @access protected
56 */
57 function tearDown() {
58 $tablesToTruncate = array(
59 'civicrm_dashboard',
60 );
61 $this->quickCleanup($tablesToTruncate, TRUE);
62 }
63
64 function testDashboardCreate() {
65 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
66 $params = array(
67 'version' => 3,
68 'label' => 'New Dashlet element',
69 'name' => 'New Dashlet element',
70 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
71 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
72 );
73 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
74 $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
75 $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
76 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
77 $this->assertEquals($oldCount + 1, $newCount);
78 $this->DashboardDelete($dashboard['id'], $oldCount);
79 }
80
81 /**
82 * @param int $id
83 * @param $oldCount
84 */
85 function DashboardDelete($id, $oldCount) {
86 $params = array(
87 'version' => 3,
88 'id' => $id,
89 );
90 $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
91 $this->assertEquals($id, $dashboardget['id']);
92 $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
93 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
94 $this->assertEquals($oldCount, $newCount);
95 }
96 }