4 * Class CRM_Core_BAO_IMTest
7 class CRM_Core_BAO_IMTest
extends CiviUnitTestCase
{
8 public function setUp() {
13 * Add() method (create and update modes)
15 public function testAdd() {
16 $contactId = Contact
::createIndividual();
23 'location_type_id' => 1,
24 'contact_id' => $contactId,
27 CRM_Core_BAO_IM
::add($params);
29 $imId = $this->assertDBNotNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name',
30 'Database check for created IM name.'
33 // Now call add() to modify an existing IM
38 'contact_id' => $contactId,
43 CRM_Core_BAO_IM
::add($params);
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.');
50 $this->contactDelete($contactId);
54 * AllIMs() method - get all IMs for our contact, with primary IM first
56 public function testAllIMs() {
57 $op = new PHPUnit_Extensions_Database_Operation_Insert();
60 $this->createFlatXMLDataSet(dirname(__FILE__
) . '/dataset/im_test.xml')
64 $IMs = CRM_Core_BAO_IM
::allIMs($contactId);
66 $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.');
68 $firstIMValue = array_slice($IMs, 0, 1);
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.');
73 $this->contactDelete($contactId);