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