Merge pull request #2287 from pradpnayak/CRM-13848
[civicrm-core.git] / tests / phpunit / api / v3 / DashboardContactTest.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_DashboardContactTest extends CiviUnitTestCase {
35 protected $_params;
36 protected $_params2;
37 protected $_entity = 'dashborad_contact';
38 protected $_apiversion = 3;
39
40 public $_eNoticeCompliant = TRUE;
41 /**
42 * Test setup for every test
43 *
44 * Connect to the database, truncate the tables that will be used
45 * and redirect stdin to a temporary file
46 */
47 public function setUp() {
48 // Connect to the database
49 parent::setUp();
50 }
51
52 /**
53 * Tears down the fixture, for example, closes a network connection.
54 * This method is called after a test is executed.
55 *
56 * @access protected
57 */
58 function tearDown() {
59 $tablesToTruncate = array(
60 'civicrm_dashboard',
61 'civicrm_dashboard_contact',
62 );
63 $this->quickCleanup($tablesToTruncate, TRUE);
64 }
65
66 function testDashboardContactCreate() {
67 $dashParams = array(
68 'version' => 3,
69 'label' => 'New Dashlet element',
70 'name' => 'New Dashlet element',
71 'url' => 'civicrm/report/list&compid=99&reset=1&snippet=5',
72 'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
73 );
74 $dashresult = $this->callAPISuccess('dashboard', 'create', $dashParams);
75 $contact = $this->callAPISuccess('contact', 'create', array( 'first_name' => 'abc1',
76 'contact_type' => 'Individual',
77 'last_name' => 'xyz1',
78 'email' => 'abc@abc.com')
79 );
80 $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']}");
81 $params = array(
82 'version' => 3,
83 'contact_id' => $contact['id'],
84 'dashboard_id' => $dashresult['id'],
85 'is_active' => 1,
86 );
87 $dashboradContact = $this->callAPISuccess('dashboard_contact', 'create', $params);
88 $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']}");
89 $this->assertEquals($oldCount+1, $newCount);
90 }
91 }