Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / tests / phpunit / api / v3 / DashboardContactTest.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
15d9b3ae
N
22/**
23 * Test APIv3 civicrm_action_schedule functions
24 *
151da6c3
TO
25 * @package CiviCRM_APIv3
26 * @subpackage API_ActionSchedule
acb109b7 27 * @group headless
15d9b3ae 28 */
15d9b3ae
N
29class api_v3_DashboardContactTest extends CiviUnitTestCase {
30 protected $_params;
31 protected $_params2;
dcf56200 32 protected $_entity = 'dashboard_contact';
15d9b3ae
N
33 protected $_apiversion = 3;
34
15d9b3ae 35 /**
eceb18cc 36 * Test setup for every test.
15d9b3ae 37 *
d177a2a6
EM
38 * Connect to the database, truncate the tables that will be used
39 * and redirect stdin to a temporary file
15d9b3ae
N
40 */
41 public function setUp() {
42 // Connect to the database
43 parent::setUp();
ce062e01 44 $this->useTransaction(TRUE);
15d9b3ae 45 }
151da6c3 46
76f87236
CW
47 /**
48 * @param int $version
49 * @dataProvider versionThreeAndFour
50 */
51 public function testDashboardContactCreate($version) {
52 $this->_apiversion = $version;
9099cab3 53 $dashParams = [
15d9b3ae
N
54 'label' => 'New Dashlet element',
55 'name' => 'New Dashlet element',
242055d3
CW
56 'url' => 'civicrm/report/list&compid=99&reset=1',
57 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
9099cab3 58 ];
151da6c3 59 $dashresult = $this->callAPISuccess('dashboard', 'create', $dashParams);
9099cab3 60 $contact = $this->callAPISuccess('contact', 'create', [
39b959db
SL
61 'first_name' => 'abc1',
62 'contact_type' => 'Individual',
63 'last_name' => 'xyz1',
64 'email' => 'abc@abc.com',
9099cab3 65 ]);
151da6c3 66 $oldCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
9099cab3 67 $params = [
15d9b3ae
N
68 'contact_id' => $contact['id'],
69 'dashboard_id' => $dashresult['id'],
70 'is_active' => 1,
9099cab3 71 ];
76f87236 72 $this->callAPISuccess('dashboard_contact', 'create', $params);
151da6c3
TO
73 $newCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
74 $this->assertEquals($oldCount + 1, $newCount);
15d9b3ae 75 }
96025800 76
4b2694ae 77}