Merge pull request #8470 from ankitjain28may/master
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / IMTest.php
1 <?php
2
3 /**
4 * Class CRM_Core_BAO_IMTest
5 * @group headless
6 */
7 class CRM_Core_BAO_IMTest extends CiviUnitTestCase {
8 public function setUp() {
9 parent::setUp();
10 }
11
12 /**
13 * Add() method (create and update modes)
14 */
15 public function testAdd() {
16 $contactId = Contact::createIndividual();
17
18 $params = array();
19 $params = array(
20 'name' => 'jane.doe',
21 'provider_id' => 1,
22 'is_primary' => 1,
23 'location_type_id' => 1,
24 'contact_id' => $contactId,
25 );
26
27 CRM_Core_BAO_IM::add($params);
28
29 $imId = $this->assertDBNotNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name',
30 'Database check for created IM name.'
31 );
32
33 // Now call add() to modify an existing IM
34
35 $params = array();
36 $params = array(
37 'id' => $imId,
38 'contact_id' => $contactId,
39 'provider_id' => 3,
40 'name' => 'doe.jane',
41 );
42
43 CRM_Core_BAO_IM::add($params);
44
45 $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'provider_id', 'id', 'Database check on updated IM provider_name record.');
46 $this->assertEquals($isEditIM, 3, 'Verify IM provider_id value is 3.');
47 $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'name', 'id', 'Database check on updated IM name record.');
48 $this->assertEquals($isEditIM, 'doe.jane', 'Verify IM provider_id value is doe.jane.');
49
50 $this->contactDelete($contactId);
51 }
52
53 /**
54 * AllIMs() method - get all IMs for our contact, with primary IM first
55 */
56 public function testAllIMs() {
57 $op = new PHPUnit_Extensions_Database_Operation_Insert();
58 $op->execute(
59 $this->_dbconn,
60 $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml')
61 );
62
63 $contactId = 69;
64 $IMs = CRM_Core_BAO_IM::allIMs($contactId);
65
66 $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.');
67
68 $firstIMValue = array_slice($IMs, 0, 1);
69
70 $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.');
71 $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.');
72
73 $this->contactDelete($contactId);
74 }
75
76 }