Merge pull request #7641 from totten/master-test-cv
[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 * Test APIv3 civicrm_action_schedule functions
24 *
25 * @package CiviCRM_APIv3
26 * @subpackage API_ActionSchedule
27 */
28 class api_v3_DashboardTest extends CiviUnitTestCase {
29 protected $_params;
30 protected $_params2;
31 protected $_entity = 'dashboard';
32 protected $_apiversion = 3;
33
34 /**
35 * Test setup for every test.
36 *
37 * Connect to the database, truncate the tables that will be used
38 * and redirect stdin to a temporary file
39 */
40 public function setUp() {
41 // Connect to the database
42 parent::setUp();
43 $this->useTransaction(TRUE);
44 }
45
46 public function testDashboardCreate() {
47 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
48 $params = array(
49 'version' => 3,
50 'label' => 'New Dashlet element',
51 'name' => 'New Dashlet element',
52 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
53 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
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');
59 $this->assertEquals($oldCount + 1, $newCount);
60 $this->DashboardDelete($dashboard['id'], $oldCount);
61 }
62
63 /**
64 * @param int $id
65 * @param $oldCount
66 */
67 public function DashboardDelete($id, $oldCount) {
68 $params = array(
69 'version' => 3,
70 'id' => $id,
71 );
72 $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
73 $this->assertEquals($id, $dashboardget['id']);
74 $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
75 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
76 $this->assertEquals($oldCount, $newCount);
77 }
78
79 }