13f41fcbd2c0e169d332c7eb4ed666faa6135a1c
[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 * @group headless
28 */
29 class api_v3_DashboardTest extends CiviUnitTestCase {
30 protected $_params;
31 protected $_params2;
32 protected $_entity = 'dashboard';
33 protected $_apiversion = 3;
34
35 /**
36 * Test setup for every test.
37 *
38 * Connect to the database, truncate the tables that will be used
39 * and redirect stdin to a temporary file
40 */
41 public function setUp() {
42 // Connect to the database
43 parent::setUp();
44 $this->useTransaction(TRUE);
45 }
46
47 public function testDashboardCreate() {
48 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
49 $params = array(
50 'version' => 3,
51 'label' => 'New Dashlet element',
52 'name' => 'New Dashlet element',
53 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
54 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
55 );
56 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
57 $this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
58 $this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
59 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
60 $this->assertEquals($oldCount + 1, $newCount);
61 $this->DashboardDelete($dashboard['id'], $oldCount);
62 $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 1);
63 }
64
65 /**
66 * CRM-19217.
67 * Ensure that where is_active is specifically set to 0 is_active returns 0.
68 */
69 public function testDashboardCreateNotActive() {
70 $params = array(
71 'version' => 3,
72 'label' => 'New Dashlet element',
73 'name' => 'New Dashlet element',
74 'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
75 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
76 'is_active' => 0,
77 );
78 $dashboard = $this->callAPISuccess('dashboard', 'create', $params);
79 $this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 0);
80 }
81
82 /**
83 * @param int $id
84 * @param $oldCount
85 */
86 public function DashboardDelete($id, $oldCount) {
87 $params = array(
88 'version' => 3,
89 'id' => $id,
90 );
91 $dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
92 $this->assertEquals($id, $dashboardget['id']);
93 $dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
94 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
95 $this->assertEquals($oldCount, $newCount);
96 }
97
98 }