2 require_once 'CiviTest/CiviUnitTestCase.php';
3 require_once 'CiviTest/Contact.php';
6 * Class CRM_Core_BAO_IMTest
8 class CRM_Core_BAO_IMTest
extends CiviUnitTestCase
{
15 'description' => 'Test all Core_BAO_IM methods.',
16 'group' => 'CiviCRM BAO Tests',
25 * add() method (create and update modes)
28 $contactId = Contact
::createIndividual();
35 'location_type_id' => 1,
36 'contact_id' => $contactId,
39 CRM_Core_BAO_IM
::add($params);
41 $imId = $this->assertDBNotNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name',
42 'Database check for created IM name.'
45 // Now call add() to modify an existing IM
50 'contact_id' => $contactId,
55 CRM_Core_BAO_IM
::add($params);
57 $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'provider_id', 'id', 'Database check on updated IM provider_name record.');
58 $this->assertEquals($isEditIM, 3, 'Verify IM provider_id value is 3.');
59 $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'name', 'id', 'Database check on updated IM name record.');
60 $this->assertEquals($isEditIM, 'doe.jane', 'Verify IM provider_id value is doe.jane.');
62 Contact
::delete($contactId);
66 * AllIMs() method - get all IMs for our contact, with primary IM first
68 function testAllIMs() {
69 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
72 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__
) . '/dataset/im_test.xml')
76 $IMs = CRM_Core_BAO_IM
::allIMs($contactId);
78 $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.');
80 $firstIMValue = array_slice($IMs, 0, 1);
82 $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.');
83 $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.');
85 Contact
::delete($contactId);