Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / api / v3 / ImTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31/**
32 * Test APIv3 civicrm_im_* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Contact
36 */
37
38class api_v3_ImTest extends CiviUnitTestCase {
39 protected $_apiversion;
40 protected $params;
41 protected $id;
42 protected $_entity;
43 public $_eNoticeCompliant = TRUE;
44 public $DBResetRequired = FALSE; function setUp() {
45 parent::setUp();
46
47 $this->_entity = 'im';
48 $this->_apiversion = 3;
49 $this->_contactID = $this->organizationCreate();
50 $this->params = array(
51 'version' => 3,
52 'contact_id' => $this->_contactID,
53 'name' => 'My Yahoo IM Handle',
54 'location_type_id' => 1,
55 'provider_id' => 1,
56 );
57 }
58
59 function tearDown() {
60 $this->quickCleanup(array(
61 'civicrm_im',
62 'civicrm_contact'
63 ));
64 }
65
66 public function testCreateIm() {
67 $result = civicrm_api($this->_entity, 'create', $this->params);
68 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
69 $this->assertAPISuccess($result, 'In line ' . __LINE__);
70 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
71 $this->getAndCheck($this->params, $result['id'], $this->_entity);
72 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
73 }
74
75 public function testGetIm() {
76 $result = civicrm_api($this->_entity, 'create', $this->params);
77 $result = civicrm_api($this->_entity, 'get', $this->params);
78 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
79 $this->assertAPISuccess($result, 'In line ' . __LINE__);
80 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
81 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
82 civicrm_api($this->_entity, 'delete', array('version' => 3, 'id' => $result['id']));
83 }
84
85 public function testDeleteIm() {
86 $result = civicrm_api($this->_entity, 'create', $this->params);
87 $this->assertAPISuccess($result, 'in line ' . __LINE__);
88 $deleteParams = array('version' => 3, 'id' => $result['id']);
89 $result = civicrm_api($this->_entity, 'delete', $deleteParams);
90 $this->documentMe($deleteParams, $result, __FUNCTION__, __FILE__);
91 $this->assertAPISuccess($result, 'In line ' . __LINE__);
92 $checkDeleted = civicrm_api($this->_entity, 'get', array('version' => 3));
93 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
94 }
95 public function testDeleteImInvalid() {
96 $result = civicrm_api($this->_entity, 'create', $this->params);
97 $this->assertAPISuccess($result, 'in line ' . __LINE__);
98 $deleteParams = array('version' => 3, 'id' => 600);
99 $result = civicrm_api($this->_entity, 'delete', $deleteParams);
100 $this->assertEquals(1,$result['is_error'], 'In line ' . __LINE__);
101 $checkDeleted = civicrm_api($this->_entity, 'get', array('version' => 3));
102 $this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__);
103 }
104}